Viewer.js 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858
  1. MWF.xApplication.query = MWF.xApplication.query || {};
  2. MWF.xApplication.query.Query = MWF.xApplication.query.Query || {};
  3. MWF.require("MWF.widget.Common", null, false);
  4. MWF.require("o2.widget.Paging", null, false);
  5. MWF.require("MWF.xScript.Macro", null, false);
  6. MWF.xDesktop.requireApp("query.Query", "lp.zh-cn", null, false);
  7. MWF.xApplication.query.Query.Viewer = MWF.QViewer = new Class({
  8. Implements: [Options, Events],
  9. Extends: MWF.widget.Common,
  10. options: {
  11. "style": "default",
  12. "resizeNode": true,
  13. "paging" : "scroll",
  14. "perPageCount" : 50,
  15. "isload": "true",
  16. "export": false,
  17. "moduleEvents": ["queryLoad", "postLoad", "postLoadPageData", "postLoadPage", "selectRow", "unselectRow",
  18. "queryLoadItemRow", "postLoadItemRow", "queryLoadCategoryRow", "postLoadCategoryRow"]
  19. // "actions": {
  20. // "lookup": {"uri": "/jaxrs/view/flag/{view}/query/{application}/execute", "method":"PUT"},
  21. // "getView": {"uri": "/jaxrs/view/flag/{view}/query/{application}"}
  22. //
  23. // },
  24. // "actionRoot": "x_query_assemble_surface"
  25. },
  26. initialize: function(container, json, options, app, parentMacro){
  27. //本类有三种事件,
  28. //一种是通过 options 传进来的事件,包括 loadView、openDocument、select
  29. //一种是用户配置的 事件, 在this.options.moduleEvents 中定义的作为类事件
  30. //还有一种也是用户配置的事件,不在this.options.moduleEvents 中定义的作为 this.node 的DOM事件
  31. this.setOptions(options);
  32. this.path = "/x_component_query_Query/$Viewer/";
  33. this.cssPath = "/x_component_query_Query/$Viewer/"+this.options.style+"/css.wcss";
  34. this._loadCss();
  35. this.lp = MWF.xApplication.query.Query.LP;
  36. this.app = app;
  37. this.container = $(container);
  38. this.json = json;
  39. this.parentMacro = parentMacro;
  40. debugger;
  41. this.originalJson = Object.clone(json);
  42. this.viewJson = null;
  43. this.filterItems = [];
  44. this.searchStatus = "none"; //none, custom, default
  45. this.items = [];
  46. this.selectedItems = [];
  47. this.hideColumns = [];
  48. this.openColumns = [];
  49. this.gridJson = null;
  50. if (this.options.isload){
  51. this.init(function(){
  52. this.load();
  53. }.bind(this));
  54. }
  55. },
  56. loadView: function(){
  57. if (this.viewJson){
  58. this.reload();
  59. }else{
  60. this.init(function(){
  61. this.load();
  62. }.bind(this));
  63. }
  64. },
  65. init: function(callback){
  66. if (this.json.data){
  67. this.viewJson = JSON.decode(this.json.data);
  68. if (callback) callback();
  69. }else{
  70. this.getView(callback);
  71. }
  72. },
  73. load: function(){
  74. this.loadMacro( function () {
  75. this._loadModuleEvents();
  76. if (this.fireEvent("queryLoad")){
  77. this._loadUserInterface();
  78. //this._loadStyles();
  79. this._loadDomEvents();
  80. }
  81. }.bind(this))
  82. },
  83. _loadUserInterface : function(){
  84. this.loadLayout();
  85. this.createActionbarNode();
  86. this.createSearchNode();
  87. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  88. if (this.options.resizeNode){
  89. this.setContentHeightFun = this.setContentHeight.bind(this);
  90. this.container.addEvent("resize", this.setContentHeightFun);
  91. this.setContentHeightFun();
  92. }
  93. },
  94. loadLayout: function(){
  95. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  96. this.actionbarAreaNode = new Element("div", {"styles": this.css.actionbarAreaNode}).inject(this.node);
  97. //if (this.options.export) this.exportAreaNode = new Element("div", {"styles": this.css.exportAreaNode}).inject(this.node);
  98. this.searchAreaNode = new Element("div", {"styles": this.css.searchAreaNode}).inject(this.node);
  99. this.viewAreaNode = new Element("div", {"styles": this.css.viewAreaNode}).inject(this.node);
  100. this.viewPageNode = new Element("div", {"styles": this.css.viewPageNode}).inject(this.node);
  101. this.viewPageAreaNode = new Element("div", {"styles": this.css.viewPageAreaNode}).inject(this.viewPageNode);
  102. },
  103. loadMacro: function (callback) {
  104. MWF.require("MWF.xScript.Macro", function () {
  105. this.Macro = new MWF.Macro.ViewContext(this);
  106. if (callback) callback();
  107. }.bind(this));
  108. },
  109. createExportNode: function(){
  110. if (this.options.export){
  111. MWF.require("MWF.widget.Toolbar", function(){
  112. this.toolbar = new MWF.widget.Toolbar(this.actionbarAreaNode, {"style": "simple"}, this); //this.exportAreaNode
  113. var actionNode = new Element("div", {
  114. "id": "",
  115. "MWFnodetype": "MWFToolBarButton",
  116. "MWFButtonImage": this.path+""+this.options.style+"/icon/export.png",
  117. "title": this.lp.exportExcel,
  118. "MWFButtonAction": "exportView",
  119. "MWFButtonText": this.lp.exportExcel
  120. }).inject(this.actionbarAreaNode); //this.exportAreaNode
  121. this.toolbar.load();
  122. }.bind(this));
  123. //this.exportNode = new Element("button", {"text": this.lp.exportExcel}).inject(this.exportAreaNode);
  124. }
  125. },
  126. exportView: function(){
  127. var action = MWF.Actions.get("x_query_assemble_surface");
  128. var filterData = this.json.filter ? this.json.filter.clone() : [];
  129. if (this.filterItems.length){
  130. this.filterItems.each(function(filter){
  131. filterData.push(filter.data);
  132. }.bind(this));
  133. }
  134. action.exportViewWithQuery(this.json.viewName, this.json.application, {"filterList": filterData}, function(json){
  135. var uri = action.action.actions.getViewExcel.uri;
  136. uri = uri.replace("{flag}", json.data.id);
  137. uri = action.action.address+uri;
  138. var a = new Element("a", {"href": uri, "target":"_blank"});
  139. a.click();
  140. a.destroy();
  141. }.bind(this));
  142. },
  143. createSearchNode: function(){
  144. if (this.viewJson.customFilterList && this.viewJson.customFilterList.length){
  145. this.searchStatus = "default";
  146. this.loadFilterSearch();
  147. }else{
  148. this.loadSimpleSearch();
  149. }
  150. },
  151. loadSimpleSearch: function(){
  152. return false;
  153. this.searchSimpleNode = new Element("div", {"styles": this.css.searchSimpleNode}).inject(this.searchAreaNode);
  154. this.searchSimpleButtonNode = new Element("div", {"styles": this.css.searchSimpleButtonNode}).inject(this.searchSimpleNode);
  155. this.searchSimpleInputNode = new Element("input", {"type":"text", "styles": this.css.searchSimpleInputNode, "value": this.lp.searchKeywork}).inject(this.searchSimpleNode);
  156. this.searchSimpleButtonNode.addEvent("click", function(){
  157. this.search();
  158. }.bind(this));
  159. this.searchSimpleInputNode.addEvents({
  160. "focus": function(){
  161. if (this.searchSimpleInputNode.get("value")===this.lp.searchKeywork) this.searchSimpleInputNode.set("value", "");
  162. }.bind(this),
  163. "blur": function(){if (!this.searchSimpleInputNode.get("value")) this.searchSimpleInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  164. "keydown": function(e){
  165. if (e.code===13) this.search();
  166. }.bind(this)
  167. });
  168. },
  169. search: function(){
  170. if (this.gridJson){
  171. var key = this.searchSimpleInputNode.get("value");
  172. var rows = this.viewTable.rows;
  173. var first = (this.json.isTitle!=="no") ? 1 : 0;
  174. for (var i = first; i<rows.length; i++){
  175. var tr = rows[i];
  176. if (!key || key==this.lp.searchKeywork){
  177. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  178. }else{
  179. if (tr.get("text").indexOf(key)!==-1){
  180. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  181. }else{
  182. if (tr.getStyle("display")!=="none") tr.setStyle("display", "none");
  183. }
  184. }
  185. }
  186. //if (this.viewPageAreaNode) this.viewPageAreaNode.hide();
  187. }
  188. },
  189. loadFilterSearch: function(){
  190. this.viewSearchCustomActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomActionNode, "text": this.lp.customSearch}).inject(this.searchAreaNode);
  191. this.viewSearchInputAreaNode = new Element("div", {"styles": this.css.viewFilterSearchInputAreaNode}).inject(this.searchAreaNode);
  192. this.viewSearchIconNode = new Element("div", {"styles": this.css.viewFilterSearchIconNode}).inject(this.viewSearchInputAreaNode);
  193. this.viewSearchInputBoxNode = new Element("div", {"styles": this.css.viewFilterSearchInputBoxNode}).inject(this.viewSearchInputAreaNode);
  194. this.viewSearchInputNode = new Element("input", {"styles": this.css.viewFilterSearchInputNode, "value": this.lp.searchKeywork}).inject(this.viewSearchInputBoxNode);
  195. this.viewSearchInputNode.addEvents({
  196. "focus": function(){
  197. if (this.viewSearchInputNode.get("value")===this.lp.searchKeywork) this.viewSearchInputNode.set("value", "");
  198. }.bind(this),
  199. "blur": function(){if (!this.viewSearchInputNode.get("value")) this.viewSearchInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  200. "keydown": function(e){
  201. if (e.code===13) this.searchView();
  202. }.bind(this)
  203. });
  204. this.viewSearchIconNode.addEvents({
  205. "click": function(){this.searchView();}.bind(this)
  206. });
  207. this.viewSearchCustomActionNode.addEvents({
  208. "click": function(){this.loadCustomSearch();}.bind(this)
  209. });
  210. },
  211. searchView: function(){
  212. if (this.viewJson.customFilterList) {
  213. var key = this.viewSearchInputNode.get("value");
  214. if (key && key !== this.lp.searchKeywork) {
  215. var filterData = this.json.filter ? this.json.filter : [];
  216. this.filterItems = [];
  217. this.viewJson.customFilterList.each(function (entry) {
  218. if (entry.formatType === "textValue") {
  219. var d = {
  220. "path": entry.path,
  221. "value": key,
  222. "formatType": entry.formatType,
  223. "logic": "or",
  224. "comparison": "like"
  225. };
  226. filterData.push(d);
  227. this.filterItems.push({"data":d});
  228. }
  229. if (entry.formatType === "numberValue") {
  230. var v = key.toFloat();
  231. if (!isNaN(v)) {
  232. var d = {
  233. "path": entry.path,
  234. "value": v,
  235. "formatType": entry.formatType,
  236. "logic": "or",
  237. "comparison": "like"
  238. };
  239. filterData.push(d);
  240. this.filterItems.push({"data":d});
  241. }
  242. }
  243. }.bind(this));
  244. this.createViewNode({"filterList": filterData});
  245. }else{
  246. this.createViewNode();
  247. }
  248. }
  249. },
  250. searchCustomView: function(){
  251. if (this.filterItems.length){
  252. var filterData = this.json.filter ? this.json.filter.clone() : [];
  253. this.filterItems.each(function(filter){
  254. filterData.push(filter.data);
  255. }.bind(this));
  256. this.createViewNode({"filterList": filterData});
  257. }else{
  258. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  259. }
  260. },
  261. loadCustomSearch: function(){
  262. this.viewSearchIconNode.setStyle("display", "none");
  263. this.viewSearchInputBoxNode.setStyle("display", "none");
  264. this.viewSearchCustomActionNode.setStyle("display", "none");
  265. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  266. var x = this.viewSearchInputAreaNode.getParent().getSize().x-2-20;
  267. this.css.viewFilterSearchInputAreaNode_custom.width = ""+x+"px";
  268. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  269. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  270. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode_custom).chain(function(){
  271. this.searchStatus = "custom";
  272. this.css.viewFilterSearchInputAreaNode_custom.width = "auto";
  273. this.viewSearchInputAreaNode.setStyle("width", "auto");
  274. if (this.viewSearchCustomContentNode){
  275. this.viewSearchCustomCloseActionNode.setStyle("display", "block");
  276. this.viewSearchCustomContentNode.setStyle("display", "block");
  277. }else{
  278. this.loadCustomSearchContent();
  279. }
  280. this.setContentHeightFun();
  281. }.bind(this));
  282. this.searchCustomView();
  283. },
  284. loadCustomSearchContent: function(){
  285. this.viewSearchCustomCloseActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomCloseActionNode}).inject(this.viewSearchInputAreaNode);
  286. this.viewSearchCustomContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomContentNode}).inject(this.viewSearchInputAreaNode);
  287. this.viewSearchCustomPathContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomPathContentNode}).inject(this.viewSearchCustomContentNode);
  288. this.viewSearchCustomComparisonContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomComparisonContentNode}).inject(this.viewSearchCustomContentNode);
  289. this.viewSearchCustomValueContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomValueContentNode}).inject(this.viewSearchCustomContentNode);
  290. this.viewSearchCustomAddContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddContentNode}).inject(this.viewSearchCustomContentNode);
  291. this.viewSearchCustomAddIconNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddIconNode}).inject(this.viewSearchCustomAddContentNode);
  292. this.viewSearchCustomFilterContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomFilterContentNode}).inject(this.viewSearchCustomContentNode);
  293. this.loadViewSearchCustomList();
  294. this.viewSearchCustomCloseActionNode.addEvents({
  295. "click": function(){this.closeCustomSearch();}.bind(this)
  296. });
  297. this.viewSearchCustomAddIconNode.addEvents({
  298. "click": function(){this.viewSearchCustomAddToFilter();}.bind(this)
  299. });
  300. },
  301. loadViewSearchCustomList: function(){
  302. this.viewSearchCustomPathListNode = new Element("select", {
  303. "styles": this.css.viewFilterSearchCustomPathListNode,
  304. "multiple": true
  305. }).inject(this.viewSearchCustomPathContentNode);
  306. this.viewSearchCustomComparisonListNode = new Element("select", {
  307. "styles": this.css.viewFilterSearchCustomComparisonListNode,
  308. "multiple": true
  309. }).inject(this.viewSearchCustomComparisonContentNode);
  310. this.viewJson.customFilterList.each(function(entry){
  311. var option = new Element("option", {
  312. "style": this.css.viewFilterSearchOptionNode,
  313. "value": entry.path,
  314. "text": entry.title
  315. }).inject(this.viewSearchCustomPathListNode);
  316. option.store("entry", entry);
  317. }.bind(this));
  318. this.viewSearchCustomPathListNode.addEvent("change", function(){
  319. this.loadViewSearchCustomComparisonList();
  320. }.bind(this));
  321. },
  322. loadViewSearchCustomComparisonList: function(){
  323. var idx = this.viewSearchCustomPathListNode.selectedIndex;
  324. var option = this.viewSearchCustomPathListNode.options[idx];
  325. var entry = option.retrieve("entry");
  326. if (entry){
  327. switch (entry.formatType){
  328. case "numberValue":
  329. this.loadComparisonSelect(this.lp.numberFilter);
  330. this.loadViewSearchCustomValueNumberInput();
  331. break;
  332. case "dateTimeValue":
  333. this.loadComparisonSelect(this.lp.dateFilter);
  334. this.loadViewSearchCustomValueDateTimeInput();
  335. break;
  336. case "dateValue":
  337. this.loadComparisonSelect(this.lp.dateFilter);
  338. this.loadViewSearchCustomValueDateInput();
  339. break;
  340. case "timeValue":
  341. this.loadComparisonSelect(this.lp.dateFilter);
  342. this.loadViewSearchCustomValueTimeInput();
  343. break;
  344. case "booleanValue":
  345. this.loadComparisonSelect(this.lp.booleanFilter);
  346. this.loadViewSearchCustomValueBooleanInput();
  347. break;
  348. default:
  349. this.loadComparisonSelect(this.lp.textFilter);
  350. this.loadViewSearchCustomValueTextInput();
  351. }
  352. }
  353. },
  354. loadViewSearchCustomValueNumberInput: function(){
  355. this.viewSearchCustomValueContentNode.empty();
  356. this.viewSearchCustomValueNode = new Element("input", {
  357. "styles": this.css.viewFilterSearchCustomValueNode,
  358. "type": "number"
  359. }).inject(this.viewSearchCustomValueContentNode);
  360. },
  361. loadViewSearchCustomValueDateTimeInput: function(){
  362. this.viewSearchCustomValueContentNode.empty();
  363. this.viewSearchCustomValueNode = new Element("input", {
  364. "styles": this.css.viewFilterSearchCustomValueNode,
  365. "type": "text",
  366. "readonly": true
  367. }).inject(this.viewSearchCustomValueContentNode);
  368. MWF.require("MWF.widget.Calendar", function(){
  369. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  370. "style": "xform",
  371. "isTime": true,
  372. "target": this.container,
  373. "format": "db"
  374. });
  375. }.bind(this));
  376. },
  377. loadViewSearchCustomValueDateInput: function(){
  378. this.viewSearchCustomValueContentNode.empty();
  379. this.viewSearchCustomValueNode = new Element("input", {
  380. "styles": this.css.viewFilterSearchCustomValueNode,
  381. "type": "text",
  382. "readonly": true
  383. }).inject(this.viewSearchCustomValueContentNode);
  384. MWF.require("MWF.widget.Calendar", function(){
  385. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  386. "style": "xform",
  387. "isTime": false,
  388. "target": this.container,
  389. "format": "%Y-%m-%d"
  390. });
  391. }.bind(this));
  392. },
  393. loadViewSearchCustomValueTimeInput: function(){
  394. this.viewSearchCustomValueContentNode.empty();
  395. this.viewSearchCustomValueNode = new Element("input", {
  396. "styles": this.css.viewFilterSearchCustomValueNode,
  397. "type": "text",
  398. "readonly": true
  399. }).inject(this.viewSearchCustomValueContentNode);
  400. MWF.require("MWF.widget.Calendar", function(){
  401. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  402. "style": "xform",
  403. "timeOnly": true,
  404. "target": this.container,
  405. "format": "%H:%M:%S"
  406. });
  407. }.bind(this));
  408. },
  409. loadViewSearchCustomValueBooleanInput: function(){
  410. this.viewSearchCustomValueContentNode.empty();
  411. this.viewSearchCustomValueNode = new Element("select", {
  412. "styles": this.css.viewFilterSearchCustomValueSelectNode,
  413. "multiple": true
  414. }).inject(this.viewSearchCustomValueContentNode);
  415. new Element("option", {"value": "true","text": this.lp.yes}).inject(this.viewSearchCustomValueNode);
  416. new Element("option", {"value": "false","text": this.lp.no}).inject(this.viewSearchCustomValueNode);
  417. },
  418. loadViewSearchCustomValueTextInput: function(){
  419. this.viewSearchCustomValueContentNode.empty();
  420. this.viewSearchCustomValueNode = new Element("textarea", {
  421. "styles": this.css.viewFilterSearchCustomValueNode
  422. }).inject(this.viewSearchCustomValueContentNode);
  423. },
  424. loadComparisonSelect:function(obj){
  425. this.viewSearchCustomComparisonListNode.empty();
  426. Object.each(obj, function(v, k){
  427. var option = new Element("option", {"value": k,"text": v}).inject(this.viewSearchCustomComparisonListNode);
  428. }.bind(this));
  429. },
  430. closeCustomSearch: function(){
  431. if (this.viewSearchCustomContentNode && this.viewSearchCustomContentNode.getStyle("display")==="block"){
  432. this.viewSearchCustomCloseActionNode.setStyle("display", "none");
  433. this.viewSearchCustomContentNode.setStyle("display", "none");
  434. var x = this.viewSearchInputAreaNode.getParent().getSize().x;
  435. x1 = x-2-10-90;
  436. this.css.viewFilterSearchInputAreaNode.width = ""+x1+"px";
  437. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  438. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  439. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  440. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode).chain(function(){
  441. this.searchStatus = "default";
  442. this.css.viewFilterSearchInputAreaNode.width = "auto";
  443. this.viewSearchInputAreaNode.setStyle("margin-right", "90px");
  444. this.viewSearchIconNode.setStyle("display", "block");
  445. this.viewSearchInputBoxNode.setStyle("display", "block");
  446. this.viewSearchCustomActionNode.setStyle("display", "block");
  447. this.setContentHeightFun();
  448. }.bind(this));
  449. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  450. }
  451. },
  452. viewSearchCustomAddToFilter: function(){
  453. var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
  454. var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
  455. if (pathIdx===-1){
  456. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
  457. return false;
  458. }
  459. if (comparisonIdx===-1){
  460. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
  461. return false;
  462. }
  463. var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
  464. var entry = pathOption.retrieve("entry");
  465. if (entry){
  466. var pathTitle = entry.title;
  467. var path = entry.path;
  468. var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
  469. var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
  470. var value = "";
  471. switch (entry.formatType){
  472. case "numberValue":
  473. value = this.viewSearchCustomValueNode.get("value");
  474. break;
  475. case "dateTimeValue":
  476. value = this.viewSearchCustomValueNode.get("value");
  477. break;
  478. case "booleanValue":
  479. var idx = this.viewSearchCustomValueNode.selectedIndex;
  480. if (idx!==-1){
  481. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  482. value = (v==="true");
  483. }
  484. break;
  485. default:
  486. value = this.viewSearchCustomValueNode.get("value");
  487. }
  488. if (value===""){
  489. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
  490. return false;
  491. }
  492. this.filterItems.push(new MWF.xApplication.query.Query.Viewer.Filter(this, {
  493. "logic": "and",
  494. "path": path,
  495. "title": pathTitle,
  496. "comparison": comparison,
  497. "comparisonTitle": comparisonTitle,
  498. "value": value,
  499. "formatType": (entry.formatType=="datetimeValue") ? "dateTimeValue": entry.formatType
  500. }, this.viewSearchCustomFilterContentNode));
  501. this.searchCustomView();
  502. }
  503. },
  504. searchViewRemoveFilter: function(filter){
  505. this.filterItems.erase(filter);
  506. filter.destroy();
  507. this.searchCustomView()
  508. },
  509. setContentHeight: function(){
  510. var size = this.node.getSize();
  511. var searchSize = this.searchAreaNode.getComputedSize();
  512. var h = size.y-searchSize.totalHeight;
  513. //if (this.exportAreaNode){
  514. // var exportSize = this.exportAreaNode.getComputedSize();
  515. // h = h-exportSize.totalHeight;
  516. //}
  517. if( this.actionbarAreaNode ){
  518. var exportSize = this.actionbarAreaNode.getComputedSize();
  519. h = h-exportSize.totalHeight;
  520. }
  521. var pageSize = this.viewPageNode.getComputedSize();
  522. h = h-pageSize.totalHeight;
  523. this.viewAreaNode.setStyle("height", ""+h+"px");
  524. },
  525. createLoadding: function(){
  526. this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.contentAreaNode);
  527. new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
  528. var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
  529. new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
  530. var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
  531. loadingTextNode.set("text", "loading...");
  532. },
  533. createActionbarNode : function(){
  534. this.actionbarAreaNode.empty();
  535. if( typeOf( this.viewJson.actionbarHidden ) === "boolean" ){
  536. if( this.viewJson.actionbarHidden === true || !this.viewJson.actionbarList || !this.viewJson.actionbarList.length )return;
  537. this.actionbar = new MWF.xApplication.query.Query.Viewer.Actionbar(this.actionbarAreaNode, this.viewJson.actionbarList[0], this, {});
  538. this.actionbar.load();
  539. }else{ //兼容以前的ExportNode
  540. this.createExportNode();
  541. }
  542. },
  543. createViewNode: function(data){
  544. this.viewAreaNode.empty();
  545. this.contentAreaNode = new Element("div", {"styles": this.css.contentAreaNode}).inject(this.viewAreaNode);
  546. this.viewTable = new Element("table", {
  547. "styles": this.css.viewTitleTableNode,
  548. "border": "0px",
  549. "cellPadding": "0",
  550. "cellSpacing": "0"
  551. }).inject(this.contentAreaNode);
  552. this.createLoadding();
  553. if (this.json.isTitle!=="no"){
  554. this.viewTitleLine = new Element("tr", {"styles": this.css.viewTitleLineNode}).inject(this.viewTable);
  555. //if (this.json.select==="single" || this.json.select==="multi") {
  556. this.selectTitleCell = new Element("td", {
  557. "styles": this.css.viewTitleCellNode
  558. }).inject(this.viewTitleLine);
  559. this.selectTitleCell.setStyle("width", "10px");
  560. if (this.json.titleStyles) this.selectTitleCell.setStyles(this.json.titleStyles);
  561. //}
  562. //序号
  563. if (this.viewJson.isSequence==="yes"){
  564. this.sequenceTitleCell = new Element("td", {
  565. "styles": this.css.viewTitleCellNode
  566. }).inject(this.viewTitleLine);
  567. this.sequenceTitleCell.setStyle("width", "10px");
  568. if (this.json.titleStyles) this.sequenceTitleCell.setStyles(this.json.titleStyles);
  569. }
  570. this.entries = {};
  571. this.viewJson.selectList.each(function(column){
  572. this.entries[column.column] = column;
  573. if (!column.hideColumn){
  574. var viewCell = new Element("td", {
  575. "styles": this.css.viewTitleCellNode,
  576. "text": column.displayName
  577. }).inject(this.viewTitleLine);
  578. var size = MWF.getTextSize(column.displayName, this.css.viewTitleCellNode);
  579. viewCell.setStyle("min-width", ""+size.x+"px");
  580. if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  581. }else{
  582. this.hideColumns.push(column.column);
  583. }
  584. if (column.allowOpen) this.openColumns.push(column.column);
  585. }.bind(this));
  586. this.lookup(data);
  587. }else{
  588. this.viewJson.selectList.each(function(column){
  589. if (column.hideColumn) this.hideColumns.push(column.column);
  590. if (!column.allowOpen) this.openColumns.push(column.column);
  591. }.bind(this));
  592. this.lookup(data);
  593. }
  594. },
  595. // _loadPageCountNode: function(){
  596. // this.viewPageContentNode.empty();
  597. //
  598. // var size = this.viewPageAreaNode.getSize();
  599. // var w1 = this.viewPageFirstNode.getSize().x*2;
  600. // var w2 = this.viewPageContentNode.getStyle("margin-left").toInt();
  601. // var w = size.x-w1-w2;
  602. //
  603. // var bw = this.css.viewPageButtonNode.width.toInt()+this.css.viewPageButtonNode["margin-right"].toInt();
  604. // var count = (w/bw).toInt()-2;
  605. // if (count>10) count = 10;
  606. // this.showPageCount = Math.min(count, this.pages);
  607. //
  608. // var tmp = this.showPageCount/2;
  609. // var n = tmp.toInt();
  610. // var left = this.currentPage-n;
  611. // if (left<=0) left = 1;
  612. // var right = this.showPageCount + left-1;
  613. // if (right>this.pages) right = this.pages;
  614. // left = right-this.showPageCount+1;
  615. // if (left<=1) left = 1;
  616. //
  617. // this.viewPagePrevNode = new Element("div", {"styles": this.css.viewPagePrevButtonNode}).inject(this.viewPageContentNode);
  618. // this.loadPageButtonEvent(this.viewPagePrevNode, "viewPagePrevButtonNode_over", "viewPagePrevButtonNode_up", "viewPagePrevButtonNode_down", function(){
  619. // if (this.currentPage>1) this.currentPage--;
  620. // this.loadCurrentPageData();
  621. // }.bind(this));
  622. //
  623. // for (i=left; i<=right; i++){
  624. // var node = new Element("div", {"styles": this.css.viewPageButtonNode, "text": i}).inject(this.viewPageContentNode);
  625. // if (i==this.currentPage){
  626. // node.setStyles(this.css.viewPageButtonNode_current);
  627. // }else{
  628. // this.loadPageButtonEvent(node, "viewPageButtonNode_over", "viewPageButtonNode_up", "viewPageButtonNode_down", function(e){
  629. // this.currentPage = e.target.get("text").toInt();
  630. // this.loadCurrentPageData();
  631. // }.bind(this));
  632. // }
  633. // }
  634. // this.viewPageNextNode = new Element("div", {"styles": this.css.viewPageNextButtonNode}).inject(this.viewPageContentNode);
  635. // this.loadPageButtonEvent(this.viewPageNextNode, "viewPageNextButtonNode_over", "viewPageNextButtonNode_up", "viewPageNextButtonNode_down", function(){
  636. // if (this.currentPage<=this.pages-1) this.currentPage++;
  637. // this.loadCurrentPageData();
  638. // }.bind(this));
  639. // },
  640. // loadPageButtonEvent: function(node, over, out, down, click){
  641. // node.addEvents({
  642. // "mouseover": function(){node.setStyles(this.css[over])}.bind(this),
  643. // "mouseout": function(){node.setStyles(this.css[out])}.bind(this),
  644. // "mousedown": function(){node.setStyles(this.css[down])}.bind(this),
  645. // "mouseup": function(){node.setStyles(this.css[out])}.bind(this),
  646. // "click": click
  647. // });
  648. // },
  649. // _loadPageNode: function(){
  650. // this.viewPageAreaNode.empty();
  651. // this.viewPageFirstNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.firstPage}).inject(this.viewPageAreaNode);
  652. // this.viewPageContentNode = new Element("div", {"styles": this.css.viewPageContentNode}).inject(this.viewPageAreaNode);
  653. // this.viewPageLastNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.lastPage}).inject(this.viewPageAreaNode);
  654. // this._loadPageCountNode();
  655. //
  656. // this.loadPageButtonEvent(this.viewPageFirstNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
  657. // this.currentPage = 1;
  658. // this.loadCurrentPageData();
  659. // }.bind(this));
  660. // this.loadPageButtonEvent(this.viewPageLastNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
  661. // this.currentPage = this.pages;
  662. // this.loadCurrentPageData();
  663. // }.bind(this));
  664. // },
  665. _loadPageNode : function(){
  666. debugger;
  667. this.viewPageAreaNode.empty();
  668. this.paging = new o2.widget.Paging(this.viewPageAreaNode, {
  669. countPerPage: this.json.pageSize || this.options.perPageCount,
  670. visiblePages: this.viewJson.visiblePages ? this.viewJson.visiblePages.toInt() : 9,
  671. currentPage: this.currentPage,
  672. itemSize: this.count,
  673. pageSize: this.pages,
  674. hasNextPage: typeOf( this.viewJson.hasPreNextPage ) === "boolean" ? this.viewJson.hasPreNextPage : true,
  675. hasPrevPage: typeOf( this.viewJson.hasPreNextPage ) === "boolean" ? this.viewJson.hasPreNextPage : true,
  676. hasTruningBar: typeOf( this.viewJson.hasTruningBar ) === "boolean" ? this.viewJson.hasTruningBar : true,
  677. hasBatchTuring: typeOf( this.viewJson.hasBatchTuring ) === "boolean" ? this.viewJson.hasBatchTuring : true,
  678. hasFirstPage: typeOf( this.viewJson.hasFirstLastPage ) === "boolean" ? this.viewJson.hasFirstLastPage : true,
  679. hasLastPage: typeOf( this.viewJson.hasFirstLastPage ) === "boolean" ? this.viewJson.hasFirstLastPage : true,
  680. hasJumper: typeOf( this.viewJson.hasPageJumper ) === "boolean" ? this.viewJson.hasPageJumper : true,
  681. hiddenWithDisable: false,
  682. hiddenWithNoItem: true,
  683. text: {
  684. prePage: "",
  685. nextPage: "",
  686. firstPage: this.lp.firstPage,
  687. lastPage: this.lp.lastPage
  688. },
  689. onJumpingPage : function( pageNum, itemNum ){
  690. this.currentPage = pageNum;
  691. this.loadCurrentPageData();
  692. }.bind(this),
  693. onPostLoad : function () {
  694. this.setContentHeightFun();
  695. }.bind(this)
  696. });
  697. this.paging.load();
  698. },
  699. _initPage: function(){
  700. this.count = this.bundleItems.length;
  701. var i = this.count/this.json.pageSize;
  702. this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  703. this.currentPage = 1;
  704. },
  705. lookup: function(data){
  706. this.getLookupAction(function(){
  707. if (this.json.application){
  708. var d = data || {};
  709. d.count = this.json.count;
  710. this.lookupAction.bundleView(this.json.id, d, function(json){
  711. this.bundleItems = json.data.valueList;
  712. this._initPage();
  713. if (this.bundleItems.length){
  714. this.loadCurrentPageData( function () {
  715. this.fireEvent("postLoad"); //用户配置的事件
  716. }.bind(this));
  717. }else{
  718. //this._loadPageNode();
  719. this.viewPageAreaNode.empty();
  720. if (this.loadingAreaNode){
  721. this.loadingAreaNode.destroy();
  722. this.loadingAreaNode = null;
  723. }
  724. this.fireEvent("postLoad"); //用户配置的事件
  725. }
  726. }.bind(this));
  727. }
  728. }.bind(this));
  729. },
  730. loadCurrentPageData: function( callback ){
  731. debugger;
  732. //是否需要在翻页的时候清空之前的items ?
  733. this.items = [];
  734. var p = this.currentPage;
  735. var d = {};
  736. var valueList = this.bundleItems.slice((p-1)*this.json.pageSize,this.json.pageSize*p);
  737. d.bundleList = valueList;
  738. while (this.viewTable.rows.length>1){
  739. this.viewTable.deleteRow(-1);
  740. }
  741. //this.createLoadding();
  742. this.loadViewRes = this.lookupAction.loadView(this.json.name, this.json.application, d, function(json){
  743. this.viewData = json.data;
  744. this.fireEvent("postLoadPageData");
  745. if (this.viewJson.group.column){
  746. this.gridJson = json.data.groupGrid;
  747. this.loadGroupData();
  748. }else{
  749. this.gridJson = json.data.grid;
  750. this.loadData();
  751. }
  752. if (this.gridJson.length) this._loadPageNode();
  753. if (this.loadingAreaNode){
  754. this.loadingAreaNode.destroy();
  755. this.loadingAreaNode = null;
  756. }
  757. this.fireEvent("loadView"); //options 传入的事件
  758. this.fireEvent("postLoadPage");
  759. if(callback)callback();
  760. }.bind(this));
  761. },
  762. loadData: function(){
  763. if (this.gridJson.length){
  764. // if( !this.options.paging ){
  765. this.gridJson.each(function(line, i){
  766. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, line, null, i));
  767. }.bind(this));
  768. // }else{
  769. // this.loadPaging();
  770. // }
  771. }else{
  772. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  773. }
  774. },
  775. loadPaging : function(){
  776. this.isItemsLoading = false;
  777. this.pageNumber = 0;
  778. this.isItemsLoaded = false;
  779. this.isSetedScroll = false;
  780. this.setScroll();
  781. this.loadDataByPaging()
  782. },
  783. setScroll : function(){
  784. if( this.options.paging && !this.isSetedScroll ){
  785. this.contentAreaNode.setStyle("overflow","auto");
  786. this.scrollContainerFun = function(){
  787. var scrollSize = this.contentAreaNode.getScrollSize();
  788. var clientSize = this.contentAreaNode.getSize();
  789. var scrollHeight = scrollSize.y - clientSize.y;
  790. //alert( "clientSize.y=" + clientSize.y + " scrollSize.y="+scrollSize.y + " this.contentAreaNode.scrollTop="+this.contentAreaNode.scrollTop);
  791. if (this.contentAreaNode.scrollTop + 150 > scrollHeight ) {
  792. if (!this.isItemsLoaded) this.loadDataByPaging();
  793. }
  794. }.bind(this);
  795. this.isSetedScroll = true;
  796. this.contentAreaNode.addEvent("scroll", this.scrollContainerFun )
  797. }
  798. },
  799. loadDataByPaging : function(){
  800. if( this.isItemsLoading )return;
  801. if( !this.isItemsLoaded ){
  802. var from = Math.min( this.pageNumber * this.options.perPageCount , this.gridJson.length);
  803. var to = Math.min( ( this.pageNumber + 1 ) * this.options.perPageCount + 1 , this.gridJson.length);
  804. this.isItemsLoading = true;
  805. for( var i = from; i<to; i++ ){
  806. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, this.gridJson[i], null, i));
  807. }
  808. this.isItemsLoading = false;
  809. this.pageNumber ++;
  810. if( to == this.gridJson.length )this.isItemsLoaded = true;
  811. }
  812. },
  813. loadGroupData: function(){
  814. if (this.selectTitleCell){
  815. this.selectTitleCell.set("html", "<span style='font-family: Webdings'>"+"<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>"+"</span>");
  816. this.selectTitleCell.setStyle("cursor", "pointer");
  817. this.selectTitleCell.addEvent("click", this.expandOrCollapseAll.bind(this));
  818. }
  819. if (this.gridJson.length){
  820. var i = 0;
  821. this.gridJson.each(function(data){
  822. this.items.push(new MWF.xApplication.query.Query.Viewer.ItemCategory(this, data, i));
  823. i += data.list.length;
  824. }.bind(this));
  825. if (this.json.isExpand=="yes") this.expandOrCollapseAll();
  826. }else{
  827. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  828. }
  829. },
  830. expandOrCollapseAll: function(){
  831. var icon = this.selectTitleCell.getElement("span");
  832. if (icon.get("html").indexOf("expand.png")===-1){
  833. this.items.each(function(item){
  834. item.collapse();
  835. icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>");
  836. }.bind(this));
  837. }else{
  838. this.items.each(function(item, i){
  839. window.setTimeout(function(){
  840. item.expand();
  841. }.bind(this), 10*i+5);
  842. icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/down.png'/>");
  843. }.bind(this));
  844. }
  845. },
  846. getView: function(callback){
  847. this.getLookupAction(function(){
  848. if (this.json.application){
  849. this.getViewRes = this.lookupAction.getView(this.json.viewName, this.json.application, function(json){
  850. this.viewJson = JSON.decode(json.data.data);
  851. this.json = Object.merge(this.json, json.data);
  852. if (callback) callback();
  853. }.bind(this));
  854. // this.lookupAction.invoke({"name": "getView","async": true, "parameter": {"view": this.json.viewName, "application": this.json.application},"success": function(json){
  855. // this.viewJson = JSON.decode(json.data.data);
  856. // this.json = Object.merge(this.json, json.data);
  857. // //var viewData = JSON.decode(json.data.data);
  858. // if (callback) callback();
  859. // }.bind(this)});
  860. }else{
  861. this.getViewRes = this.lookupAction.getViewById(this.json.viewId, function(json){
  862. this.viewJson = JSON.decode(json.data.data);
  863. this.json.application = json.data.query;
  864. this.json = Object.merge(this.json, json.data);
  865. if (callback) callback();
  866. }.bind(this));
  867. }
  868. }.bind(this));
  869. },
  870. getLookupAction: function(callback){
  871. if (!this.lookupAction){
  872. this.lookupAction = MWF.Actions.get("x_query_assemble_surface");
  873. if (callback) callback();
  874. // var _self = this;
  875. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  876. // this.lookupAction = new MWF.xDesktop.Actions.RestActions("", this.options.actionRoot, "");
  877. // this.lookupAction.getActions = function(actionCallback){
  878. // this.actions = _self.options.actions;
  879. // if (actionCallback) actionCallback();
  880. // };
  881. // if (callback) callback();
  882. // }.bind(this));
  883. }else{
  884. if (callback) callback();
  885. }
  886. },
  887. hide: function(){
  888. this.node.setStyle("display", "none");
  889. },
  890. reload: function(){
  891. this.node.setStyle("display", "block");
  892. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  893. this.filterItems.each(function(filter){
  894. filter.destroy();
  895. }.bind(this));
  896. this.filterItems = [];
  897. if (this.viewSearchInputNode) this.viewSearchInputNode.set("text", this.lp.searchKeywork);
  898. this.closeCustomSearch();
  899. this.viewAreaNode.empty();
  900. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  901. },
  902. getFilter: function(){
  903. var filterData = [];
  904. if (this.searchStatus==="custom"){
  905. if (this.filterItems.length){
  906. this.filterItems.each(function(filter){
  907. filterData.push(filter.data);
  908. }.bind(this));
  909. }
  910. }
  911. if (this.searchStatus==="default"){
  912. var key = this.viewSearchInputNode.get("value");
  913. if (key && key!==this.lp.searchKeywork){
  914. this.viewJson.customFilterList.each(function(entry){
  915. if (entry.formatType==="textValue"){
  916. var d = {
  917. "path": entry.path,
  918. "value": key,
  919. "formatType": entry.formatType,
  920. "logic": "or",
  921. "comparison": "like"
  922. };
  923. filterData.push(d);
  924. }
  925. if (entry.formatType==="numberValue"){
  926. var v = key.toFloat();
  927. if (!isNaN(v)){
  928. var d = {
  929. "path": entry.path,
  930. "value": v,
  931. "formatType": entry.formatType,
  932. "logic": "or",
  933. "comparison": "like"
  934. };
  935. filterData.push(d);
  936. }
  937. }
  938. }.bind(this));
  939. }
  940. }
  941. return (filterData.length) ? filterData : null;
  942. },
  943. getSelectedData : function(){
  944. return this.getData();
  945. },
  946. getData: function(){
  947. if (this.selectedItems.length){
  948. var arr = [];
  949. this.selectedItems.each(function(item){
  950. arr.push(item.data);
  951. });
  952. return arr;
  953. }else{
  954. return [];
  955. }
  956. },
  957. _loadModuleEvents : function(){
  958. debugger;
  959. Object.each(this.viewJson.events, function(e, key){
  960. if (e.code){
  961. if (this.options.moduleEvents.indexOf(key)!==-1){
  962. this.addEvent(key, function(event, target){
  963. debugger;
  964. return this.Macro.fire(e.code, target || this, event);
  965. }.bind(this));
  966. }
  967. }
  968. }.bind(this));
  969. },
  970. _loadDomEvents: function(){
  971. Object.each(this.viewJson.events, function(e, key){
  972. if (e.code){
  973. if (this.options.moduleEvents.indexOf(key)===-1){
  974. this.node.addEvent(key, function(event){
  975. return this.Macro.fire(e.code, this, event);
  976. }.bind(this));
  977. }
  978. }
  979. }.bind(this));
  980. },
  981. //api 使用 开始
  982. getParentEnvironment : function(){
  983. return this.parentMacro ? this.parentMacro.environment : null;
  984. },
  985. getViewInfor : function(){
  986. return this.json;
  987. },
  988. getPageInfor : function(){
  989. return {
  990. pages : this.pages,
  991. perPageCount : this.options.perPageCount,
  992. currentPageNumber : this.currentPage
  993. };
  994. },
  995. getPageData : function () {
  996. return this.gridJson;
  997. },
  998. toPage : function( pageNumber, callback ){
  999. this.currentPage = pageNumber;
  1000. this.loadCurrentPageData( callback );
  1001. },
  1002. selectAll : function(){
  1003. var flag = this.json.select || this.viewJson.select || "none";
  1004. if ( flag==="multi"){
  1005. this.items.each( function (item) {
  1006. if( item.clazzType === "item" ){
  1007. item.selected();
  1008. }else{
  1009. item.expand();
  1010. if( item.items ){
  1011. item.items.each( function (it) {
  1012. it.selected();
  1013. })
  1014. }
  1015. }
  1016. })
  1017. }
  1018. },
  1019. unSelectAll : function(){
  1020. var flag = this.json.select || this.viewJson.select || "none";
  1021. if ( flag==="multi"){
  1022. this.items.each( function (item) {
  1023. if( item.clazzType === "item" ){
  1024. item.unSelected();
  1025. }else{
  1026. if(item.items){
  1027. item.items.each( function (it) {
  1028. it.unSelected();
  1029. })
  1030. }
  1031. }
  1032. })
  1033. }
  1034. },
  1035. setFilter : function( filter ){
  1036. if( !filter )filter = [];
  1037. if( typeOf( filter ) === "object" )filter = [ filter ];
  1038. this.json.filter = filter;
  1039. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  1040. },
  1041. switchView : function( json ){
  1042. debugger;
  1043. // json = {
  1044. // "application": application,
  1045. // "viewName": viewName,
  1046. // "isTitle": "yes",
  1047. // "select": "none",
  1048. // "titleStyles": titleStyles,
  1049. // "itemStyles": itemStyles,
  1050. // "isExpand": "no",
  1051. // "filter": filter
  1052. // }
  1053. this.node.setStyle("display", "block");
  1054. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  1055. this.searchMorph = null;
  1056. this.viewSearchCustomContentNode = null;
  1057. var newJson = Object.merge( Object.clone(this.originalJson), json );
  1058. this.container.empty();
  1059. this.initialize( this.container, newJson, Object.clone(this.options), this.app, this.parentMacro);
  1060. },
  1061. confirm: function (type, e, title, text, width, height, ok, cancel, callback, mask, style) {
  1062. this.app.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style)
  1063. },
  1064. alert: function (type, title, text, width, height) {
  1065. this.app.alert(type, "center", title, text, width, height);
  1066. },
  1067. notice: function (content, type, target, where, offset, option) {
  1068. this.app.notice(content, type, target, where, offset, option)
  1069. }
  1070. //api 使用 结束
  1071. });
  1072. MWF.xApplication.query.Query.Viewer.Item = new Class({
  1073. initialize: function(view, data, prev, i){
  1074. this.view = view;
  1075. this.data = data;
  1076. this.css = this.view.css;
  1077. this.isSelected = false;
  1078. this.prev = prev;
  1079. this.idx = i;
  1080. this.clazzType = "item";
  1081. this.load();
  1082. },
  1083. load: function(){
  1084. this.view.fireEvent("queryLoadItemRow", [null, this]);
  1085. this.node = new Element("tr", {"styles": this.css.viewContentTrNode});
  1086. if (this.prev){
  1087. this.node.inject(this.prev.node, "after");
  1088. }else{
  1089. this.node.inject(this.view.viewTable);
  1090. }
  1091. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  1092. this.selectTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1093. this.selectTd.setStyles({"cursor": "pointer"});
  1094. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  1095. //}
  1096. //序号
  1097. if (this.view.viewJson.isSequence==="yes"){
  1098. this.sequenceTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1099. this.sequenceTd.setStyle("width", "10px");
  1100. var s= 1+this.view.json.pageSize*(this.view.currentPage-1)+this.idx;
  1101. this.sequenceTd.set("text", s);
  1102. }
  1103. Object.each(this.view.entries, function(c, k){
  1104. var cell = this.data.data[k];
  1105. if (cell === undefined) cell = "";
  1106. //if (cell){
  1107. if (this.view.hideColumns.indexOf(k)===-1){
  1108. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1109. if (k!== this.view.viewJson.group.column){
  1110. //var v = (this.view.entries[k].code) ? MWF.Macro.exec(this.view.entries[k].code, {"value": cell, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : cell;
  1111. var v = cell;
  1112. if (c.isHtml){
  1113. td.set("html", v);
  1114. }else{
  1115. td.set("text", v);
  1116. }
  1117. }
  1118. if (this.view.openColumns.indexOf(k)!==-1){
  1119. this.setOpenWork(td, c)
  1120. }
  1121. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  1122. }
  1123. //}
  1124. }.bind(this));
  1125. // Object.each(this.data.data, function(cell, k){
  1126. // if (this.view.hideColumns.indexOf(k)===-1){
  1127. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  1128. // if (k!== this.view.viewJson.group.column){
  1129. // var v = (this.view.entries[k].code) ? MWF.Macro.exec(this.view.entries[k].code, {"value": cell, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : cell;
  1130. // td.set("text", v);
  1131. // }
  1132. // if (this.view.openColumns.indexOf(k)!==-1){
  1133. // this.setOpenWork(td)
  1134. // }
  1135. // if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  1136. // }
  1137. // }.bind(this));
  1138. this.setEvent();
  1139. this.view.fireEvent("postLoadItemRow", [null, this]);
  1140. },
  1141. setOpenWork: function(td, column){
  1142. td.setStyle("cursor", "pointer");
  1143. if( column.clickCode ){
  1144. // if( !this.view.Macro ){
  1145. // MWF.require("MWF.xScript.Macro", function () {
  1146. // this.view.businessData = {};
  1147. // this.view.Macro = new MWF.Macro.PageContext(this.view);
  1148. // }.bind(this), false);
  1149. // }
  1150. td.addEvent("click", function( ev ){
  1151. var result = this.view.Macro.fire(column.clickCode, this, ev);
  1152. ev.stopPropagation();
  1153. return result;
  1154. }.bind(this));
  1155. }else{
  1156. if (this.view.json.type==="cms"){
  1157. td.addEvent("click", function(ev){
  1158. this.openCms(ev)
  1159. ev.stopPropagation();
  1160. }.bind(this));
  1161. }else{
  1162. td.addEvent("click", function(ev){
  1163. this.openWorkAndCompleted(ev)
  1164. ev.stopPropagation();
  1165. }.bind(this));
  1166. }
  1167. }
  1168. },
  1169. openCms: function(e){
  1170. var options = {"documentId": this.data.bundle};
  1171. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1172. layout.desktop.openApplication(e, "cms.Document", options);
  1173. },
  1174. openWorkAndCompleted: function(e){
  1175. MWF.Actions.get("x_processplatform_assemble_surface").listWorkByJob(this.data.bundle, function(json){
  1176. var workCompletedCount = json.data.workCompletedList.length;
  1177. var workCount = json.data.workList.length;
  1178. var count = workCount+workCompletedCount;
  1179. if (count===1){
  1180. if (workCompletedCount) {
  1181. this.openWorkCompleted(json.data.workCompletedList[0].id, e);
  1182. }else{
  1183. this.openWork(json.data.workList[0].id, e);
  1184. }
  1185. }else if (count>1){
  1186. var worksAreaNode = this.createWorksArea();
  1187. json.data.workCompletedList.each(function(work){
  1188. this.createWorkCompletedNode(work, worksAreaNode);
  1189. }.bind(this));
  1190. json.data.workList.each(function(work){
  1191. this.createWorkNode(work, worksAreaNode);
  1192. }.bind(this));
  1193. this.showWorksArea(worksAreaNode, e);
  1194. }else{
  1195. }
  1196. }.bind(this));
  1197. },
  1198. createWorkNode: function(work, worksAreaNode){
  1199. var worksAreaContentNode = worksAreaNode.getLast();
  1200. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  1201. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  1202. actionNode.store("workId", work.id);
  1203. actionNode.addEvent("click", function(e){
  1204. this.openWork(e.target.retrieve("workId"), e);
  1205. this.mask.hide();
  1206. worksAreaNode.destroy();
  1207. }.bind(this));
  1208. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  1209. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  1210. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  1211. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  1212. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": work.activityName}).inject(contentNode);
  1213. var taskUsers = [];
  1214. MWF.Actions.get("x_processplatform_assemble_surface").listTaskByWork(work.id, function(json){
  1215. json.data.each(function(task){
  1216. taskUsers.push(MWF.name.cn(task.person));
  1217. }.bind(this));
  1218. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.taskPeople+": "}).inject(contentNode);
  1219. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": taskUsers.join(", ")}).inject(contentNode);
  1220. }.bind(this));
  1221. },
  1222. createWorkCompletedNode: function(work, worksAreaNode){
  1223. var worksAreaContentNode = worksAreaNode.getLast();
  1224. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  1225. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  1226. actionNode.store("workId", work.id);
  1227. actionNode.addEvent("click", function(e){
  1228. this.mask.hide();
  1229. var id = e.target.retrieve("workId");
  1230. worksAreaNode.destroy();
  1231. this.openWorkCompleted(id, e);
  1232. }.bind(this));
  1233. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  1234. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  1235. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  1236. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  1237. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": this.view.lp.processCompleted}).inject(contentNode);
  1238. },
  1239. createWorksArea: function(){
  1240. var worksAreaNode = new Element("div", {"styles": this.css.worksAreaNode});
  1241. var worksAreaTitleNode = new Element("div", {"styles": this.css.worksAreaTitleNode}).inject(worksAreaNode);
  1242. var worksAreaTitleCloseNode = new Element("div", {"styles": this.css.worksAreaTitleCloseNode}).inject(worksAreaTitleNode);
  1243. worksAreaTitleCloseNode.addEvent("click", function(e){
  1244. this.mask.hide();
  1245. e.target.getParent().getParent().destroy();
  1246. }.bind(this));
  1247. var worksAreaContentNode = new Element("div", {"styles": this.css.worksAreaContentNode}).inject(worksAreaNode);
  1248. return worksAreaNode;
  1249. },
  1250. showWorksArea: function(node, e){
  1251. MWF.require("MWF.widget.Mask", null, false);
  1252. this.mask = new MWF.widget.Mask({"style": "desktop", "loading": false});
  1253. this.mask.loadNode(this.view.container);
  1254. node.inject(this.view.node);
  1255. this.setWorksAreaPosition(node, e.target);
  1256. },
  1257. setWorksAreaPosition: function(node, td){
  1258. var p = td.getPosition(this.view.container);
  1259. var containerS = this.view.container.getSize();
  1260. var containerP = this.view.container.getPosition(this.view.container.getOffsetParent());
  1261. var s = node.getSize();
  1262. var offX = p.x+s.x-containerS.x;
  1263. offX = (offX>0) ? offX+20 : 0;
  1264. var offY = p.y+s.y-containerS.y;
  1265. offY = (offY>0) ? offY+5 : 0;
  1266. node.position({
  1267. "relativeTo": td,
  1268. "position": "lefttop",
  1269. "edge": "lefttop",
  1270. "offset": {
  1271. "x": 0-offX,
  1272. "y": 0-offY
  1273. }
  1274. });
  1275. },
  1276. openWork: function(id, e){
  1277. var options = {"workId": id};
  1278. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1279. layout.desktop.openApplication(e, "process.Work", options);
  1280. },
  1281. openWorkCompleted: function(id, e){
  1282. var options = {"workCompletedId": id};
  1283. this.view.fireEvent("openDocument", [options, this]); //options 传入的事件
  1284. layout.desktop.openApplication(e, "process.Work", options);
  1285. },
  1286. setEvent: function(){
  1287. var flag = this.view.json.select || this.view.viewJson.select || "none";
  1288. if ( flag ==="single" || flag==="multi"){
  1289. this.node.addEvents({
  1290. "mouseover": function(){
  1291. if (!this.isSelected){
  1292. var iconName = "checkbox";
  1293. if (flag==="single") iconName = "radiobox";
  1294. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/"+iconName+".png) center center no-repeat"});
  1295. }
  1296. }.bind(this),
  1297. "mouseout": function(){
  1298. if (!this.isSelected) this.selectTd.setStyles({"background": "transparent"});
  1299. }.bind(this),
  1300. "click": function(){this.select();}.bind(this)
  1301. });
  1302. }
  1303. },
  1304. select: function(){
  1305. var flag = this.view.json.select || this.view.viewJson.select || "none";
  1306. if (this.isSelected){
  1307. if (flag==="single"){
  1308. this.unSelectedSingle();
  1309. }else{
  1310. this.unSelected();
  1311. }
  1312. }else{
  1313. if (flag==="single"){
  1314. this.selectedSingle();
  1315. }else{
  1316. this.selected();
  1317. }
  1318. }
  1319. this.view.fireEvent("select"); //options 传入的事件
  1320. },
  1321. selected: function(){
  1322. this.view.selectedItems.push(this);
  1323. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/checkbox_checked.png) center center no-repeat"});
  1324. this.node.setStyles(this.css.viewContentTrNode_selected);
  1325. this.isSelected = true;
  1326. this.view.fireEvent("selectRow", [this]);
  1327. },
  1328. unSelected: function(){
  1329. this.view.selectedItems.erase(this);
  1330. this.selectTd.setStyles({"background": "transparent"});
  1331. this.node.setStyles(this.css.viewContentTrNode);
  1332. this.isSelected = false;
  1333. this.view.fireEvent("unselectRow", [this]);
  1334. },
  1335. selectedSingle: function(){
  1336. if (this.view.currentSelectedItem) this.view.currentSelectedItem.unSelectedSingle();
  1337. this.view.selectedItems = [this];
  1338. this.view.currentSelectedItem = this;
  1339. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/radiobox_checked.png) center center no-repeat"});
  1340. this.node.setStyles(this.css.viewContentTrNode_selected);
  1341. this.isSelected = true;
  1342. this.view.fireEvent("selectRow", [this]);
  1343. },
  1344. unSelectedSingle: function(){
  1345. this.view.selectedItems = [];
  1346. this.view.currentSelectedItem = null;
  1347. this.selectTd.setStyles({"background": "transparent"});
  1348. this.node.setStyles(this.css.viewContentTrNode);
  1349. this.isSelected = false;
  1350. this.view.fireEvent("unselectRow", [this]);
  1351. }
  1352. });
  1353. MWF.xApplication.query.Query.Viewer.ItemCategory = new Class({
  1354. initialize: function(view, data, i){
  1355. this.view = view;
  1356. this.data = data;
  1357. this.css = this.view.css;
  1358. this.items = [];
  1359. this.loadChild = false;
  1360. this.idx = i;
  1361. this.clazzType = "category";
  1362. this.load();
  1363. },
  1364. load: function(){
  1365. this.view.fireEvent("queryLoadCategoryRow", [null, this]);
  1366. this.node = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.view.viewTable);
  1367. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  1368. this.selectTd = new Element("td", {"styles": this.css.viewContentCategoryTdNode}).inject(this.node);
  1369. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  1370. //}
  1371. this.categoryTd = new Element("td", {
  1372. "styles": this.css.viewContentCategoryTdNode,
  1373. "colspan": this.view.viewJson.selectList.length+1
  1374. }).inject(this.node);
  1375. this.groupColumn = null;
  1376. for (var c = 0; c<this.view.viewJson.selectList.length; c++){
  1377. if (this.view.viewJson.selectList[c].column === this.view.viewJson.group.column){
  1378. this.groupColumn = this.view.viewJson.selectList[c];
  1379. break;
  1380. }
  1381. }
  1382. if (this.groupColumn){
  1383. //var text = (this.groupColumn.code) ? MWF.Macro.exec(this.groupColumn.code, {"value": this.data.group, "gridData": this.view.gridJson, "data": this.view.viewData, "entry": this.data}) : this.data.group;
  1384. var text = this.data.group;
  1385. }else{
  1386. var text = this.data.group;
  1387. }
  1388. this.categoryTd.set("html", "<span style='font-family: Webdings'><img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/></span> "+text);
  1389. if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);
  1390. this.setEvent();
  1391. this.view.fireEvent("postLoadCategoryRow", [null, this]);
  1392. },
  1393. setEvent: function(){
  1394. //if (this.selectTd){
  1395. this.node.addEvents({
  1396. "click": function(){this.expandOrCollapse();}.bind(this)
  1397. });
  1398. //}
  1399. },
  1400. expandOrCollapse: function(){
  1401. var t = this.node.getElement("span").get("html");
  1402. if (t.indexOf("expand.png")===-1){
  1403. this.collapse();
  1404. }else{
  1405. this.expand();
  1406. }
  1407. },
  1408. collapse: function(){
  1409. this.items.each(function(item){
  1410. item.node.setStyle("display", "none");
  1411. }.bind(this));
  1412. this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/>");
  1413. },
  1414. expand: function(){
  1415. this.items.each(function(item){
  1416. item.node.setStyle("display", "table-row");
  1417. }.bind(this));
  1418. this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/down.png'/>");
  1419. if (!this.loadChild){
  1420. //window.setTimeout(function(){
  1421. this.data.list.each(function(line, i){
  1422. var s = this.idx+i;
  1423. this.lastItem = new MWF.xApplication.query.Query.Viewer.Item(this.view, line, (this.lastItem || this), s);
  1424. this.items.push(this.lastItem);
  1425. }.bind(this));
  1426. this.loadChild = true;
  1427. //}.bind(this), 10);
  1428. }
  1429. }
  1430. });
  1431. MWF.xApplication.query.Query.Viewer.Filter = new Class({
  1432. initialize: function(viewer, data, node){
  1433. this.viewer = viewer;
  1434. this.data = data;
  1435. this.css = this.viewer.css;
  1436. this.content = node;
  1437. this.load();
  1438. },
  1439. load: function(){
  1440. this.node = new Element("div", {"styles": this.css.viewSearchFilterNode}).inject(this.content);
  1441. if (this.viewer.filterItems.length){
  1442. this.logicNode = new Element("div", {"styles": this.css.viewSearchFilterSelectAreaNode}).inject(this.node);
  1443. this.logicSelectNode = new Element("div", {
  1444. "styles": this.css.viewSearchFilterSelectNode,
  1445. "text": this.viewer.lp.and,
  1446. "value": "and"
  1447. }).inject(this.logicNode);
  1448. this.logicSelectButtonNode = new Element("div", {"styles": this.css.viewSearchFilterSelectButtonNode}).inject(this.logicNode);
  1449. this.logicNode.addEvents({
  1450. "click": function(){
  1451. var v = this.logicSelectNode.get("value");
  1452. if (v==="and"){
  1453. this.logicSelectButtonNode.setStyle("float", "left");
  1454. this.logicSelectNode.setStyle("float", "right");
  1455. this.logicSelectNode.set({
  1456. "text": this.viewer.lp.or,
  1457. "value": "or"
  1458. });
  1459. this.data.logic = "or";
  1460. }else{
  1461. this.logicSelectButtonNode.setStyle("float", "right");
  1462. this.logicSelectNode.setStyle("float", "left");
  1463. this.logicSelectNode.set({
  1464. "text": this.viewer.lp.and,
  1465. "value": "and"
  1466. });
  1467. this.data.logic = "and";
  1468. }
  1469. this.viewer.searchCustomView();
  1470. }.bind(this)
  1471. });
  1472. }
  1473. this.titleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.title}).inject(this.node);
  1474. this.comparisonTitleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.comparisonTitle}).inject(this.node);
  1475. this.valueNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": "\""+this.data.value+"\""}).inject(this.node);
  1476. this.deleteNode = new Element("div", {"styles": this.css.viewSearchFilterDeleteNode}).inject(this.node);
  1477. this.node.addEvents({
  1478. "mouseover": function(){
  1479. this.node.setStyles(this.css.viewSearchFilterNode_over);
  1480. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode_over);
  1481. }.bind(this),
  1482. "mouseout": function(){
  1483. this.node.setStyles(this.css.viewSearchFilterNode);
  1484. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode);
  1485. }.bind(this)
  1486. });
  1487. this.deleteNode.addEvent("click", function(){
  1488. this.viewer.searchViewRemoveFilter(this);
  1489. }.bind(this));
  1490. },
  1491. destroy: function(){
  1492. this.node.destroy();
  1493. MWF.release(this);
  1494. }
  1495. });
  1496. MWF.xApplication.query.Query.Viewer.Actionbar = new Class({
  1497. Implements: [Events],
  1498. options: {
  1499. "style" : "default",
  1500. "moduleEvents": ["load", "queryLoad", "postLoad", "afterLoad"]
  1501. },
  1502. initialize: function(node, json, form, options){
  1503. this.node = $(node);
  1504. this.node.store("module", this);
  1505. this.json = json;
  1506. this.form = form;
  1507. this.view = form;
  1508. },
  1509. hide: function(){
  1510. var dsp = this.node.getStyle("display");
  1511. if (dsp!=="none") this.node.store("mwf_display", dsp);
  1512. this.node.setStyle("display", "none");
  1513. },
  1514. show: function(){
  1515. var dsp = this.node.retrieve("mwf_display", dsp);
  1516. this.node.setStyle("display", dsp);
  1517. },
  1518. load: function(){
  1519. this._loadModuleEvents();
  1520. if (this.fireEvent("queryLoad")){
  1521. //this._queryLoaded();
  1522. this._loadUserInterface();
  1523. this._loadStyles();
  1524. this._loadDomEvents();
  1525. //this._loadEvents();
  1526. //this._afterLoaded();
  1527. this.fireEvent("postLoad");
  1528. this.fireEvent("load");
  1529. }
  1530. },
  1531. _loadStyles: function(){
  1532. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  1533. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
  1534. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  1535. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  1536. var host3 = MWF.Actions.getHost("x_cms_assemble_control");
  1537. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  1538. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1539. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  1540. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1541. }
  1542. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  1543. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1544. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  1545. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1546. }
  1547. if (value.indexOf("/x_cms_assemble_control")!==-1){
  1548. value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
  1549. }else if (value.indexOf("x_cms_assemble_control")!==-1){
  1550. value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
  1551. }
  1552. }
  1553. this.node.setStyle(key, value);
  1554. }.bind(this));
  1555. // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  1556. // var host = MWF.Actions.getHost(root);
  1557. // return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  1558. // }
  1559. //if (this.json.styles) this.node.setStyles(this.json.styles);
  1560. },
  1561. _loadModuleEvents : function(){
  1562. Object.each(this.json.events, function(e, key){
  1563. if (e.code){
  1564. if (this.options.moduleEvents.indexOf(key)!==-1){
  1565. this.addEvent(key, function(event){
  1566. return this.form.Macro.fire(e.code, this, event);
  1567. }.bind(this));
  1568. }
  1569. }
  1570. }.bind(this));
  1571. },
  1572. _loadDomEvents: function(){
  1573. Object.each(this.json.events, function(e, key){
  1574. if (e.code){
  1575. if (this.options.moduleEvents.indexOf(key)===-1){
  1576. this.node.addEvent(key, function(event){
  1577. return this.form.Macro.fire(e.code, this, event);
  1578. }.bind(this));
  1579. }
  1580. }
  1581. }.bind(this));
  1582. },
  1583. _loadEvents: function(){
  1584. Object.each(this.json.events, function(e, key){
  1585. if (e.code){
  1586. if (this.options.moduleEvents.indexOf(key)!==-1){
  1587. this.addEvent(key, function(event){
  1588. return this.form.Macro.fire(e.code, this, event);
  1589. }.bind(this));
  1590. }else{
  1591. this.node.addEvent(key, function(event){
  1592. return this.form.Macro.fire(e.code, this, event);
  1593. }.bind(this));
  1594. }
  1595. }
  1596. }.bind(this));
  1597. },
  1598. addModuleEvent: function(key, fun){
  1599. if (this.options.moduleEvents.indexOf(key)!==-1){
  1600. this.addEvent(key, function(event){
  1601. return (fun) ? fun(this, event) : null;
  1602. }.bind(this));
  1603. }else{
  1604. this.node.addEvent(key, function(event){
  1605. return (fun) ? fun(this, event) : null;
  1606. }.bind(this));
  1607. }
  1608. },
  1609. _loadUserInterface: function(){
  1610. // if (this.form.json.mode == "Mobile"){
  1611. // this.node.empty();
  1612. // }else if (COMMON.Browser.Platform.isMobile){
  1613. // this.node.empty();
  1614. // }else{
  1615. this.toolbarNode = this.node.getFirst("div");
  1616. if( !this.toolbarNode ){
  1617. this.toolbarNode = new Element("div").inject( this.node );
  1618. }
  1619. this.toolbarNode.empty();
  1620. MWF.require("MWF.widget.Toolbar", function(){
  1621. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {
  1622. "style": this.json.style,
  1623. "onPostLoad" : function(){
  1624. this.fireEvent("afterLoad");
  1625. }.bind(this)
  1626. }, this);
  1627. if (this.json.actionStyles) this.toolbarWidget.css = this.json.actionStyles;
  1628. //alert(this.readonly)
  1629. if (this.json.hideSystemTools){
  1630. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1631. this.toolbarWidget.load();
  1632. }else{
  1633. if (this.json.defaultTools){
  1634. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  1635. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1636. this.toolbarWidget.load();
  1637. }else{
  1638. MWF.getJSON(this.form.path+"toolbars.json", function(json){
  1639. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  1640. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  1641. this.toolbarWidget.load();
  1642. }.bind(this), null);
  1643. }
  1644. }
  1645. }.bind(this));
  1646. // }
  1647. },
  1648. setCustomToolbars: function(tools, node){
  1649. var path = "/x_component_process_FormDesigner/Module/Actionbar/";
  1650. var iconPath = "";
  1651. if( this.json.customIconStyle ){
  1652. iconPath = this.json.customIconStyle+"/";
  1653. }
  1654. tools.each(function(tool){
  1655. var flag = true;
  1656. if (this.readonly){
  1657. flag = tool.readShow;
  1658. }else{
  1659. flag = tool.editShow;
  1660. }
  1661. if (flag){
  1662. flag = true;
  1663. // if (tool.control){
  1664. // flag = this.form.businessData.control[tool.control]
  1665. // }
  1666. if (tool.condition){
  1667. var hideFlag = this.form.Macro.exec(tool.condition, this);
  1668. flag = !hideFlag;
  1669. }
  1670. if (flag){
  1671. var actionNode = new Element("div", {
  1672. "id": tool.id,
  1673. "MWFnodetype": tool.type,
  1674. "MWFButtonImage": path+""+this.form.options.style+"/custom/"+iconPath+tool.img,
  1675. "title": tool.title,
  1676. "MWFButtonAction": "runCustomAction",
  1677. "MWFButtonText": tool.text
  1678. }).inject(node);
  1679. if( this.json.customIconOverStyle ){
  1680. actionNode.set("MWFButtonImageOver" , path+""+this.form.options.style +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  1681. }
  1682. if( tool.properties ){
  1683. actionNode.set(tool.properties);
  1684. }
  1685. if (tool.actionScript){
  1686. actionNode.store("script", tool.actionScript);
  1687. }
  1688. if (tool.sub){
  1689. var subNode = node.getLast();
  1690. this.setCustomToolbars(tool.sub, subNode);
  1691. }
  1692. }
  1693. }
  1694. }.bind(this));
  1695. },
  1696. setToolbarItem: function(tool, node, readonly, noCondition){
  1697. //var path = "/x_component_process_FormDesigner/Module/Actionbar/";
  1698. var path = "/x_component_query_ViewDesigner/$View/";
  1699. var flag = true;
  1700. // if (tool.control){
  1701. // flag = this.form.businessData.control[tool.control]
  1702. // }
  1703. if (!noCondition) if (tool.condition){
  1704. var hideFlag = this.form.Macro.exec(tool.condition, this);
  1705. flag = flag && (!hideFlag);
  1706. }
  1707. if (readonly) if (!tool.read) flag = false;
  1708. if (flag){
  1709. var actionNode = new Element("div", {
  1710. "id": tool.id,
  1711. "MWFnodetype": tool.type,
  1712. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  1713. //"MWFButtonImage": path+(this.options.style||"default") +"/tools/"+ (this.json.style || "default") +"/"+tool.img,
  1714. "MWFButtonImage": path+this.options.style+"/actionbar/"+tool.img,
  1715. "title": tool.title,
  1716. "MWFButtonAction": tool.action,
  1717. "MWFButtonText": tool.text
  1718. }).inject(node);
  1719. if( this.json.iconOverStyle ){
  1720. actionNode.set("MWFButtonImageOver" , path+""+this.options.style+"/actionbar/"+this.json.iconOverStyle+"/"+tool.img );
  1721. //actionNode.set("MWFButtonImageOver" , path+""+(this.options.style||"default")+"/tools/"+( this.json.iconOverStyle || "default" )+"/"+tool.img );
  1722. }
  1723. if( tool.properties ){
  1724. actionNode.set(tool.properties);
  1725. }
  1726. if (tool.sub){
  1727. var subNode = node.getLast();
  1728. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  1729. }
  1730. }
  1731. },
  1732. setToolbars: function(tools, node, readonly, noCondition){
  1733. tools.each(function(tool){
  1734. this.setToolbarItem(tool, node, readonly, noCondition);
  1735. }.bind(this));
  1736. },
  1737. runCustomAction: function(bt){
  1738. var script = bt.node.retrieve("script");
  1739. this.form.Macro.exec(script, this);
  1740. },
  1741. exportView : function(){
  1742. this.form.exportView();
  1743. },
  1744. deleteWork: function(){
  1745. this.form.deleteWork();
  1746. }
  1747. });