Viewer.js 58 KB

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