Viewer.js 52 KB

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