Viewer.js 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  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. // "actions": {
  17. // "lookup": {"uri": "/jaxrs/view/flag/{view}/query/{application}/execute", "method":"PUT"},
  18. // "getView": {"uri": "/jaxrs/view/flag/{view}/query/{application}"}
  19. //
  20. // },
  21. // "actionRoot": "x_query_assemble_surface"
  22. },
  23. initialize: function(container, json, options){
  24. this.setOptions(options);
  25. this.path = "/x_component_query_Query/$Viewer/";
  26. this.cssPath = "/x_component_query_Query/$Viewer/"+this.options.style+"/css.wcss";
  27. this._loadCss();
  28. this.lp = MWF.xApplication.query.Query.LP;
  29. this.container = $(container);
  30. this.json = json;
  31. this.viewJson = null;
  32. this.filterItems = [];
  33. this.searchStatus = "none"; //none, custom, default
  34. this.items = [];
  35. this.selectedItems = [];
  36. this.hideColumns = [];
  37. this.openColumns = [];
  38. this.gridJson = null;
  39. if (this.options.isload){
  40. this.init(function(){
  41. this.load();
  42. }.bind(this));
  43. }
  44. },
  45. loadView: function(){
  46. if (this.viewJson){
  47. this.reload();
  48. }else{
  49. this.init(function(){
  50. this.load();
  51. }.bind(this));
  52. }
  53. },
  54. init: function(callback){
  55. if (this.json.data){
  56. this.viewJson = JSON.decode(this.json.data);
  57. if (callback) callback();
  58. }else{
  59. this.getView(callback);
  60. }
  61. },
  62. load: function(){
  63. this.loadLayout();
  64. this.createExportNode();
  65. this.createSearchNode();
  66. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  67. if (this.options.resizeNode){
  68. this.setContentHeightFun = this.setContentHeight.bind(this);
  69. this.container.addEvent("resize", this.setContentHeightFun);
  70. this.setContentHeightFun();
  71. }
  72. },
  73. loadLayout: function(){
  74. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  75. if (this.options.export) this.exportAreaNode = new Element("div", {"styles": this.css.exportAreaNode}).inject(this.node);
  76. this.searchAreaNode = new Element("div", {"styles": this.css.searchAreaNode}).inject(this.node);
  77. this.viewAreaNode = new Element("div", {"styles": this.css.viewAreaNode}).inject(this.node);
  78. this.viewPageNode = new Element("div", {"styles": this.css.viewPageNode}).inject(this.node);
  79. this.viewPageAreaNode = new Element("div", {"styles": this.css.viewPageAreaNode}).inject(this.viewPageNode);
  80. },
  81. createExportNode: function(){
  82. if (this.options.export){
  83. MWF.require("MWF.widget.Toolbar", function(){
  84. this.toolbar = new MWF.widget.Toolbar(this.exportAreaNode, {"style": "simple"}, this);
  85. var actionNode = new Element("div", {
  86. "id": "",
  87. "MWFnodetype": "MWFToolBarButton",
  88. "MWFButtonImage": this.path+""+this.options.style+"/icon/export.png",
  89. "title": this.lp.exportExcel,
  90. "MWFButtonAction": "exportView",
  91. "MWFButtonText": this.lp.exportExcel
  92. }).inject(this.exportAreaNode);
  93. this.toolbar.load();
  94. }.bind(this));
  95. //this.exportNode = new Element("button", {"text": this.lp.exportExcel}).inject(this.exportAreaNode);
  96. }
  97. },
  98. exportView: function(){
  99. var action = MWF.Actions.get("x_query_assemble_surface");
  100. var filterData = this.json.filter ? this.json.filter.clone() : [];
  101. if (this.filterItems.length){
  102. this.filterItems.each(function(filter){
  103. filterData.push(filter.data);
  104. }.bind(this));
  105. }
  106. action.exportViewWithQuery(this.json.viewName, this.json.application, {"filterList": filterData}, function(json){
  107. var uri = action.action.actions.getViewExcel.uri;
  108. uri = uri.replace("{flag}", json.data.id);
  109. uri = action.action.address+uri;
  110. var a = new Element("a", {"href": uri, "target":"_blank"});
  111. a.click();
  112. a.destroy();
  113. }.bind(this));
  114. },
  115. createSearchNode: function(){
  116. if (this.viewJson.customFilterList && this.viewJson.customFilterList.length){
  117. this.searchStatus = "default";
  118. this.loadFilterSearch();
  119. }else{
  120. this.loadSimpleSearch();
  121. }
  122. },
  123. loadSimpleSearch: function(){
  124. this.searchSimpleNode = new Element("div", {"styles": this.css.searchSimpleNode}).inject(this.searchAreaNode);
  125. this.searchSimpleButtonNode = new Element("div", {"styles": this.css.searchSimpleButtonNode}).inject(this.searchSimpleNode);
  126. this.searchSimpleInputNode = new Element("input", {"type":"text", "styles": this.css.searchSimpleInputNode, "value": this.lp.searchKeywork}).inject(this.searchSimpleNode);
  127. this.searchSimpleButtonNode.addEvent("click", function(){
  128. this.search();
  129. }.bind(this));
  130. this.searchSimpleInputNode.addEvents({
  131. "focus": function(){
  132. if (this.searchSimpleInputNode.get("value")===this.lp.searchKeywork) this.searchSimpleInputNode.set("value", "");
  133. }.bind(this),
  134. "blur": function(){if (!this.searchSimpleInputNode.get("value")) this.searchSimpleInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  135. "keydown": function(e){
  136. if (e.code===13) this.search();
  137. }.bind(this)
  138. });
  139. },
  140. search: function(){
  141. if (this.gridJson){
  142. var key = this.searchSimpleInputNode.get("value");
  143. var rows = this.viewTable.rows;
  144. var first = (this.json.isTitle!=="no") ? 1 : 0;
  145. for (var i = first; i<rows.length; i++){
  146. var tr = rows[i];
  147. if (!key || key==this.lp.searchKeywork){
  148. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  149. }else{
  150. if (tr.get("text").indexOf(key)!==-1){
  151. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  152. }else{
  153. if (tr.getStyle("display")!=="none") tr.setStyle("display", "none");
  154. }
  155. }
  156. }
  157. }
  158. },
  159. loadFilterSearch: function(){
  160. this.viewSearchCustomActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomActionNode, "text": this.lp.customSearch}).inject(this.searchAreaNode);
  161. this.viewSearchInputAreaNode = new Element("div", {"styles": this.css.viewFilterSearchInputAreaNode}).inject(this.searchAreaNode);
  162. this.viewSearchIconNode = new Element("div", {"styles": this.css.viewFilterSearchIconNode}).inject(this.viewSearchInputAreaNode);
  163. this.viewSearchInputBoxNode = new Element("div", {"styles": this.css.viewFilterSearchInputBoxNode}).inject(this.viewSearchInputAreaNode);
  164. this.viewSearchInputNode = new Element("input", {"styles": this.css.viewFilterSearchInputNode, "value": this.lp.searchKeywork}).inject(this.viewSearchInputBoxNode);
  165. this.viewSearchInputNode.addEvents({
  166. "focus": function(){
  167. if (this.viewSearchInputNode.get("value")===this.lp.searchKeywork) this.viewSearchInputNode.set("value", "");
  168. }.bind(this),
  169. "blur": function(){if (!this.viewSearchInputNode.get("value")) this.viewSearchInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  170. "keydown": function(e){
  171. if (e.code===13) this.searchView();
  172. }.bind(this)
  173. });
  174. this.viewSearchIconNode.addEvents({
  175. "click": function(){this.searchView();}.bind(this)
  176. });
  177. this.viewSearchCustomActionNode.addEvents({
  178. "click": function(){this.loadCustomSearch();}.bind(this)
  179. });
  180. },
  181. searchView: function(){
  182. if (this.viewJson.customFilterList) {
  183. var key = this.viewSearchInputNode.get("value");
  184. if (key && key !== this.lp.searchKeywork) {
  185. var filterData = this.json.filter ? this.json.filter : [];
  186. this.viewJson.customFilterList.each(function (entry) {
  187. if (entry.formatType === "textValue") {
  188. var d = {
  189. "path": entry.path,
  190. "value": key,
  191. "formatType": entry.formatType,
  192. "logic": "or",
  193. "comparison": "like"
  194. };
  195. filterData.push(d);
  196. }
  197. if (entry.formatType === "numberValue") {
  198. var v = key.toFloat();
  199. if (!isNaN(v)) {
  200. var d = {
  201. "path": entry.path,
  202. "value": v,
  203. "formatType": entry.formatType,
  204. "logic": "or",
  205. "comparison": "like"
  206. };
  207. filterData.push(d);
  208. }
  209. }
  210. }.bind(this));
  211. this.createViewNode({"filterList": filterData});
  212. }else{
  213. this.createViewNode();
  214. }
  215. }
  216. },
  217. searchCustomView: function(){
  218. if (this.filterItems.length){
  219. var filterData = this.json.filter ? this.json.filter.clone() : [];
  220. this.filterItems.each(function(filter){
  221. filterData.push(filter.data);
  222. }.bind(this));
  223. this.createViewNode({"filterList": filterData});
  224. }else{
  225. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  226. }
  227. },
  228. loadCustomSearch: function(){
  229. this.viewSearchIconNode.setStyle("display", "none");
  230. this.viewSearchInputBoxNode.setStyle("display", "none");
  231. this.viewSearchCustomActionNode.setStyle("display", "none");
  232. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  233. var x = this.viewSearchInputAreaNode.getParent().getSize().x-2-20;
  234. this.css.viewFilterSearchInputAreaNode_custom.width = ""+x+"px";
  235. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  236. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  237. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode_custom).chain(function(){
  238. this.searchStatus = "custom";
  239. this.css.viewFilterSearchInputAreaNode_custom.width = "auto";
  240. this.viewSearchInputAreaNode.setStyle("width", "auto");
  241. if (this.viewSearchCustomContentNode){
  242. this.viewSearchCustomCloseActionNode.setStyle("display", "block");
  243. this.viewSearchCustomContentNode.setStyle("display", "block");
  244. }else{
  245. this.loadCustomSearchContent();
  246. }
  247. this.setContentHeightFun();
  248. }.bind(this));
  249. this.searchCustomView();
  250. },
  251. loadCustomSearchContent: function(){
  252. this.viewSearchCustomCloseActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomCloseActionNode}).inject(this.viewSearchInputAreaNode);
  253. this.viewSearchCustomContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomContentNode}).inject(this.viewSearchInputAreaNode);
  254. this.viewSearchCustomPathContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomPathContentNode}).inject(this.viewSearchCustomContentNode);
  255. this.viewSearchCustomComparisonContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomComparisonContentNode}).inject(this.viewSearchCustomContentNode);
  256. this.viewSearchCustomValueContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomValueContentNode}).inject(this.viewSearchCustomContentNode);
  257. this.viewSearchCustomAddContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddContentNode}).inject(this.viewSearchCustomContentNode);
  258. this.viewSearchCustomAddIconNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddIconNode}).inject(this.viewSearchCustomAddContentNode);
  259. this.viewSearchCustomFilterContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomFilterContentNode}).inject(this.viewSearchCustomContentNode);
  260. this.loadViewSearchCustomList();
  261. this.viewSearchCustomCloseActionNode.addEvents({
  262. "click": function(){this.closeCustomSearch();}.bind(this)
  263. });
  264. this.viewSearchCustomAddIconNode.addEvents({
  265. "click": function(){this.viewSearchCustomAddToFilter();}.bind(this)
  266. });
  267. },
  268. loadViewSearchCustomList: function(){
  269. this.viewSearchCustomPathListNode = new Element("select", {
  270. "styles": this.css.viewFilterSearchCustomPathListNode,
  271. "multiple": true
  272. }).inject(this.viewSearchCustomPathContentNode);
  273. this.viewSearchCustomComparisonListNode = new Element("select", {
  274. "styles": this.css.viewFilterSearchCustomComparisonListNode,
  275. "multiple": true
  276. }).inject(this.viewSearchCustomComparisonContentNode);
  277. this.viewJson.customFilterList.each(function(entry){
  278. var option = new Element("option", {
  279. "style": this.css.viewFilterSearchOptionNode,
  280. "value": entry.path,
  281. "text": entry.title
  282. }).inject(this.viewSearchCustomPathListNode);
  283. option.store("entry", entry);
  284. }.bind(this));
  285. this.viewSearchCustomPathListNode.addEvent("change", function(){
  286. this.loadViewSearchCustomComparisonList();
  287. }.bind(this));
  288. },
  289. loadViewSearchCustomComparisonList: function(){
  290. var idx = this.viewSearchCustomPathListNode.selectedIndex;
  291. var option = this.viewSearchCustomPathListNode.options[idx];
  292. var entry = option.retrieve("entry");
  293. if (entry){
  294. switch (entry.formatType){
  295. case "numberValue":
  296. this.loadComparisonSelect(this.lp.numberFilter);
  297. this.loadViewSearchCustomValueNumberInput();
  298. break;
  299. case "dateTimeValue":
  300. this.loadComparisonSelect(this.lp.dateFilter);
  301. this.loadViewSearchCustomValueDateTimeInput();
  302. break;
  303. case "dateValue":
  304. this.loadComparisonSelect(this.lp.dateFilter);
  305. this.loadViewSearchCustomValueDateInput();
  306. break;
  307. case "timeValue":
  308. this.loadComparisonSelect(this.lp.dateFilter);
  309. this.loadViewSearchCustomValueTimeInput();
  310. break;
  311. case "booleanValue":
  312. this.loadComparisonSelect(this.lp.booleanFilter);
  313. this.loadViewSearchCustomValueBooleanInput();
  314. break;
  315. default:
  316. this.loadComparisonSelect(this.lp.textFilter);
  317. this.loadViewSearchCustomValueTextInput();
  318. }
  319. }
  320. },
  321. loadViewSearchCustomValueNumberInput: function(){
  322. this.viewSearchCustomValueContentNode.empty();
  323. this.viewSearchCustomValueNode = new Element("input", {
  324. "styles": this.css.viewFilterSearchCustomValueNode,
  325. "type": "number"
  326. }).inject(this.viewSearchCustomValueContentNode);
  327. },
  328. loadViewSearchCustomValueDateTimeInput: function(){
  329. this.viewSearchCustomValueContentNode.empty();
  330. this.viewSearchCustomValueNode = new Element("input", {
  331. "styles": this.css.viewFilterSearchCustomValueNode,
  332. "type": "text",
  333. "readonly": true
  334. }).inject(this.viewSearchCustomValueContentNode);
  335. MWF.require("MWF.widget.Calendar", function(){
  336. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  337. "style": "xform",
  338. "isTime": true,
  339. "target": this.container,
  340. "format": "db"
  341. });
  342. }.bind(this));
  343. },
  344. loadViewSearchCustomValueDateInput: function(){
  345. this.viewSearchCustomValueContentNode.empty();
  346. this.viewSearchCustomValueNode = new Element("input", {
  347. "styles": this.css.viewFilterSearchCustomValueNode,
  348. "type": "text",
  349. "readonly": true
  350. }).inject(this.viewSearchCustomValueContentNode);
  351. MWF.require("MWF.widget.Calendar", function(){
  352. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  353. "style": "xform",
  354. "isTime": false,
  355. "target": this.container,
  356. "format": "%Y-%m-%d"
  357. });
  358. }.bind(this));
  359. },
  360. loadViewSearchCustomValueTimeInput: 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. "timeOnly": true,
  371. "target": this.container,
  372. "format": "%H:%M:%S"
  373. });
  374. }.bind(this));
  375. },
  376. loadViewSearchCustomValueBooleanInput: function(){
  377. this.viewSearchCustomValueContentNode.empty();
  378. this.viewSearchCustomValueNode = new Element("select", {
  379. "styles": this.css.viewFilterSearchCustomValueSelectNode,
  380. "multiple": true
  381. }).inject(this.viewSearchCustomValueContentNode);
  382. new Element("option", {"value": "true","text": this.lp.yes}).inject(this.viewSearchCustomValueNode);
  383. new Element("option", {"value": "false","text": this.lp.no}).inject(this.viewSearchCustomValueNode);
  384. },
  385. loadViewSearchCustomValueTextInput: function(){
  386. this.viewSearchCustomValueContentNode.empty();
  387. this.viewSearchCustomValueNode = new Element("textarea", {
  388. "styles": this.css.viewFilterSearchCustomValueNode
  389. }).inject(this.viewSearchCustomValueContentNode);
  390. },
  391. loadComparisonSelect:function(obj){
  392. this.viewSearchCustomComparisonListNode.empty();
  393. Object.each(obj, function(v, k){
  394. var option = new Element("option", {"value": k,"text": v}).inject(this.viewSearchCustomComparisonListNode);
  395. }.bind(this));
  396. },
  397. closeCustomSearch: function(){
  398. if (this.viewSearchCustomContentNode && this.viewSearchCustomContentNode.getStyle("display")==="block"){
  399. this.viewSearchCustomCloseActionNode.setStyle("display", "none");
  400. this.viewSearchCustomContentNode.setStyle("display", "none");
  401. var x = this.viewSearchInputAreaNode.getParent().getSize().x;
  402. x1 = x-2-10-90;
  403. this.css.viewFilterSearchInputAreaNode.width = ""+x1+"px";
  404. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  405. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  406. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  407. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode).chain(function(){
  408. this.searchStatus = "default";
  409. this.css.viewFilterSearchInputAreaNode.width = "auto";
  410. this.viewSearchInputAreaNode.setStyle("margin-right", "90px");
  411. this.viewSearchIconNode.setStyle("display", "block");
  412. this.viewSearchInputBoxNode.setStyle("display", "block");
  413. this.viewSearchCustomActionNode.setStyle("display", "block");
  414. this.setContentHeightFun();
  415. }.bind(this));
  416. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  417. }
  418. },
  419. viewSearchCustomAddToFilter: function(){
  420. var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
  421. var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
  422. if (pathIdx===-1){
  423. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
  424. return false;
  425. }
  426. if (comparisonIdx===-1){
  427. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
  428. return false;
  429. }
  430. var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
  431. var entry = pathOption.retrieve("entry");
  432. if (entry){
  433. var pathTitle = entry.title;
  434. var path = entry.path;
  435. var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
  436. var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
  437. var value = "";
  438. switch (entry.formatType){
  439. case "numberValue":
  440. value = this.viewSearchCustomValueNode.get("value");
  441. break;
  442. case "dateTimeValue":
  443. value = this.viewSearchCustomValueNode.get("value");
  444. break;
  445. case "booleanValue":
  446. var idx = this.viewSearchCustomValueNode.selectedIndex;
  447. if (idx!==-1){
  448. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  449. value = (v==="true");
  450. }
  451. break;
  452. default:
  453. value = this.viewSearchCustomValueNode.get("value");
  454. }
  455. if (value===""){
  456. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
  457. return false;
  458. }
  459. this.filterItems.push(new MWF.xApplication.query.Query.Viewer.Filter(this, {
  460. "logic": "and",
  461. "path": path,
  462. "title": pathTitle,
  463. "comparison": comparison,
  464. "comparisonTitle": comparisonTitle,
  465. "value": value,
  466. "formatType": (entry.formatType=="datetimeValue") ? "dateTimeValue": entry.formatType
  467. }, this.viewSearchCustomFilterContentNode));
  468. this.searchCustomView();
  469. }
  470. },
  471. searchViewRemoveFilter: function(filter){
  472. this.filterItems.erase(filter);
  473. filter.destroy();
  474. this.searchCustomView()
  475. },
  476. setContentHeight: function(){
  477. var size = this.node.getSize();
  478. var searchSize = this.searchAreaNode.getComputedSize();
  479. var h = size.y-searchSize.totalHeight;
  480. if (this.exportAreaNode){
  481. var exportSize = this.exportAreaNode.getComputedSize();
  482. h = h-exportSize.totalHeight;
  483. }
  484. var pageSize = this.viewPageNode.getComputedSize();
  485. h = h-pageSize.totalHeight;
  486. this.viewAreaNode.setStyle("height", ""+h+"px");
  487. },
  488. createLoadding: function(){
  489. this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.contentAreaNode);
  490. new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
  491. var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
  492. new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
  493. var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
  494. loadingTextNode.set("text", "loading...");
  495. },
  496. createViewNode: function(data){
  497. this.viewAreaNode.empty();
  498. this.contentAreaNode = new Element("div", {"styles": this.css.contentAreaNode}).inject(this.viewAreaNode);
  499. this.viewTable = new Element("table", {
  500. "styles": this.css.viewTitleTableNode,
  501. "border": "0px",
  502. "cellPadding": "0",
  503. "cellSpacing": "0"
  504. }).inject(this.contentAreaNode);
  505. this.createLoadding();
  506. if (this.json.isTitle!=="no"){
  507. this.viewTitleLine = new Element("tr", {"styles": this.css.viewTitleLineNode}).inject(this.viewTable);
  508. //if (this.json.select==="single" || this.json.select==="multi") {
  509. this.selectTitleCell = new Element("td", {
  510. "styles": this.css.viewTitleCellNode
  511. }).inject(this.viewTitleLine);
  512. this.selectTitleCell.setStyle("width", "10px");
  513. if (this.json.titleStyles) this.selectTitleCell.setStyles(this.json.titleStyles);
  514. //}
  515. //序号
  516. if (this.viewJson.isSequence==="yes"){
  517. this.sequenceTitleCell = new Element("td", {
  518. "styles": this.css.viewTitleCellNode
  519. }).inject(this.viewTitleLine);
  520. this.sequenceTitleCell.setStyle("width", "10px");
  521. if (this.json.titleStyles) this.sequenceTitleCell.setStyles(this.json.titleStyles);
  522. }
  523. this.entries = {};
  524. this.viewJson.selectList.each(function(column){
  525. this.entries[column.column] = column;
  526. if (!column.hideColumn){
  527. var viewCell = new Element("td", {
  528. "styles": this.css.viewTitleCellNode,
  529. "text": column.displayName
  530. }).inject(this.viewTitleLine);
  531. var size = MWF.getTextSize(column.displayName, this.css.viewTitleCellNode);
  532. viewCell.setStyle("min-width", ""+size.x+"px");
  533. if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  534. }else{
  535. this.hideColumns.push(column.column);
  536. }
  537. if (column.allowOpen) this.openColumns.push(column.column);
  538. }.bind(this));
  539. this.lookup(data);
  540. }else{
  541. this.viewJson.selectList.each(function(column){
  542. if (column.hideColumn) this.hideColumns.push(column.column);
  543. if (!column.allowOpen) this.openColumns.push(column.column);
  544. }.bind(this));
  545. this.lookup(data);
  546. }
  547. },
  548. _loadPageCountNode: function(){
  549. this.viewPageContentNode.empty();
  550. var size = this.viewPageAreaNode.getSize();
  551. var w1 = this.viewPageFirstNode.getSize().x*2;
  552. var w2 = this.viewPageContentNode.getStyle("margin-left").toInt();
  553. var w = size.x-w1-w2;
  554. var bw = this.css.viewPageButtonNode.width.toInt()+this.css.viewPageButtonNode["margin-right"].toInt();
  555. var count = (w/bw).toInt()-2;
  556. if (count>10) count = 10;
  557. this.showPageCount = Math.min(count, this.pages);
  558. var tmp = this.showPageCount/2;
  559. var n = tmp.toInt();
  560. var left = this.currentPage-n;
  561. if (left<=0) left = 1;
  562. var right = this.showPageCount + left-1;
  563. if (right>this.pages) right = this.pages;
  564. left = right-this.showPageCount+1;
  565. if (left<=1) left = 1;
  566. this.viewPagePrevNode = new Element("div", {"styles": this.css.viewPagePrevButtonNode}).inject(this.viewPageContentNode);
  567. this.loadPageButtonEvent(this.viewPagePrevNode, "viewPagePrevButtonNode_over", "viewPagePrevButtonNode_up", "viewPagePrevButtonNode_down", function(){
  568. if (this.currentPage>1) this.currentPage--;
  569. this.loadCurrentPageData();
  570. }.bind(this));
  571. for (i=left; i<=right; i++){
  572. var node = new Element("div", {"styles": this.css.viewPageButtonNode, "text": i}).inject(this.viewPageContentNode);
  573. if (i==this.currentPage){
  574. node.setStyles(this.css.viewPageButtonNode_current);
  575. }else{
  576. this.loadPageButtonEvent(node, "viewPageButtonNode_over", "viewPageButtonNode_up", "viewPageButtonNode_down", function(e){
  577. this.currentPage = e.target.get("text").toInt();
  578. this.loadCurrentPageData();
  579. }.bind(this));
  580. }
  581. }
  582. this.viewPageNextNode = new Element("div", {"styles": this.css.viewPageNextButtonNode}).inject(this.viewPageContentNode);
  583. this.loadPageButtonEvent(this.viewPageNextNode, "viewPageNextButtonNode_over", "viewPageNextButtonNode_up", "viewPageNextButtonNode_down", function(){
  584. if (this.currentPage<=this.pages-1) this.currentPage++;
  585. this.loadCurrentPageData();
  586. }.bind(this));
  587. },
  588. loadPageButtonEvent: function(node, over, out, down, click){
  589. node.addEvents({
  590. "mouseover": function(){node.setStyles(this.css[over])}.bind(this),
  591. "mouseout": function(){node.setStyles(this.css[out])}.bind(this),
  592. "mousedown": function(){node.setStyles(this.css[down])}.bind(this),
  593. "mouseup": function(){node.setStyles(this.css[out])}.bind(this),
  594. "click": click,
  595. });
  596. },
  597. _loadPageNode: function(){
  598. this.viewPageAreaNode.empty();
  599. this.viewPageFirstNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.firstPage}).inject(this.viewPageAreaNode);
  600. this.viewPageContentNode = new Element("div", {"styles": this.css.viewPageContentNode}).inject(this.viewPageAreaNode);
  601. this.viewPageLastNode = new Element("div", {"styles": this.css.viewPageFirstLastNode, "text": this.lp.lastPage}).inject(this.viewPageAreaNode);
  602. this._loadPageCountNode();
  603. this.loadPageButtonEvent(this.viewPageFirstNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
  604. this.currentPage = 1;
  605. this.loadCurrentPageData();
  606. }.bind(this));
  607. this.loadPageButtonEvent(this.viewPageLastNode, "viewPageFirstLastNode_over", "viewPageFirstLastNode_up", "viewPageFirstLastNode_down", function(){
  608. this.currentPage = this.pages;
  609. this.loadCurrentPageData();
  610. }.bind(this));
  611. },
  612. _initPage: function(){
  613. this.count = this.bundleItems.length;
  614. var i = this.count/this.json.pageSize;
  615. this.pages = (i.toInt()<i) ? i.toInt()+1 : i;
  616. this.currentPage = 1;
  617. },
  618. lookup: function(data){
  619. this.getLookupAction(function(){
  620. if (this.json.application){
  621. var d = data || {};
  622. d.count = this.json.count;
  623. this.lookupAction.bundleView(this.json.id, d, function(json){
  624. this.bundleItems = json.data.valueList;
  625. this._initPage();
  626. if (this.bundleItems.length){
  627. this.loadCurrentPageData();
  628. }else{
  629. //this._loadPageNode();
  630. if (this.loadingAreaNode){
  631. this.loadingAreaNode.destroy();
  632. this.loadingAreaNode = null;
  633. }
  634. }
  635. }.bind(this));
  636. }
  637. }.bind(this));
  638. },
  639. loadCurrentPageData: function(){
  640. var p = this.currentPage;
  641. var d = {};
  642. var valueList = this.bundleItems.slice((p-1)*this.json.pageSize,this.json.pageSize*p);
  643. d.bundleList = valueList;
  644. while (this.viewTable.rows.length>1){
  645. this.viewTable.deleteRow(-1);
  646. }
  647. //this.createLoadding();
  648. this.loadViewRes = this.lookupAction.loadView(this.json.name, this.json.application, d, function(json){
  649. this.viewData = json.data;
  650. if (this.viewJson.group.column){
  651. this.gridJson = json.data.groupGrid;
  652. this.loadGroupData();
  653. }else{
  654. this.gridJson = json.data.grid;
  655. this.loadData();
  656. }
  657. if (this.gridJson.length) this._loadPageNode();
  658. if (this.loadingAreaNode){
  659. this.loadingAreaNode.destroy();
  660. this.loadingAreaNode = null;
  661. }
  662. this.fireEvent("loadView");
  663. }.bind(this));
  664. },
  665. loadData: function(){
  666. if (this.gridJson.length){
  667. // if( !this.options.paging ){
  668. this.gridJson.each(function(line, i){
  669. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, line, null, i));
  670. }.bind(this));
  671. // }else{
  672. // this.loadPaging();
  673. // }
  674. }else{
  675. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  676. }
  677. },
  678. loadPaging : function(){
  679. this.isItemsLoading = false;
  680. this.pageNumber = 0;
  681. this.isItemsLoaded = false;
  682. this.isSetedScroll = false;
  683. this.setScroll();
  684. this.loadDataByPaging()
  685. },
  686. setScroll : function(){
  687. if( this.options.paging && !this.isSetedScroll ){
  688. this.contentAreaNode.setStyle("overflow","auto");
  689. this.scrollContainerFun = function(){
  690. var scrollSize = this.contentAreaNode.getScrollSize();
  691. var clientSize = this.contentAreaNode.getSize();
  692. var scrollHeight = scrollSize.y - clientSize.y;
  693. //alert( "clientSize.y=" + clientSize.y + " scrollSize.y="+scrollSize.y + " this.contentAreaNode.scrollTop="+this.contentAreaNode.scrollTop);
  694. if (this.contentAreaNode.scrollTop + 150 > scrollHeight ) {
  695. if (!this.isItemsLoaded) this.loadDataByPaging();
  696. }
  697. }.bind(this);
  698. this.isSetedScroll = true;
  699. this.contentAreaNode.addEvent("scroll", this.scrollContainerFun )
  700. }
  701. },
  702. loadDataByPaging : function(){
  703. if( this.isItemsLoading )return;
  704. if( !this.isItemsLoaded ){
  705. var from = Math.min( this.pageNumber * this.options.perPageCount , this.gridJson.length);
  706. var to = Math.min( ( this.pageNumber + 1 ) * this.options.perPageCount + 1 , this.gridJson.length);
  707. this.isItemsLoading = true;
  708. for( var i = from; i<to; i++ ){
  709. this.items.push(new MWF.xApplication.query.Query.Viewer.Item(this, this.gridJson[i], null, i));
  710. }
  711. this.isItemsLoading = false;
  712. this.pageNumber ++;
  713. if( to == this.gridJson.length )this.isItemsLoaded = true;
  714. }
  715. },
  716. loadGroupData: function(){
  717. if (this.selectTitleCell){
  718. this.selectTitleCell.set("html", "<span style='font-family: Webdings'>"+"<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>"+"</span>");
  719. this.selectTitleCell.setStyle("cursor", "pointer");
  720. this.selectTitleCell.addEvent("click", this.expandOrCollapseAll.bind(this));
  721. }
  722. if (this.gridJson.length){
  723. var i = 0;
  724. this.gridJson.each(function(data){
  725. this.items.push(new MWF.xApplication.query.Query.Viewer.ItemCategory(this, data, i));
  726. i += data.list.length;
  727. }.bind(this));
  728. if (this.json.isExpand=="yes") this.expandOrCollapseAll();
  729. }else{
  730. if (this.viewPageAreaNode) this.viewPageAreaNode.empty();
  731. }
  732. },
  733. expandOrCollapseAll: function(){
  734. var icon = this.selectTitleCell.getElement("span");
  735. if (icon.get("html").indexOf("expand.png")===-1){
  736. this.items.each(function(item){
  737. item.collapse();
  738. icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/expand.png'/>");
  739. }.bind(this));
  740. }else{
  741. this.items.each(function(item, i){
  742. window.setTimeout(function(){
  743. item.expand();
  744. }.bind(this), 10*i+5);
  745. icon.set("html", "<img src='/x_component_query_Query/$Viewer/"+this.options.style+"/icon/down.png'/>");
  746. }.bind(this));
  747. }
  748. },
  749. getView: function(callback){
  750. this.getLookupAction(function(){
  751. if (this.json.application){
  752. this.getViewRes = this.lookupAction.getView(this.json.viewName, this.json.application, function(json){
  753. this.viewJson = JSON.decode(json.data.data);
  754. this.json = Object.merge(this.json, json.data);
  755. if (callback) callback();
  756. }.bind(this));
  757. // this.lookupAction.invoke({"name": "getView","async": true, "parameter": {"view": this.json.viewName, "application": this.json.application},"success": function(json){
  758. // this.viewJson = JSON.decode(json.data.data);
  759. // this.json = Object.merge(this.json, json.data);
  760. // //var viewData = JSON.decode(json.data.data);
  761. // if (callback) callback();
  762. // }.bind(this)});
  763. }else{
  764. this.getViewRes = this.lookupAction.getViewById(this.json.viewId, function(json){
  765. this.viewJson = JSON.decode(json.data.data);
  766. this.json.application = json.data.query;
  767. this.json = Object.merge(this.json, json.data);
  768. if (callback) callback();
  769. }.bind(this));
  770. }
  771. }.bind(this));
  772. },
  773. getLookupAction: function(callback){
  774. if (!this.lookupAction){
  775. this.lookupAction = MWF.Actions.get("x_query_assemble_surface");
  776. if (callback) callback();
  777. // var _self = this;
  778. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  779. // this.lookupAction = new MWF.xDesktop.Actions.RestActions("", this.options.actionRoot, "");
  780. // this.lookupAction.getActions = function(actionCallback){
  781. // this.actions = _self.options.actions;
  782. // if (actionCallback) actionCallback();
  783. // };
  784. // if (callback) callback();
  785. // }.bind(this));
  786. }else{
  787. if (callback) callback();
  788. }
  789. },
  790. hide: function(){
  791. this.node.setStyle("display", "none");
  792. },
  793. reload: function(){
  794. this.node.setStyle("display", "block");
  795. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  796. this.filterItems.each(function(filter){
  797. filter.destroy();
  798. }.bind(this));
  799. this.filterItems = [];
  800. if (this.viewSearchInputNode) this.viewSearchInputNode.set("text", this.lp.searchKeywork);
  801. this.closeCustomSearch();
  802. this.viewAreaNode.empty();
  803. this.createViewNode({"filterList": this.json.filter ? this.json.filter.clone() : null});
  804. },
  805. getFilter: function(){
  806. var filterData = [];
  807. if (this.searchStatus==="custom"){
  808. if (this.filterItems.length){
  809. this.filterItems.each(function(filter){
  810. filterData.push(filter.data);
  811. }.bind(this));
  812. }
  813. }
  814. if (this.searchStatus==="default"){
  815. var key = this.viewSearchInputNode.get("value");
  816. if (key && key!==this.lp.searchKeywork){
  817. this.viewJson.customFilterList.each(function(entry){
  818. if (entry.formatType==="textValue"){
  819. var d = {
  820. "path": entry.path,
  821. "value": key,
  822. "formatType": entry.formatType,
  823. "logic": "or",
  824. "comparison": "like"
  825. };
  826. filterData.push(d);
  827. }
  828. if (entry.formatType==="numberValue"){
  829. var v = key.toFloat();
  830. if (!isNaN(v)){
  831. var d = {
  832. "path": entry.path,
  833. "value": v,
  834. "formatType": entry.formatType,
  835. "logic": "or",
  836. "comparison": "like"
  837. };
  838. filterData.push(d);
  839. }
  840. }
  841. }.bind(this));
  842. }
  843. }
  844. return (filterData.length) ? filterData : null;
  845. },
  846. getData: function(){
  847. if (this.selectedItems.length){
  848. var arr = [];
  849. this.selectedItems.each(function(item){
  850. arr.push(item.data);
  851. });
  852. return arr;
  853. }else{
  854. return [];
  855. }
  856. }
  857. });
  858. MWF.xApplication.query.Query.Viewer.Item = new Class({
  859. initialize: function(view, data, prev, i){
  860. this.view = view;
  861. this.data = data;
  862. this.css = this.view.css;
  863. this.isSelected = false;
  864. this.prev = prev;
  865. this.idx = i;
  866. this.load();
  867. },
  868. load: function(){
  869. this.node = new Element("tr", {"styles": this.css.viewContentTrNode});
  870. if (this.prev){
  871. this.node.inject(this.prev.node, "after");
  872. }else{
  873. this.node.inject(this.view.viewTable);
  874. }
  875. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  876. this.selectTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  877. this.selectTd.setStyles({"cursor": "pointer"});
  878. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  879. //}
  880. //序号
  881. if (this.view.viewJson.isSequence==="yes"){
  882. this.sequenceTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  883. this.sequenceTd.setStyle("width", "10px");
  884. var s= 1+this.view.json.pageSize*(this.view.currentPage-1)+this.idx;
  885. this.sequenceTd.set("text", s);
  886. }
  887. Object.each(this.view.entries, function(c, k){
  888. var cell = this.data.data[k];
  889. if (cell === undefined) cell = "";
  890. //if (cell){
  891. if (this.view.hideColumns.indexOf(k)===-1){
  892. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  893. if (k!== this.view.viewJson.group.column){
  894. //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;
  895. var v = cell;
  896. if (c.isHtml){
  897. td.set("html", v);
  898. }else{
  899. td.set("text", v);
  900. }
  901. }
  902. if (this.view.openColumns.indexOf(k)!==-1){
  903. this.setOpenWork(td)
  904. }
  905. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  906. }
  907. //}
  908. }.bind(this));
  909. // Object.each(this.data.data, function(cell, k){
  910. // if (this.view.hideColumns.indexOf(k)===-1){
  911. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  912. // if (k!== this.view.viewJson.group.column){
  913. // 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;
  914. // td.set("text", v);
  915. // }
  916. // if (this.view.openColumns.indexOf(k)!==-1){
  917. // this.setOpenWork(td)
  918. // }
  919. // if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  920. // }
  921. // }.bind(this));
  922. this.setEvent();
  923. },
  924. setOpenWork: function(td){
  925. td.setStyle("cursor", "pointer");
  926. if (this.view.json.type==="cms"){
  927. td.addEvent("click", this.openCms.bind(this));
  928. }else{
  929. td.addEvent("click", this.openWorkAndCompleted.bind(this));
  930. }
  931. },
  932. openCms: function(e){
  933. var options = {"documentId": this.data.bundle};
  934. this.view.fireEvent("openDocument", [options, this]);
  935. layout.desktop.openApplication(e, "cms.Document", options);
  936. },
  937. openWorkAndCompleted: function(e){
  938. MWF.Actions.get("x_processplatform_assemble_surface").listWorkByJob(this.data.bundle, function(json){
  939. var workCompletedCount = json.data.workCompletedList.length;
  940. var workCount = json.data.workList.length;
  941. var count = workCount+workCompletedCount;
  942. if (count===1){
  943. if (workCompletedCount) {
  944. this.openWorkCompleted(json.data.workCompletedList[0].id, e);
  945. }else{
  946. this.openWork(json.data.workList[0].id, e);
  947. }
  948. }else if (count>1){
  949. var worksAreaNode = this.createWorksArea();
  950. json.data.workCompletedList.each(function(work){
  951. this.createWorkCompletedNode(work, worksAreaNode);
  952. }.bind(this));
  953. json.data.workList.each(function(work){
  954. this.createWorkNode(work, worksAreaNode);
  955. }.bind(this));
  956. this.showWorksArea(worksAreaNode, e);
  957. }else{
  958. }
  959. }.bind(this));
  960. },
  961. createWorkNode: function(work, worksAreaNode){
  962. var worksAreaContentNode = worksAreaNode.getLast();
  963. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  964. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  965. actionNode.store("workId", work.id);
  966. actionNode.addEvent("click", function(e){
  967. this.openWork(e.target.retrieve("workId"), e);
  968. this.mask.hide();
  969. worksAreaNode.destroy();
  970. }.bind(this));
  971. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  972. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  973. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  974. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  975. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": work.activityName}).inject(contentNode);
  976. var taskUsers = [];
  977. MWF.Actions.get("x_processplatform_assemble_surface").listTaskByWork(work.id, function(json){
  978. json.data.each(function(task){
  979. taskUsers.push(MWF.name.cn(task.person));
  980. }.bind(this));
  981. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.taskPeople+": "}).inject(contentNode);
  982. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": taskUsers.join(", ")}).inject(contentNode);
  983. }.bind(this));
  984. },
  985. createWorkCompletedNode: function(work, worksAreaNode){
  986. var worksAreaContentNode = worksAreaNode.getLast();
  987. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  988. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  989. actionNode.store("workId", work.id);
  990. actionNode.addEvent("click", function(e){
  991. this.mask.hide();
  992. worksAreaNode.destroy();
  993. this.openWorkCompleted(e.target.retrieve("workId"), e)
  994. }.bind(this));
  995. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  996. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  997. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  998. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  999. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": this.view.lp.processCompleted}).inject(contentNode);
  1000. },
  1001. createWorksArea: function(){
  1002. var worksAreaNode = new Element("div", {"styles": this.css.worksAreaNode});
  1003. var worksAreaTitleNode = new Element("div", {"styles": this.css.worksAreaTitleNode}).inject(worksAreaNode);
  1004. var worksAreaTitleCloseNode = new Element("div", {"styles": this.css.worksAreaTitleCloseNode}).inject(worksAreaTitleNode);
  1005. worksAreaTitleCloseNode.addEvent("click", function(e){
  1006. this.mask.hide();
  1007. e.target.getParent().getParent().destroy();
  1008. }.bind(this));
  1009. var worksAreaContentNode = new Element("div", {"styles": this.css.worksAreaContentNode}).inject(worksAreaNode);
  1010. return worksAreaNode;
  1011. },
  1012. showWorksArea: function(node, e){
  1013. MWF.require("MWF.widget.Mask", null, false);
  1014. this.mask = new MWF.widget.Mask({"style": "desktop", "loading": false});
  1015. this.mask.loadNode(this.view.container);
  1016. node.inject(this.view.node);
  1017. this.setWorksAreaPosition(node, e.target);
  1018. },
  1019. setWorksAreaPosition: function(node, td){
  1020. var p = td.getPosition(this.view.container);
  1021. var containerS = this.view.container.getSize();
  1022. var containerP = this.view.container.getPosition(this.view.container.getOffsetParent());
  1023. var s = node.getSize();
  1024. var offX = p.x+s.x-containerS.x;
  1025. offX = (offX>0) ? offX+20 : 0;
  1026. var offY = p.y+s.y-containerS.y;
  1027. offY = (offY>0) ? offY+5 : 0;
  1028. node.position({
  1029. "relativeTo": td,
  1030. "position": "lefttop",
  1031. "edge": "lefttop",
  1032. "offset": {
  1033. "x": 0-offX,
  1034. "y": 0-offY
  1035. }
  1036. });
  1037. },
  1038. openWork: function(id, e){
  1039. var options = {"workId": id};
  1040. this.view.fireEvent("openDocument", [options, this]);
  1041. layout.desktop.openApplication(e, "process.Work", options);
  1042. },
  1043. openWorkCompleted: function(id, e){
  1044. var options = {"workCompletedId": id};
  1045. this.view.fireEvent("openDocument", [options, this]);
  1046. layout.desktop.openApplication(e, "process.Work", options);
  1047. },
  1048. setEvent: function(){
  1049. if (this.view.json.select==="single" || this.view.json.select==="multi"){
  1050. this.node.addEvents({
  1051. "mouseover": function(){
  1052. if (!this.isSelected){
  1053. var iconName = "checkbox";
  1054. if (this.view.json.select==="single") iconName = "radiobox";
  1055. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/"+iconName+".png) center center no-repeat"});
  1056. }
  1057. }.bind(this),
  1058. "mouseout": function(){
  1059. if (!this.isSelected) this.selectTd.setStyles({"background": "transparent"});
  1060. }.bind(this),
  1061. "click": function(){this.select();}.bind(this)
  1062. });
  1063. }
  1064. },
  1065. select: function(){
  1066. if (this.isSelected){
  1067. if (this.view.json.select==="single"){
  1068. this.unSelectedSingle();
  1069. }else{
  1070. this.unSelected();
  1071. }
  1072. }else{
  1073. if (this.view.json.select==="single"){
  1074. this.selectedSingle();
  1075. }else{
  1076. this.selected();
  1077. }
  1078. }
  1079. this.view.fireEvent("select");
  1080. },
  1081. selected: function(){
  1082. this.view.selectedItems.push(this);
  1083. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/checkbox_checked.png) center center no-repeat"});
  1084. this.node.setStyles(this.css.viewContentTrNode_selected);
  1085. this.isSelected = true;
  1086. },
  1087. unSelected: function(){
  1088. this.view.selectedItems.erase(this);
  1089. this.selectTd.setStyles({"background": "transparent"});
  1090. this.node.setStyles(this.css.viewContentTrNode);
  1091. this.isSelected = false;
  1092. },
  1093. selectedSingle: function(){
  1094. if (this.view.currentSelectedItem) this.view.currentSelectedItem.unSelectedSingle();
  1095. this.view.selectedItems = [this];
  1096. this.view.currentSelectedItem = this;
  1097. this.selectTd.setStyles({"background": "url("+"/x_component_query_Query/$Viewer/default/icon/radiobox_checked.png) center center no-repeat"});
  1098. this.node.setStyles(this.css.viewContentTrNode_selected);
  1099. this.isSelected = true;
  1100. },
  1101. unSelectedSingle: function(){
  1102. this.view.selectedItems = [];
  1103. this.view.currentSelectedItem = null;
  1104. this.selectTd.setStyles({"background": "transparent"});
  1105. this.node.setStyles(this.css.viewContentTrNode);
  1106. this.isSelected = false;
  1107. }
  1108. });
  1109. MWF.xApplication.query.Query.Viewer.ItemCategory = new Class({
  1110. initialize: function(view, data, i){
  1111. this.view = view;
  1112. this.data = data;
  1113. this.css = this.view.css;
  1114. this.items = [];
  1115. this.loadChild = false;
  1116. this.idx = i;
  1117. this.load();
  1118. },
  1119. load: function(){
  1120. this.node = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.view.viewTable);
  1121. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  1122. this.selectTd = new Element("td", {"styles": this.css.viewContentCategoryTdNode}).inject(this.node);
  1123. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  1124. //}
  1125. this.categoryTd = new Element("td", {
  1126. "styles": this.css.viewContentCategoryTdNode,
  1127. "colspan": this.view.viewJson.selectList.length+1
  1128. }).inject(this.node);
  1129. this.groupColumn = null;
  1130. for (var c = 0; c<this.view.viewJson.selectList.length; c++){
  1131. if (this.view.viewJson.selectList[c].column === this.view.viewJson.group.column){
  1132. this.groupColumn = this.view.viewJson.selectList[c];
  1133. break;
  1134. }
  1135. }
  1136. if (this.groupColumn){
  1137. //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;
  1138. var text = this.data.group;
  1139. }else{
  1140. var text = this.data.group;
  1141. }
  1142. 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);
  1143. if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);
  1144. this.setEvent();
  1145. },
  1146. setEvent: function(){
  1147. //if (this.selectTd){
  1148. this.node.addEvents({
  1149. "click": function(){this.expandOrCollapse();}.bind(this)
  1150. });
  1151. //}
  1152. },
  1153. expandOrCollapse: function(){
  1154. var t = this.node.getElement("span").get("html");
  1155. if (t.indexOf("expand.png")===-1){
  1156. this.collapse();
  1157. }else{
  1158. this.expand();
  1159. }
  1160. },
  1161. collapse: function(){
  1162. this.items.each(function(item){
  1163. item.node.setStyle("display", "none");
  1164. }.bind(this));
  1165. this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/expand.png'/>");
  1166. },
  1167. expand: function(){
  1168. this.items.each(function(item){
  1169. item.node.setStyle("display", "table-row");
  1170. }.bind(this));
  1171. this.node.getElement("span").set("html", "<img src='/x_component_query_Query/$Viewer/"+this.view.options.style+"/icon/down.png'/>");
  1172. if (!this.loadChild){
  1173. //window.setTimeout(function(){
  1174. this.data.list.each(function(line, i){
  1175. var s = this.idx+i;
  1176. this.lastItem = new MWF.xApplication.query.Query.Viewer.Item(this.view, line, (this.lastItem || this), s);
  1177. this.items.push(this.lastItem);
  1178. }.bind(this));
  1179. this.loadChild = true;
  1180. //}.bind(this), 10);
  1181. }
  1182. }
  1183. });
  1184. MWF.xApplication.query.Query.Viewer.Filter = new Class({
  1185. initialize: function(viewer, data, node){
  1186. this.viewer = viewer;
  1187. this.data = data;
  1188. this.css = this.viewer.css;
  1189. this.content = node;
  1190. this.load();
  1191. },
  1192. load: function(){
  1193. this.node = new Element("div", {"styles": this.css.viewSearchFilterNode}).inject(this.content);
  1194. if (this.viewer.filterItems.length){
  1195. this.logicNode = new Element("div", {"styles": this.css.viewSearchFilterSelectAreaNode}).inject(this.node);
  1196. this.logicSelectNode = new Element("div", {
  1197. "styles": this.css.viewSearchFilterSelectNode,
  1198. "text": this.viewer.lp.and,
  1199. "value": "and"
  1200. }).inject(this.logicNode);
  1201. this.logicSelectButtonNode = new Element("div", {"styles": this.css.viewSearchFilterSelectButtonNode}).inject(this.logicNode);
  1202. this.logicNode.addEvents({
  1203. "click": function(){
  1204. var v = this.logicSelectNode.get("value");
  1205. if (v==="and"){
  1206. this.logicSelectButtonNode.setStyle("float", "left");
  1207. this.logicSelectNode.setStyle("float", "right");
  1208. this.logicSelectNode.set({
  1209. "text": this.viewer.lp.or,
  1210. "value": "or"
  1211. });
  1212. this.data.logic = "or";
  1213. }else{
  1214. this.logicSelectButtonNode.setStyle("float", "right");
  1215. this.logicSelectNode.setStyle("float", "left");
  1216. this.logicSelectNode.set({
  1217. "text": this.viewer.lp.and,
  1218. "value": "and"
  1219. });
  1220. this.data.logic = "and";
  1221. }
  1222. this.viewer.searchCustomView();
  1223. }.bind(this)
  1224. });
  1225. }
  1226. this.titleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.title}).inject(this.node);
  1227. this.comparisonTitleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.comparisonTitle}).inject(this.node);
  1228. this.valueNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": "\""+this.data.value+"\""}).inject(this.node);
  1229. this.deleteNode = new Element("div", {"styles": this.css.viewSearchFilterDeleteNode}).inject(this.node);
  1230. this.node.addEvents({
  1231. "mouseover": function(){
  1232. this.node.setStyles(this.css.viewSearchFilterNode_over);
  1233. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode_over);
  1234. }.bind(this),
  1235. "mouseout": function(){
  1236. this.node.setStyles(this.css.viewSearchFilterNode);
  1237. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode);
  1238. }.bind(this)
  1239. });
  1240. this.deleteNode.addEvent("click", function(){
  1241. this.viewer.searchViewRemoveFilter(this);
  1242. }.bind(this));
  1243. },
  1244. destroy: function(){
  1245. this.node.destroy();
  1246. MWF.release(this);
  1247. }
  1248. });