Viewer.js 59 KB

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