Viewer.js 75 KB

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