Viewer.js 52 KB

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