Viewer.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. MWF.xApplication.process = MWF.xApplication.process || {};
  2. MWF.xApplication.process.Application = MWF.xApplication.process.Application || {};
  3. MWF.require("MWF.widget.Common", null, false);
  4. MWF.require("MWF.xScript.Macro", null, false);
  5. MWF.xDesktop.requireApp("process.Application", "lp."+o2.language, null, false);
  6. MWF.xApplication.process.Application.Viewer = new Class({
  7. Implements: [Options, Events],
  8. Extends: MWF.widget.Common,
  9. options: {
  10. "style": "default",
  11. "resizeNode": true,
  12. "actions": {
  13. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  14. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"},
  15. "listWorkByJob": {"uri": "/jaxrs/job/{job}/find/work/workcompleted"},
  16. "listTaskByWork": {"uri": "/jaxrs/work/{id}/assignment/manage"}
  17. },
  18. "actionRoot": "x_processplatform_assemble_surface"
  19. },
  20. initialize: function(container, json, options){
  21. this.setOptions(options);
  22. this.path = "/x_component_process_Application/$Viewer/";
  23. this.cssPath = "/x_component_process_Application/$Viewer/"+this.options.style+"/css.wcss";
  24. this._loadCss();
  25. this.lp = MWF.xApplication.process.Application.LP;
  26. this.container = $(container);
  27. this.json = json;
  28. this.viewJson = null;
  29. this.filterItems = [];
  30. this.searchStatus = "none"; //none, custom, default
  31. this.items = [];
  32. this.selectedItems = [];
  33. this.hideColumns = [];
  34. this.openColumns = [];
  35. this.gridJson = null;
  36. this.init(function(){
  37. this.load();
  38. }.bind(this));
  39. },
  40. init: function(callback){
  41. if (this.json.data){
  42. this.viewJson = JSON.decode(this.json.data);
  43. if (callback) callback();
  44. }else{
  45. this.getView(callback);
  46. }
  47. },
  48. load: function(){
  49. this.loadLayout();
  50. this.createSearchNode();
  51. this.createViewNode({"filterList": this.json.filter || null});
  52. if (this.options.resizeNode){
  53. this.setContentHeightFun = this.setContentHeight.bind(this);
  54. this.container.addEvent("resize", this.setContentHeightFun);
  55. this.setContentHeightFun();
  56. }
  57. },
  58. loadLayout: function(){
  59. this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  60. this.searchAreaNode = new Element("div", {"styles": this.css.searchAreaNode}).inject(this.node);
  61. this.viewAreaNode = new Element("div", {"styles": this.css.viewAreaNode}).inject(this.node);
  62. },
  63. createSearchNode: function(){
  64. if (this.viewJson.customFilterEntryList && this.viewJson.customFilterEntryList.length){
  65. this.searchStatus = "default";
  66. this.loadFilterSearch();
  67. }else{
  68. this.loadSimpleSearch();
  69. }
  70. },
  71. loadSimpleSearch: function(){
  72. this.searchSimpleNode = new Element("div", {"styles": this.css.searchSimpleNode}).inject(this.searchAreaNode);
  73. this.searchSimpleButtonNode = new Element("div", {"styles": this.css.searchSimpleButtonNode}).inject(this.searchSimpleNode);
  74. this.searchSimpleInputNode = new Element("input", {"type":"text", "styles": this.css.searchSimpleInputNode, "value": this.lp.searchKeywork}).inject(this.searchSimpleNode);
  75. this.searchSimpleButtonNode.addEvent("click", function(){
  76. this.search();
  77. }.bind(this));
  78. this.searchSimpleInputNode.addEvents({
  79. "focus": function(){
  80. if (this.searchSimpleInputNode.get("value")===this.lp.searchKeywork) this.searchSimpleInputNode.set("value", "");
  81. }.bind(this),
  82. "blur": function(){if (!this.searchSimpleInputNode.get("value")) this.searchSimpleInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  83. "keydown": function(e){
  84. if (e.code===13) this.search();
  85. }.bind(this)
  86. });
  87. },
  88. search: function(){
  89. if (this.gridJson){
  90. var key = this.searchSimpleInputNode.get("value");
  91. var rows = this.viewTable.rows;
  92. var first = (this.json.isTitle!=="no") ? 1 : 0;
  93. for (var i = first; i<rows.length; i++){
  94. var tr = rows[i];
  95. if (!key || key==this.lp.searchKeywork){
  96. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  97. }else{
  98. if (tr.get("text").indexOf(key)!==-1){
  99. if (tr.getStyle("display")==="none") tr.setStyle("display", "table-row");
  100. }else{
  101. if (tr.getStyle("display")!=="none") tr.setStyle("display", "none");
  102. }
  103. }
  104. }
  105. }
  106. },
  107. loadFilterSearch: function(){
  108. this.viewSearchCustomActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomActionNode, "text": this.lp.customSearch}).inject(this.searchAreaNode);
  109. this.viewSearchInputAreaNode = new Element("div", {"styles": this.css.viewFilterSearchInputAreaNode}).inject(this.searchAreaNode);
  110. this.viewSearchIconNode = new Element("div", {"styles": this.css.viewFilterSearchIconNode}).inject(this.viewSearchInputAreaNode);
  111. this.viewSearchInputBoxNode = new Element("div", {"styles": this.css.viewFilterSearchInputBoxNode}).inject(this.viewSearchInputAreaNode);
  112. this.viewSearchInputNode = new Element("input", {"styles": this.css.viewFilterSearchInputNode, "value": this.lp.searchKeywork}).inject(this.viewSearchInputBoxNode);
  113. this.viewSearchInputNode.addEvents({
  114. "focus": function(){
  115. if (this.viewSearchInputNode.get("value")===this.lp.searchKeywork) this.viewSearchInputNode.set("value", "");
  116. }.bind(this),
  117. "blur": function(){if (!this.viewSearchInputNode.get("value")) this.viewSearchInputNode.set("value", this.lp.searchKeywork);}.bind(this),
  118. "keydown": function(e){
  119. if (e.code===13) this.searchView();
  120. }.bind(this)
  121. });
  122. this.viewSearchIconNode.addEvents({
  123. "click": function(){this.searchView();}.bind(this)
  124. });
  125. this.viewSearchCustomActionNode.addEvents({
  126. "click": function(){this.loadCustomSearch();}.bind(this)
  127. });
  128. },
  129. searchView: function(){
  130. if (this.viewJson.customFilterEntryList){
  131. var key = this.viewSearchInputNode.get("value");
  132. if (key && key!==this.lp.searchKeywork){
  133. var filterData = this.json.filter || [];
  134. this.viewJson.customFilterEntryList.each(function(entry){
  135. if (entry.formatType==="textValue"){
  136. var d = {
  137. "path": entry.path,
  138. "value": key,
  139. "formatType": entry.formatType,
  140. "logic": "or",
  141. "comparison": "like"
  142. };
  143. filterData.push(d);
  144. }
  145. if (entry.formatType==="numberValue"){
  146. var v = key.toFloat();
  147. if (!isNaN(v)){
  148. var d = {
  149. "path": entry.path,
  150. "value": v,
  151. "formatType": entry.formatType,
  152. "logic": "or",
  153. "comparison": "like"
  154. };
  155. filterData.push(d);
  156. }
  157. }
  158. }.bind(this));
  159. this.createViewNode({"filterList": filterData});
  160. }
  161. }
  162. },
  163. searchCustomView: function(){
  164. if (this.filterItems.length){
  165. var filterData = this.json.filter || [];
  166. this.filterItems.each(function(filter){
  167. filterData.push(filter.data);
  168. }.bind(this));
  169. this.createViewNode({"filterList": filterData});
  170. }else{
  171. this.createViewNode({"filterList": this.json.filter || null});
  172. }
  173. },
  174. loadCustomSearch: function(){
  175. this.viewSearchIconNode.setStyle("display", "none");
  176. this.viewSearchInputBoxNode.setStyle("display", "none");
  177. this.viewSearchCustomActionNode.setStyle("display", "none");
  178. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  179. var x = this.viewSearchInputAreaNode.getParent().getSize().x-2-20;
  180. this.css.viewFilterSearchInputAreaNode_custom.width = ""+x+"px";
  181. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  182. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  183. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode_custom).chain(function(){
  184. this.searchStatus = "custom";
  185. this.css.viewFilterSearchInputAreaNode_custom.width = "auto";
  186. this.viewSearchInputAreaNode.setStyle("width", "auto");
  187. if (this.viewSearchCustomContentNode){
  188. this.viewSearchCustomCloseActionNode.setStyle("display", "block");
  189. this.viewSearchCustomContentNode.setStyle("display", "block");
  190. }else{
  191. this.loadCustomSearchContent();
  192. }
  193. this.setContentHeightFun();
  194. }.bind(this));
  195. this.searchCustomView();
  196. },
  197. loadCustomSearchContent: function(){
  198. this.viewSearchCustomCloseActionNode = new Element("div", {"styles": this.css.viewFilterSearchCustomCloseActionNode}).inject(this.viewSearchInputAreaNode);
  199. this.viewSearchCustomContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomContentNode}).inject(this.viewSearchInputAreaNode);
  200. this.viewSearchCustomPathContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomPathContentNode}).inject(this.viewSearchCustomContentNode);
  201. this.viewSearchCustomComparisonContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomComparisonContentNode}).inject(this.viewSearchCustomContentNode);
  202. this.viewSearchCustomValueContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomValueContentNode}).inject(this.viewSearchCustomContentNode);
  203. this.viewSearchCustomAddContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddContentNode}).inject(this.viewSearchCustomContentNode);
  204. this.viewSearchCustomAddIconNode = new Element("div", {"styles": this.css.viewFilterSearchCustomAddIconNode}).inject(this.viewSearchCustomAddContentNode);
  205. this.viewSearchCustomFilterContentNode = new Element("div", {"styles": this.css.viewFilterSearchCustomFilterContentNode}).inject(this.viewSearchCustomContentNode);
  206. this.loadViewSearchCustomList();
  207. this.viewSearchCustomCloseActionNode.addEvents({
  208. "click": function(){this.closeCustomSearch();}.bind(this)
  209. });
  210. this.viewSearchCustomAddIconNode.addEvents({
  211. "click": function(){this.viewSearchCustomAddToFilter();}.bind(this)
  212. });
  213. },
  214. loadViewSearchCustomList: function(){
  215. this.viewSearchCustomPathListNode = new Element("select", {
  216. "styles": this.css.viewFilterSearchCustomPathListNode,
  217. "multiple": true
  218. }).inject(this.viewSearchCustomPathContentNode);
  219. this.viewSearchCustomComparisonListNode = new Element("select", {
  220. "styles": this.css.viewFilterSearchCustomComparisonListNode,
  221. "multiple": true
  222. }).inject(this.viewSearchCustomComparisonContentNode);
  223. this.viewJson.customFilterEntryList.each(function(entry){
  224. var option = new Element("option", {
  225. "style": this.css.viewFilterSearchOptionNode,
  226. "value": entry.path,
  227. "text": entry.title
  228. }).inject(this.viewSearchCustomPathListNode);
  229. option.store("entry", entry);
  230. }.bind(this));
  231. this.viewSearchCustomPathListNode.addEvent("change", function(){
  232. this.loadViewSearchCustomComparisonList();
  233. }.bind(this));
  234. },
  235. loadViewSearchCustomComparisonList: function(){
  236. var idx = this.viewSearchCustomPathListNode.selectedIndex;
  237. var option = this.viewSearchCustomPathListNode.options[idx];
  238. var entry = option.retrieve("entry");
  239. if (entry){
  240. switch (entry.formatType){
  241. case "numberValue":
  242. this.loadComparisonSelect(this.lp.numberFilter);
  243. this.loadViewSearchCustomValueNumberInput();
  244. break;
  245. case "dateTimeValue":
  246. this.loadComparisonSelect(this.lp.dateFilter);
  247. this.loadViewSearchCustomValueDateInput();
  248. break;
  249. case "booleanValue":
  250. this.loadComparisonSelect(this.lp.booleanFilter);
  251. this.loadViewSearchCustomValueBooleanInput();
  252. break;
  253. default:
  254. this.loadComparisonSelect(this.lp.textFilter);
  255. this.loadViewSearchCustomValueTextInput();
  256. }
  257. }
  258. },
  259. loadViewSearchCustomValueNumberInput: function(){
  260. this.viewSearchCustomValueContentNode.empty();
  261. this.viewSearchCustomValueNode = new Element("input", {
  262. "styles": this.css.viewFilterSearchCustomValueNode,
  263. "type": "number"
  264. }).inject(this.viewSearchCustomValueContentNode);
  265. },
  266. loadViewSearchCustomValueDateInput: function(){
  267. this.viewSearchCustomValueContentNode.empty();
  268. this.viewSearchCustomValueNode = new Element("input", {
  269. "styles": this.css.viewFilterSearchCustomValueNode,
  270. "type": "text",
  271. "readonly": true
  272. }).inject(this.viewSearchCustomValueContentNode);
  273. MWF.require("MWF.widget.Calendar", function(){
  274. this.calendar = new MWF.widget.Calendar(this.viewSearchCustomValueNode, {
  275. "style": "xform",
  276. "isTime": true,
  277. "target": this.container,
  278. "format": "db"
  279. });
  280. }.bind(this));
  281. },
  282. loadViewSearchCustomValueBooleanInput: function(){
  283. this.viewSearchCustomValueContentNode.empty();
  284. this.viewSearchCustomValueNode = new Element("select", {
  285. "styles": this.css.viewFilterSearchCustomValueSelectNode,
  286. "multiple": true
  287. }).inject(this.viewSearchCustomValueContentNode);
  288. new Element("option", {"value": "true","text": this.lp.yes}).inject(this.viewSearchCustomValueNode);
  289. new Element("option", {"value": "false","text": this.lp.no}).inject(this.viewSearchCustomValueNode);
  290. },
  291. loadViewSearchCustomValueTextInput: function(){
  292. this.viewSearchCustomValueContentNode.empty();
  293. this.viewSearchCustomValueNode = new Element("textarea", {
  294. "styles": this.css.viewFilterSearchCustomValueNode
  295. }).inject(this.viewSearchCustomValueContentNode);
  296. },
  297. loadComparisonSelect:function(obj){
  298. this.viewSearchCustomComparisonListNode.empty();
  299. Object.each(obj, function(v, k){
  300. var option = new Element("option", {"value": k,"text": v}).inject(this.viewSearchCustomComparisonListNode);
  301. }.bind(this));
  302. },
  303. closeCustomSearch: function(){
  304. if (this.viewSearchCustomContentNode && this.viewSearchCustomContentNode.getStyle("display")==="block"){
  305. this.viewSearchCustomCloseActionNode.setStyle("display", "none");
  306. this.viewSearchCustomContentNode.setStyle("display", "none");
  307. var x = this.viewSearchInputAreaNode.getParent().getSize().x;
  308. x1 = x-2-10-90;
  309. this.css.viewFilterSearchInputAreaNode.width = ""+x1+"px";
  310. var x1 = this.viewSearchInputAreaNode.getSize().x-2;
  311. this.viewSearchInputAreaNode.setStyle("width", ""+x1+"px");
  312. if (!this.searchMorph) this.searchMorph = new Fx.Morph(this.viewSearchInputAreaNode);
  313. this.searchMorph.start(this.css.viewFilterSearchInputAreaNode).chain(function(){
  314. this.searchStatus = "default";
  315. this.css.viewFilterSearchInputAreaNode.width = "auto";
  316. this.viewSearchInputAreaNode.setStyle("margin-right", "90px");
  317. this.viewSearchIconNode.setStyle("display", "block");
  318. this.viewSearchInputBoxNode.setStyle("display", "block");
  319. this.viewSearchCustomActionNode.setStyle("display", "block");
  320. this.setContentHeightFun();
  321. }.bind(this));
  322. this.createViewNode({"filterList": this.json.filter || null});
  323. }
  324. },
  325. viewSearchCustomAddToFilter: function(){
  326. var pathIdx = this.viewSearchCustomPathListNode.selectedIndex;
  327. var comparisonIdx = this.viewSearchCustomComparisonListNode.selectedIndex;
  328. if (pathIdx===-1){
  329. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorTitle, this.viewSearchCustomPathListNode, {"x": 0, "y": 85});
  330. return false;
  331. }
  332. if (comparisonIdx===-1){
  333. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorComparison, this.viewSearchCustomComparisonListNode, {"x": 0, "y": 85});
  334. return false;
  335. }
  336. var pathOption = this.viewSearchCustomPathListNode.options[pathIdx];
  337. var entry = pathOption.retrieve("entry");
  338. if (entry){
  339. var pathTitle = entry.title;
  340. var path = entry.path;
  341. var comparison = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("value");
  342. var comparisonTitle = this.viewSearchCustomComparisonListNode.options[comparisonIdx].get("text");
  343. var value = "";
  344. switch (entry.formatType){
  345. case "numberValue":
  346. value = this.viewSearchCustomValueNode.get("value");
  347. break;
  348. case "dateTimeValue":
  349. value = this.viewSearchCustomValueNode.get("value");
  350. break;
  351. case "booleanValue":
  352. var idx = this.viewSearchCustomValueNode.selectedIndex;
  353. if (idx!==-1){
  354. var v = this.viewSearchCustomValueNode.options[idx].get("value");
  355. value = (v==="true");
  356. }
  357. break;
  358. default:
  359. value = this.viewSearchCustomValueNode.get("value");
  360. }
  361. if (value===""){
  362. MWF.xDesktop.notice("error", {"x": "left", "y": "top"}, this.lp.filterErrorValue, this.viewSearchCustomValueContentNode, {"x": 0, "y": 85});
  363. return false;
  364. }
  365. this.filterItems.push(new MWF.xApplication.process.Application.Viewer.Filter(this, {
  366. "logic": "and",
  367. "path": path,
  368. "title": pathTitle,
  369. "comparison": comparison,
  370. "comparisonTitle": comparisonTitle,
  371. "value": value,
  372. "formatType": entry.formatType
  373. }, this.viewSearchCustomFilterContentNode));
  374. this.searchCustomView();
  375. }
  376. },
  377. searchViewRemoveFilter: function(filter){
  378. this.filterItems.erase(filter);
  379. filter.destroy();
  380. this.searchCustomView()
  381. },
  382. setContentHeight: function(){
  383. var size = this.node.getSize();
  384. var searchSize = this.searchAreaNode.getSize();
  385. var h = size.y-searchSize.y;
  386. this.viewAreaNode.setStyle("height", ""+h+"px");
  387. },
  388. createLoadding: function(){
  389. this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.contentAreaNode);
  390. new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
  391. var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
  392. new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
  393. var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
  394. loadingTextNode.set("text", "loading...");
  395. },
  396. createViewNode: function(data){
  397. this.viewAreaNode.empty();
  398. this.contentAreaNode = new Element("div", {"styles": this.css.contentAreaNode}).inject(this.viewAreaNode);
  399. this.viewTable = new Element("table", {
  400. "styles": this.css.viewTitleTableNode,
  401. "border": "0px",
  402. "cellPadding": "0",
  403. "cellSpacing": "0"
  404. }).inject(this.contentAreaNode);
  405. this.createLoadding();
  406. if (this.json.isTitle!=="no"){
  407. this.viewTitleLine = new Element("tr", {"styles": this.css.viewTitleLineNode}).inject(this.viewTable);
  408. //if (this.json.select==="single" || this.json.select==="multi") {
  409. this.selectTitleCell = new Element("td", {
  410. "styles": this.css.viewTitleCellNode
  411. }).inject(this.viewTitleLine);
  412. this.selectTitleCell.setStyle("width", "10px");
  413. if (this.json.titleStyles) this.selectTitleCell.setStyles(this.json.titleStyles);
  414. //}
  415. this.entries = {};
  416. this.viewJson.selectEntryList.each(function(column){
  417. this.entries[column.column] = column;
  418. if (!column.hideColumn){
  419. var viewCell = new Element("td", {
  420. "styles": this.css.viewTitleCellNode,
  421. "text": column.displayName
  422. }).inject(this.viewTitleLine);
  423. var size = MWF.getTextSize(column.displayName, this.css.viewTitleCellNode);
  424. viewCell.setStyle("min-width", ""+size.x+"px");
  425. if (this.json.titleStyles) viewCell.setStyles(this.json.titleStyles);
  426. }else{
  427. this.hideColumns.push(column.column);
  428. }
  429. if (column.allowOpen) this.openColumns.push(column.column);
  430. }.bind(this));
  431. this.lookup(data);
  432. }else{
  433. this.viewJson.selectEntryList.each(function(column){
  434. if (column.hideColumn) this.hideColumns.push(column.column);
  435. if (!column.allowOpen) this.openColumns.push(column.column);
  436. }.bind(this));
  437. this.lookup(data);
  438. }
  439. },
  440. lookup: function(data){
  441. this.getLookupAction(function(){
  442. if (this.json.application){
  443. this.lookupAction.invoke({"name": "lookup","async": true, "data": (data || null), "parameter": {"view": this.json.name, "application": this.json.application},"success": function(json){
  444. this.viewData = json.data;
  445. if (this.viewJson.groupEntry.column){
  446. this.gridJson = json.data.groupGrid;
  447. this.loadGroupData();
  448. }else{
  449. this.gridJson = json.data.grid;
  450. this.loadData();
  451. }
  452. if (this.loadingAreaNode){
  453. this.loadingAreaNode.destroy();
  454. this.loadingAreaNode = null;
  455. }
  456. }.bind(this)});
  457. }
  458. }.bind(this));
  459. },
  460. loadData: function(){
  461. if (this.gridJson.length){
  462. this.gridJson.each(function(line, i){
  463. this.items.push(new MWF.xApplication.process.Application.Viewer.Item(this, line, null, i));
  464. }.bind(this));
  465. }
  466. },
  467. loadGroupData: function(){
  468. if (this.selectTitleCell){
  469. this.selectTitleCell.set("html", "<span style='font-family: Webdings'>"+"<img src='/x_component_process_Application/$Viewer/"+this.options.style+"/icon/expand.png'/>"+"</span>");
  470. this.selectTitleCell.setStyle("cursor", "pointer");
  471. this.selectTitleCell.addEvent("click", this.expandOrCollapseAll.bind(this));
  472. }
  473. if (this.gridJson.length){
  474. this.gridJson.each(function(data){
  475. this.items.push(new MWF.xApplication.process.Application.Viewer.ItemCategory(this, data));
  476. }.bind(this));
  477. this.expandOrCollapseAll();
  478. }
  479. },
  480. expandOrCollapseAll: function(){
  481. var icon = this.selectTitleCell.getElement("span");
  482. if (icon.get("html").indexOf("expand.png")===-1){
  483. this.items.each(function(item){
  484. item.collapse();
  485. icon.set("html", "<img src='/x_component_process_Application/$Viewer/"+this.options.style+"/icon/expand.png'/>");
  486. }.bind(this));
  487. }else{
  488. this.items.each(function(item, i){
  489. window.setTimeout(function(){
  490. item.expand();
  491. }.bind(this), 10*i+5);
  492. icon.set("html", "<img src='/x_component_process_Application/$Viewer/"+this.options.style+"/icon/down.png'/>");
  493. }.bind(this));
  494. }
  495. },
  496. getView: function(callback){
  497. this.getLookupAction(function(){
  498. if (this.json.application){
  499. this.lookupAction.invoke({"name": "getView","async": true, "parameter": {"view": this.json.viewName, "application": this.json.application},"success": function(json){
  500. this.viewJson = JSON.decode(json.data.data);
  501. this.json = Object.merge(this.json, json.data);
  502. //var viewData = JSON.decode(json.data.data);
  503. if (callback) callback();
  504. }.bind(this)});
  505. }
  506. }.bind(this));
  507. },
  508. getLookupAction: function(callback){
  509. if (!this.lookupAction){
  510. var _self = this;
  511. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  512. this.lookupAction = new MWF.xDesktop.Actions.RestActions("", this.options.actionRoot, "");
  513. this.lookupAction.getActions = function(actionCallback){
  514. this.actions = _self.options.actions;
  515. if (actionCallback) actionCallback();
  516. };
  517. if (callback) callback();
  518. }.bind(this));
  519. }else{
  520. if (callback) callback();
  521. }
  522. },
  523. hide: function(){
  524. this.node.setStyle("display", "none");
  525. },
  526. reload: function(){
  527. this.node.setStyle("display", "block");
  528. if (this.loadingAreaNode) this.loadingAreaNode.setStyle("display", "block");
  529. this.filterItems.each(function(filter){
  530. filter.destroy();
  531. }.bind(this));
  532. this.filterItems = [];
  533. if (this.viewSearchInputNode) this.viewSearchInputNode.set("text", this.lp.searchKeywork);
  534. this.closeCustomSearch();
  535. this.viewAreaNode.empty();
  536. this.createViewNode({"filterList": this.json.filter || null});
  537. },
  538. getFilter: function(){
  539. var filterData = [];
  540. if (this.searchStatus==="custom"){
  541. if (this.filterItems.length){
  542. this.filterItems.each(function(filter){
  543. filterData.push(filter.data);
  544. }.bind(this));
  545. }
  546. }
  547. if (this.searchStatus==="default"){
  548. var key = this.viewSearchInputNode.get("value");
  549. if (key && key!==this.lp.searchKeywork){
  550. this.viewJson.customFilterEntryList.each(function(entry){
  551. if (entry.formatType==="textValue"){
  552. var d = {
  553. "path": entry.path,
  554. "value": key,
  555. "formatType": entry.formatType,
  556. "logic": "or",
  557. "comparison": "like"
  558. };
  559. filterData.push(d);
  560. }
  561. if (entry.formatType==="numberValue"){
  562. var v = key.toFloat();
  563. if (!isNaN(v)){
  564. var d = {
  565. "path": entry.path,
  566. "value": v,
  567. "formatType": entry.formatType,
  568. "logic": "or",
  569. "comparison": "like"
  570. };
  571. filterData.push(d);
  572. }
  573. }
  574. }.bind(this));
  575. }
  576. }
  577. return (filterData.length) ? filterData : null;
  578. },
  579. getData: function(){
  580. if (this.selectedItems.length){
  581. var arr = [];
  582. this.selectedItems.each(function(item){
  583. arr.push(item.data);
  584. });
  585. return arr;
  586. }else{
  587. return [];
  588. }
  589. }
  590. });
  591. MWF.xApplication.process.Application.Viewer.Item = new Class({
  592. initialize: function(view, data, prev, i){
  593. this.view = view;
  594. this.data = data;
  595. this.css = this.view.css;
  596. this.isSelected = false;
  597. this.prev = prev;
  598. this.load();
  599. },
  600. load: function(){
  601. this.node = new Element("tr", {"styles": this.css.viewContentTrNode});
  602. if (this.prev){
  603. this.node.inject(this.prev.node, "after");
  604. }else{
  605. this.node.inject(this.view.viewTable);
  606. }
  607. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  608. this.selectTd = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  609. this.selectTd.setStyles({"cursor": "pointer"});
  610. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  611. //}
  612. Object.each(this.data.data, function(cell, k){
  613. if (this.view.hideColumns.indexOf(k)===-1){
  614. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(this.node);
  615. if (k!== this.view.viewJson.groupEntry.column){
  616. 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
  617. td.set("text", v);
  618. }
  619. if (this.view.openColumns.indexOf(k)!==-1){
  620. this.setOpenWork(td)
  621. }
  622. if (this.view.json.itemStyles) td.setStyles(this.view.json.itemStyles);
  623. }
  624. }.bind(this));
  625. this.setEvent();
  626. },
  627. setOpenWork: function(td){
  628. td.setStyle("cursor", "pointer");
  629. td.addEvent("click", this.openWorkAndCompleted.bind(this));
  630. },
  631. openWorkAndCompleted: function(e){
  632. this.view.lookupAction.invoke({"name": "listWorkByJob","async": true, "parameter": {"job": this.data.job},"success": function(json){
  633. var workCompletedCount = json.data.workCompletedList.length;
  634. var workCount = json.data.workList.length;
  635. var count = workCount+workCompletedCount;
  636. if (count===1){
  637. if (workCompletedCount) {
  638. this.openWorkCompleted(json.data.workCompletedList[0].id, e);
  639. }else{
  640. this.openWork(json.data.workList[0].id, e);
  641. }
  642. }else if (count>1){
  643. var worksAreaNode = this.createWorksArea();
  644. json.data.workCompletedList.each(function(work){
  645. this.createWorkCompletedNode(work, worksAreaNode);
  646. }.bind(this));
  647. json.data.workList.each(function(work){
  648. this.createWorkNode(work, worksAreaNode);
  649. }.bind(this));
  650. this.showWorksArea(worksAreaNode, e);
  651. }else{
  652. }
  653. }.bind(this)});
  654. },
  655. createWorkNode: function(work, worksAreaNode){
  656. var worksAreaContentNode = worksAreaNode.getLast();
  657. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  658. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  659. actionNode.store("workId", work.id);
  660. actionNode.addEvent("click", function(e){
  661. this.openWork(e.target.retrieve("workId"), e);
  662. this.mask.hide();
  663. worksAreaNode.destroy();
  664. }.bind(this));
  665. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  666. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  667. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  668. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  669. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": work.activityName}).inject(contentNode);
  670. var taskUsers = [];
  671. this.view.lookupAction.invoke({"name": "listTaskByWork","async": true, "parameter": {"id": work.id},"success": function(json){
  672. json.data.taskList.each(function(task){
  673. taskUsers.push(MWF.name.cn(task.person));
  674. }.bind(this));
  675. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.taskPeople+": "}).inject(contentNode);
  676. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": taskUsers.join(", ")}).inject(contentNode);
  677. }.bind(this)});
  678. },
  679. createWorkCompletedNode: function(work, worksAreaNode){
  680. var worksAreaContentNode = worksAreaNode.getLast();
  681. var node = new Element("div", {"styles": this.css.workAreaNode}).inject(worksAreaContentNode);
  682. var actionNode = new Element("div", {"styles": this.css.workAreaActionNode, "text": this.view.lp.open}).inject(node);
  683. actionNode.store("workId", work.id);
  684. actionNode.addEvent("click", function(e){
  685. this.mask.hide();
  686. worksAreaNode.destroy();
  687. this.openWorkCompleted(e.target.retrieve("workId"), e)
  688. }.bind(this));
  689. var areaNode = new Element("div", {"styles": this.css.workAreaLeftNode}).inject(node);
  690. var titleNode = new Element("div", {"styles": this.css.workAreaTitleNode, "text": work.title}).inject(areaNode);
  691. var contentNode = new Element("div", {"styles": this.css.workAreaContentNode}).inject(areaNode);
  692. new Element("div", {"styles": this.css.workAreaContentTitleNode, "text": this.view.lp.activity+": "}).inject(contentNode);
  693. new Element("div", {"styles": this.css.workAreaContentTextNode, "text": this.view.lp.processCompleted}).inject(contentNode);
  694. },
  695. createWorksArea: function(){
  696. var worksAreaNode = new Element("div", {"styles": this.css.worksAreaNode});
  697. var worksAreaTitleNode = new Element("div", {"styles": this.css.worksAreaTitleNode}).inject(worksAreaNode);
  698. var worksAreaTitleCloseNode = new Element("div", {"styles": this.css.worksAreaTitleCloseNode}).inject(worksAreaTitleNode);
  699. worksAreaTitleCloseNode.addEvent("click", function(e){
  700. this.mask.hide();
  701. e.target.getParent().getParent().destroy();
  702. }.bind(this));
  703. var worksAreaContentNode = new Element("div", {"styles": this.css.worksAreaContentNode}).inject(worksAreaNode);
  704. return worksAreaNode;
  705. },
  706. showWorksArea: function(node, e){
  707. this.mask = new MWF.widget.Mask({"style": "desktop", "loading": false});
  708. this.mask.loadNode(this.view.container);
  709. node.inject(this.view.node);
  710. this.setWorksAreaPosition(node, e.target);
  711. },
  712. setWorksAreaPosition: function(node, td){
  713. var p = td.getPosition(this.view.container);
  714. var containerS = this.view.container.getSize();
  715. var containerP = this.view.container.getPosition(this.view.container.getOffsetParent());
  716. var s = node.getSize();
  717. var offX = p.x+s.x-containerS.x;
  718. offX = (offX>0) ? offX+20 : 0;
  719. var offY = p.y+s.y-containerS.y;
  720. offY = (offY>0) ? offY+5 : 0;
  721. node.position({
  722. "relativeTo": td,
  723. "position": "lefttop",
  724. "edge": "lefttop",
  725. "offset": {
  726. "x": 0-offX,
  727. "y": 0-offY
  728. }
  729. });
  730. },
  731. openWork: function(id, e){
  732. var options = {"workId": id};
  733. layout.desktop.openApplication(e, "process.Work", options);
  734. },
  735. openWorkCompleted: function(id, e){
  736. var options = {"workCompletedId": id};
  737. layout.desktop.openApplication(e, "process.Work", options);
  738. },
  739. setEvent: function(){
  740. if (this.view.json.select==="single" || this.view.json.select==="multi"){
  741. this.node.addEvents({
  742. "mouseover": function(){
  743. if (!this.isSelected){
  744. var iconName = "checkbox";
  745. if (this.view.json.select==="single") iconName = "radiobox";
  746. this.selectTd.setStyles({"background": "url("+"/x_component_process_Application/$Viewer/default/icon/"+iconName+".png) center center no-repeat"});
  747. }
  748. }.bind(this),
  749. "mouseout": function(){
  750. if (!this.isSelected) this.selectTd.setStyles({"background": "transparent"});
  751. }.bind(this),
  752. "click": function(){this.select();}.bind(this)
  753. });
  754. }
  755. },
  756. select: function(){
  757. if (this.isSelected){
  758. if (this.view.json.select==="single"){
  759. this.unSelectedSingle();
  760. }else{
  761. this.unSelected();
  762. }
  763. }else{
  764. if (this.view.json.select==="single"){
  765. this.selectedSingle();
  766. }else{
  767. this.selected();
  768. }
  769. }
  770. this.view.fireEvent("select");
  771. },
  772. selected: function(){
  773. this.view.selectedItems.push(this);
  774. this.selectTd.setStyles({"background": "url("+"/x_component_process_Application/$Viewer/default/icon/checkbox_checked.png) center center no-repeat"});
  775. this.node.setStyles(this.css.viewContentTrNode_selected);
  776. this.isSelected = true;
  777. },
  778. unSelected: function(){
  779. this.view.selectedItems.erase(this);
  780. this.selectTd.setStyles({"background": "transparent"});
  781. this.node.setStyles(this.css.viewContentTrNode);
  782. this.isSelected = false;
  783. },
  784. selectedSingle: function(){
  785. if (this.view.currentSelectedItem) this.view.currentSelectedItem.unSelectedSingle();
  786. this.view.selectedItems = [this];
  787. this.view.currentSelectedItem = this;
  788. this.selectTd.setStyles({"background": "url("+"/x_component_process_Application/$Viewer/default/icon/radiobox_checked.png) center center no-repeat"});
  789. this.node.setStyles(this.css.viewContentTrNode_selected);
  790. this.isSelected = true;
  791. },
  792. unSelectedSingle: function(){
  793. this.view.selectedItems = [];
  794. this.view.currentSelectedItem = null;
  795. this.selectTd.setStyles({"background": "transparent"});
  796. this.node.setStyles(this.css.viewContentTrNode);
  797. this.isSelected = false;
  798. }
  799. });
  800. MWF.xApplication.process.Application.Viewer.ItemCategory = new Class({
  801. initialize: function(view, data){
  802. this.view = view;
  803. this.data = data;
  804. this.css = this.view.css;
  805. this.items = [];
  806. this.loadChild = false;
  807. this.load();
  808. },
  809. load: function(){
  810. this.node = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.view.viewTable);
  811. //if (this.view.json.select==="single" || this.view.json.select==="multi"){
  812. this.selectTd = new Element("td", {"styles": this.css.viewContentCategoryTdNode}).inject(this.node);
  813. if (this.view.json.itemStyles) this.selectTd.setStyles(this.view.json.itemStyles);
  814. //}
  815. this.categoryTd = new Element("td", {
  816. "styles": this.css.viewContentCategoryTdNode,
  817. "colspan": this.view.viewJson.selectEntryList.length
  818. }).inject(this.node);
  819. this.groupColumn = null;
  820. for (var c = 0; c<this.view.viewJson.selectEntryList.length; c++){
  821. if (this.view.viewJson.selectEntryList[c].column === this.view.viewJson.groupEntry.column){
  822. this.groupColumn = this.view.viewJson.selectEntryList[c];
  823. break;
  824. }
  825. }
  826. if (this.groupColumn){
  827. 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;
  828. }else{
  829. var text = this.data.group;
  830. }
  831. this.categoryTd.set("html", "<span style='font-family: Webdings'><img src='/x_component_process_Application/$Viewer/"+this.view.options.style+"/icon/expand.png'/></span> "+text);
  832. if (this.view.json.itemStyles) this.categoryTd.setStyles(this.view.json.itemStyles);
  833. this.setEvent();
  834. },
  835. setEvent: function(){
  836. //if (this.selectTd){
  837. this.node.addEvents({
  838. "click": function(){this.expandOrCollapse();}.bind(this)
  839. });
  840. //}
  841. },
  842. expandOrCollapse: function(){
  843. var t = this.node.getElement("span").get("html");
  844. if (t.indexOf("expand.png")===-1){
  845. this.collapse();
  846. }else{
  847. this.expand();
  848. }
  849. },
  850. collapse: function(){
  851. this.items.each(function(item){
  852. item.node.setStyle("display", "none");
  853. }.bind(this));
  854. this.node.getElement("span").set("html", "<img src='/x_component_process_Application/$Viewer/"+this.view.options.style+"/icon/expand.png'/>");
  855. },
  856. expand: function(){
  857. this.items.each(function(item){
  858. item.node.setStyle("display", "table-row");
  859. }.bind(this));
  860. this.node.getElement("span").set("html", "<img src='/x_component_process_Application/$Viewer/"+this.view.options.style+"/icon/down.png'/>");
  861. if (!this.loadChild){
  862. //window.setTimeout(function(){
  863. this.data.list.each(function(line){
  864. this.items.push(new MWF.xApplication.process.Application.Viewer.Item(this.view, line, this));
  865. }.bind(this));
  866. this.loadChild = true;
  867. //}.bind(this), 10);
  868. }
  869. }
  870. });
  871. MWF.xApplication.process.Application.Viewer.Filter = new Class({
  872. initialize: function(viewer, data, node){
  873. this.viewer = viewer;
  874. this.data = data;
  875. this.css = this.viewer.css;
  876. this.content = node;
  877. this.load();
  878. },
  879. load: function(){
  880. this.node = new Element("div", {"styles": this.css.viewSearchFilterNode}).inject(this.content);
  881. if (this.viewer.filterItems.length){
  882. this.logicNode = new Element("div", {"styles": this.css.viewSearchFilterSelectAreaNode}).inject(this.node);
  883. this.logicSelectNode = new Element("div", {
  884. "styles": this.css.viewSearchFilterSelectNode,
  885. "text": this.viewer.lp.and,
  886. "value": "and"
  887. }).inject(this.logicNode);
  888. this.logicSelectButtonNode = new Element("div", {"styles": this.css.viewSearchFilterSelectButtonNode}).inject(this.logicNode);
  889. this.logicNode.addEvents({
  890. "click": function(){
  891. var v = this.logicSelectNode.get("value");
  892. if (v==="and"){
  893. this.logicSelectButtonNode.setStyle("float", "left");
  894. this.logicSelectNode.setStyle("float", "right");
  895. this.logicSelectNode.set({
  896. "text": this.viewer.lp.or,
  897. "value": "or"
  898. });
  899. this.data.logic = "or";
  900. }else{
  901. this.logicSelectButtonNode.setStyle("float", "right");
  902. this.logicSelectNode.setStyle("float", "left");
  903. this.logicSelectNode.set({
  904. "text": this.viewer.lp.and,
  905. "value": "and"
  906. });
  907. this.data.logic = "and";
  908. }
  909. this.viewer.searchCustomView();
  910. }.bind(this)
  911. });
  912. }
  913. this.titleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.title}).inject(this.node);
  914. this.comparisonTitleNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": this.data.comparisonTitle}).inject(this.node);
  915. this.valueNode = new Element("div", {"styles": this.css.viewSearchFilterTextNode, "text": "\""+this.data.value+"\""}).inject(this.node);
  916. this.deleteNode = new Element("div", {"styles": this.css.viewSearchFilterDeleteNode}).inject(this.node);
  917. this.node.addEvents({
  918. "mouseover": function(){
  919. this.node.setStyles(this.css.viewSearchFilterNode_over);
  920. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode_over);
  921. }.bind(this),
  922. "mouseout": function(){
  923. this.node.setStyles(this.css.viewSearchFilterNode);
  924. this.deleteNode.setStyles(this.css.viewSearchFilterDeleteNode);
  925. }.bind(this)
  926. });
  927. this.deleteNode.addEvent("click", function(){
  928. this.viewer.searchViewRemoveFilter(this);
  929. }.bind(this));
  930. },
  931. destroy: function(){
  932. this.node.destroy();
  933. MWF.release(this);
  934. }
  935. });