Viewer.js 75 KB

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