Property.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. MWF.require("MWF.widget.Common", null, false);
  2. MWF.require("MWF.widget.JsonTemplate", null, false);
  3. MWF.xApplication.process.ViewDesigner.Property = MWF.FVProperty = new Class({
  4. Extends: MWF.widget.Common,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "path": "/x_component_process_FormDesigner/property/property.html"
  9. },
  10. initialize: function(module, propertyNode, designer, options){
  11. this.setOptions(options);
  12. this.module = module;
  13. this.view = module.view;
  14. this.data = module.json;
  15. this.data.pid = this.view.json.id+this.data.id;
  16. this.htmlPath = this.options.path;
  17. this.designer = designer;
  18. this.propertyNode = propertyNode;
  19. },
  20. load: function(){
  21. if (this.fireEvent("queryLoad")){
  22. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  23. this.htmlString = responseText;
  24. this.fireEvent("postLoad");
  25. }.bind(this));
  26. }
  27. this.propertyNode.addEvent("keydown", function(e){e.stopPropagation();});
  28. },
  29. editProperty: function(td){
  30. },
  31. getHtmlString: function(callback){
  32. if (!this.htmlString){
  33. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  34. this.htmlString = responseText;
  35. if (callback) callback();
  36. }.bind(this));
  37. }else{
  38. if (callback) callback();
  39. }
  40. },
  41. show: function(){
  42. if (!this.propertyContent){
  43. this.getHtmlString(function(){
  44. if (this.htmlString){
  45. this.JsonTemplate = new MWF.widget.JsonTemplate(this.data, this.htmlString);
  46. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyNode);
  47. this.propertyContent.set("html", this.JsonTemplate.load());
  48. this.setEditNodeEvent();
  49. this.setEditNodeStyles(this.propertyContent);
  50. this.loadPropertyTab();
  51. this.loadPersonInput();
  52. this.loadPersonSelectInput();
  53. this.loadViewFilter();
  54. this.loadScriptArea();
  55. this.loadColumnExportEditor();
  56. this.loadJSONArea();
  57. }
  58. }.bind(this));
  59. }else{
  60. this.propertyContent.setStyle("display", "block");
  61. }
  62. },
  63. hide: function(){
  64. //this.JsonTemplate = null;
  65. //this.propertyNode.set("html", "");
  66. if (this.propertyContent) this.propertyContent.setStyle("display", "none");
  67. },
  68. loadJSONArea: function(){
  69. var jsonNode = this.propertyContent.getElement(".MWFJSONArea");
  70. if (jsonNode){
  71. this.propertyTab.pages.each(function(page){
  72. if (page.contentNode == jsonNode.parentElement){
  73. page.setOptions({
  74. "onShow": function(){
  75. jsonNode.empty();
  76. MWF.require("MWF.widget.JsonParse", function(){
  77. this.json = new MWF.widget.JsonParse(this.module.json, jsonNode, null);
  78. this.json.load();
  79. }.bind(this));
  80. }.bind(this)
  81. });
  82. }
  83. }.bind(this));
  84. }
  85. },
  86. loadPropertyTab: function(){
  87. var tabNodes = this.propertyContent.getElements(".MWFTab");
  88. if (tabNodes.length){
  89. var tmpNode = this.propertyContent.getFirst();
  90. var tabAreaNode = new Element("div", {
  91. "styles": this.view.css.propertyTabNode
  92. }).inject(tmpNode, "before");
  93. MWF.require("MWF.widget.Tab", function(){
  94. var tab = new MWF.widget.Tab(tabAreaNode, {"style": "formPropertyList"});
  95. tab.load();
  96. var tabPages = [];
  97. tabNodes.each(function(node){
  98. var page = tab.addTab(node, node.get("title"), false);
  99. tabPages.push(page);
  100. this.setScrollBar(page.contentNodeArea, "small", null, null);
  101. }.bind(this));
  102. tabPages[0].showTab();
  103. this.propertyTab = tab;
  104. this.designer.resizeNode();
  105. }.bind(this), false);
  106. }
  107. },
  108. setEditNodeEvent: function(){
  109. var property = this;
  110. // var inputs = this.process.propertyListNode.getElements(".editTableInput");
  111. var inputs = this.propertyContent.getElements("input");
  112. inputs.each(function(input){
  113. var jsondata = input.get("name");
  114. if (jsondata && jsondata.substr(0,1)!="_"){
  115. if (this.module){
  116. var id = this.module.json.id;
  117. input.set("name", id+jsondata);
  118. }
  119. if (jsondata){
  120. var inputType = input.get("type").toLowerCase();
  121. switch (inputType){
  122. case "radio":
  123. input.addEvent("change", function(e){
  124. property.setRadioValue(jsondata, this);
  125. });
  126. input.addEvent("blur", function(e){
  127. property.setRadioValue(jsondata, this);
  128. });
  129. input.addEvent("keydown", function(e){
  130. e.stopPropagation();
  131. });
  132. property.setRadioValue(jsondata, input);
  133. break;
  134. case "checkbox":
  135. input.addEvent("change", function(e){
  136. property.setCheckboxValue(jsondata, this);
  137. });
  138. input.addEvent("click", function(e){
  139. property.setCheckboxValue(jsondata, this);
  140. });
  141. input.addEvent("keydown", function(e){
  142. e.stopPropagation();
  143. });
  144. break;
  145. default:
  146. input.addEvent("change", function(e){
  147. property.setValue(jsondata, this.value, this);
  148. });
  149. input.addEvent("blur", function(e){
  150. property.setValue(jsondata, this.value, this);
  151. });
  152. input.addEvent("keydown", function(e){
  153. if (e.code==13){
  154. property.setValue(jsondata, this.value, this);
  155. }
  156. e.stopPropagation();
  157. });
  158. if (input.hasClass("editTableInputDate")){
  159. this.loadCalendar(input);
  160. }
  161. }
  162. }
  163. }
  164. }.bind(this));
  165. var selects = this.propertyContent.getElements("select");
  166. selects.each(function(select){
  167. var jsondata = select.get("name");
  168. if (jsondata){
  169. select.addEvent("change", function(e){
  170. property.setSelectValue(jsondata, this);
  171. });
  172. //property.setSelectValue(jsondata, select);
  173. }
  174. });
  175. var textareas = this.propertyContent.getElements("textarea");
  176. textareas.each(function(input){
  177. var jsondata = input.get("name");
  178. if (jsondata){
  179. input.addEvent("change", function(e){
  180. property.setValue(jsondata, this.value);
  181. });
  182. input.addEvent("blur", function(e){
  183. property.setValue(jsondata, this.value);
  184. });
  185. input.addEvent("keydown", function(e){
  186. e.stopPropagation();
  187. });
  188. }
  189. }.bind(this));
  190. },
  191. loadCalendar: function(node){
  192. MWF.require("MWF.widget.Calendar", function(){
  193. this.calendar = new MWF.widget.Calendar(node, {
  194. "style": "xform",
  195. "isTime": false,
  196. "target": this.module.designer.content,
  197. "format": "%Y-%m-%d",
  198. "onComplate": function(){
  199. //this.validationMode();
  200. //this.validation();
  201. //this.fireEvent("complete");
  202. }.bind(this)
  203. });
  204. //this.calendar.show();
  205. }.bind(this));
  206. },
  207. changeStyle: function(name){
  208. this.module.setPropertiesOrStyles(name);
  209. },
  210. changeData: function(name, input, oldValue){
  211. this.module._setEditStyle(name, input, oldValue);
  212. },
  213. changeJsonDate: function(key, value){
  214. if (typeOf(key)!="array") key = [key];
  215. var o = this.data;
  216. var len = key.length-1;
  217. key.each(function(n, i){
  218. if (!o[n]) o[n] = {};
  219. if (i<len) o = o[n];
  220. }.bind(this));
  221. o[key[len]] = value;
  222. },
  223. setRadioValue: function(name, input){
  224. if (input.checked){
  225. var i = name.indexOf("*");
  226. var names = (i==-1) ? name.split(".") : name.substr(i+1, name.length).split(".");
  227. var value = input.value;
  228. if (value=="false") value = false;
  229. if (value=="true") value = true;
  230. var oldValue = this.data;
  231. for (var idx = 0; idx<names.length; idx++){
  232. if (!oldValue[names[idx]]){
  233. oldValue = null;
  234. break;
  235. }else{
  236. oldValue = oldValue[names[idx]];
  237. }
  238. }
  239. //var oldValue = this.data[name];
  240. this.changeJsonDate(names, value);
  241. this.changeData(name, input, oldValue);
  242. }
  243. },
  244. setCheckboxValue: function(name, input){
  245. var id = this.module.json.id;
  246. var checkboxList = $$("input[name='"+id+name+"']");
  247. var values = [];
  248. checkboxList.each(function(checkbox){
  249. if (checkbox.get("checked")){
  250. values.push(checkbox.value);
  251. }
  252. });
  253. var oldValue = this.data[name];
  254. //this.data[name] = values;
  255. this.changeJsonDate(name, values);
  256. this.changeData(name, input, oldValue);
  257. },
  258. setSelectValue: function(name, select){
  259. var idx = select.selectedIndex;
  260. var options = select.getElements("option");
  261. var value = "";
  262. if (options[idx]){
  263. value = options[idx].get("value");
  264. }
  265. var oldValue = this.data[name];
  266. //this.data[name] = value;
  267. this.changeJsonDate(name, value);
  268. this.changeData(name, select, oldValue);
  269. },
  270. setValue: function(name, value, obj){
  271. var names = name.split(".");
  272. var oldValue = this.data;
  273. for (var idx = 0; idx<names.length; idx++){
  274. if (!oldValue[names[idx]]){
  275. oldValue = null;
  276. break;
  277. }else{
  278. oldValue = oldValue[names[idx]];
  279. }
  280. }
  281. //var oldValue = this.data[name];
  282. //this.data[name] = value;
  283. this.changeJsonDate(names, value);
  284. this.changeData(name, obj, oldValue);
  285. },
  286. setEditNodeStyles: function(node){
  287. var nodes = node.getChildren();
  288. if (nodes.length){
  289. nodes.each(function(el){
  290. var cName = el.get("class");
  291. if (cName){
  292. if (this.view.css[cName]) el.setStyles(this.view.css[cName]);
  293. }
  294. this.setEditNodeStyles(el);
  295. }.bind(this));
  296. }
  297. },
  298. loadScriptArea: function(){
  299. var scriptAreas = this.propertyContent.getElements(".MWFScriptArea");
  300. var formulaAreas = this.propertyContent.getElements(".MWFFormulaArea");
  301. this.loadScriptEditor(scriptAreas);
  302. this.loadScriptEditor(formulaAreas, "formula");
  303. },
  304. loadScriptEditor: function(scriptAreas, style){
  305. scriptAreas.each(function(node){
  306. var title = node.get("title");
  307. var name = node.get("name");
  308. var scriptContent = this.data[name];
  309. MWF.require("MWF.widget.ScriptArea", function(){
  310. var scriptArea = new MWF.widget.ScriptArea(node, {
  311. "title": title,
  312. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  313. "maxObj": this.designer.editContentNode,
  314. "onChange": function(){
  315. this.data[name] = scriptArea.toJson().code;
  316. }.bind(this),
  317. "onSave": function(){
  318. this.designer.saveView();
  319. }.bind(this),
  320. "style": style || "default"
  321. });
  322. scriptArea.load({"code": scriptContent});
  323. }.bind(this));
  324. }.bind(this));
  325. },
  326. loadPersonInput: function(){
  327. var identityNodes = this.propertyContent.getElements(".MWFPersonIdentity");
  328. var personUnitNodes = this.propertyContent.getElements(".MWFPersonUnit");
  329. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  330. identityNodes.each(function(node){
  331. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  332. "type": "identity",
  333. "names": this.data[node.get("name")],
  334. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  335. });
  336. }.bind(this));
  337. personUnitNodes.each(function(node){
  338. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  339. "type": "unit",
  340. "names": this.data[node.get("name")],
  341. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  342. });
  343. }.bind(this));
  344. }.bind(this));
  345. },
  346. savePersonItem: function(node, ids){
  347. var values = [];
  348. ids.each(function(id){
  349. //values.push({"name": (id.data.distinguishedName || id.data.name), "id": id.data.id});
  350. values.push((id.data.distinguishedName || id.data.id || id.data.name));
  351. }.bind(this));
  352. var name = node.get("name");
  353. key = name.split(".");
  354. var o = this.data;
  355. var len = key.length-1;
  356. key.each(function(n, i){
  357. if (!o[n]) o[n] = {};
  358. if (i<len) o = o[n];
  359. }.bind(this));
  360. o[key[len]] = values;
  361. //this.data.data.restrictWhereEntry[node.get("name")] = values;
  362. },
  363. loadPersonSelectInput: function(){
  364. var applicationNodes = this.propertyContent.getElements(".MWFSelectApplication");
  365. var processNodes = this.propertyContent.getElements(".MWFSelectProcess");
  366. // var companyNodes = this.propertyContent.getElements(".MWFSelectCompany");
  367. // var departmentNodes = this.propertyContent.getElements(".MWFSelectDepartment");
  368. var personNodes = this.propertyContent.getElements(".MWFSelectPerson");
  369. var identityNodes = this.propertyContent.getElements(".MWFSelectIdentity");
  370. var personUnitNodes = this.propertyContent.getElements(".MWFSelectUnit");
  371. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  372. applicationNodes.each(function(node){
  373. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  374. "type": "application",
  375. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.applicationList : [],
  376. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  377. });
  378. }.bind(this));
  379. processNodes.each(function(node){
  380. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  381. "type": "process",
  382. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.processList : [],
  383. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  384. });
  385. }.bind(this));
  386. personUnitNodes.each(function(node){
  387. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  388. "type": "unit",
  389. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.unitList : [],
  390. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  391. });
  392. }.bind(this));
  393. personNodes.each(function(node){
  394. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  395. "type": "person",
  396. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.personList : [],
  397. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  398. });
  399. }.bind(this));
  400. identityNodes.each(function(node){
  401. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  402. "type": "identity",
  403. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.identityList : [],
  404. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  405. });
  406. }.bind(this));
  407. }.bind(this));
  408. },
  409. savePersonSelectItem: function(node, ids){
  410. //this.initWhereEntryData();
  411. var values = [];
  412. ids.each(function(id){
  413. values.push({"name": (id.data.distinguishedName || id.data.name), "id": id.data.id});
  414. //values.push((id.data.distinguishedName || id.data.id || id.data.name));
  415. }.bind(this));
  416. var name = node.get("name");
  417. key = name.split(".");
  418. var o = this.data;
  419. var len = key.length-1;
  420. key.each(function(n, i){
  421. if (!o[n]) o[n] = {};
  422. if (i<len) o = o[n];
  423. }.bind(this));
  424. o[key[len]] = values;
  425. //this.data.data.restrictWhereEntry[node.get("name")] = values;
  426. },
  427. //loadWorkDataEditor: function(){
  428. // var workDataNodes = this.propertyContent.getElements(".MWFWorkData");
  429. // workDataNodes.each(function(node){
  430. // var select = node.getElement("select");
  431. // for (var i=0; i<select.options.length; i++){
  432. // if (select.options[i].value==this.data.name){
  433. // select.options[i].set("selected", true);
  434. // break;
  435. // }
  436. // }
  437. // if (!this.data.type) this.data.type = "text";
  438. // select.addEvent("change", function(e){
  439. // delete this.data.path;
  440. // this.data.name = select.options[select.selectedIndex].value;
  441. // this.module.listNode.getLast().set("text", this.data.text+"("+this.data.name+")");
  442. // this.setDataType();
  443. // }.bind(this));
  444. //
  445. // this.setDataType();
  446. // }.bind(this));
  447. // var nodes = this.propertyContent.getElements(".MWFWorkDataCheck");
  448. // nodes.each(function(node){
  449. // if (this.data.name) node.set("checked", true);
  450. // }.bind(this));
  451. //},
  452. //setDataType: function(){
  453. // switch (this.data.name){
  454. // case "startTime":case "completedTime":
  455. // this.data.type ="date";
  456. // break;
  457. // case "completed":
  458. // this.data.type ="boolean";
  459. // break;
  460. // default:
  461. // this.data.type ="text";
  462. // }
  463. //},
  464. //loadDataDataEditor: function(){
  465. // var nodes = this.propertyContent.getElements(".MWFDataData");
  466. // nodes.each(function(node){
  467. // var input = node.getElement("input");
  468. // input.set("value", this.data.path);
  469. // input.addEvent("change", function(e){
  470. // delete this.data.name;
  471. // this.data.path = input.get("value");
  472. // this.module.listNode.getLast().set("text", this.data.text+"("+this.data.path+")");
  473. // }.bind(this));
  474. // input.addEvent("blur", function(e){
  475. // delete this.data.name;
  476. // this.data.path = input.get("value");
  477. // this.module.listNode.getLast().set("text", this.data.text+"("+this.data.path+")");
  478. // }.bind(this));
  479. // input.addEvent("keydown", function(e){
  480. // if (e.code==13){
  481. // delete this.data.name;
  482. // this.data.path = input.get("value");
  483. // this.module.listNode.getLast().set("text", this.data.text+"("+this.data.path+")");
  484. // }
  485. // e.stopPropagation();
  486. // }.bind(this));
  487. //
  488. // var select = node.getElement("select");
  489. // for (var i=0; i<select.options.length; i++){
  490. // if (select.options[i].value==this.data.type){
  491. // select.options[i].set("selected", true);
  492. // break;
  493. // }
  494. // }
  495. // if (!this.data.type) this.data.type = "text";
  496. // select.addEvent("change", function(e){
  497. // this.data.type = select.options[select.selectedIndex].value;
  498. // }.bind(this));
  499. //
  500. // }.bind(this));
  501. // var nodes = this.propertyContent.getElements(".MWFDataDataCheck");
  502. // nodes.each(function(node){
  503. // if (this.data.path) node.set("checked", true);
  504. // }.bind(this));
  505. //},
  506. loadColumnExportEditor: function(){
  507. var _self = this;
  508. var nodes = this.propertyContent.getElements(".MWFColumnExport");
  509. nodes.each(function(node){
  510. //if (!this.data.export) this.data.export = {};
  511. //var sort = this.data.export.sort || "";
  512. //var sortOrder = this.data.export.sortOrder || "1";
  513. var select = node.getElement("select");
  514. var sortList = this.view.data.data.orderEntryList;
  515. sortList.each(function(order){
  516. if (order.column==this.data.column){
  517. if (order.orderType=="asc") select.options[1].set("selected", true);
  518. if (order.orderType=="desc") select.options[1].set("selected", false);
  519. }
  520. }.bind(this));
  521. select.addEvent("change", function(e){
  522. var v = select.options[select.selectedIndex].value;
  523. if (v!="none"){
  524. var flag = false;
  525. sortList.each(function(order){
  526. if (order.column==this.data.column){
  527. flag = true;
  528. order.orderType=select.options[select.selectedIndex].value;
  529. }
  530. }.bind(this));
  531. if (!flag) sortList.push({"column": this.data.column, "orderType": select.options[select.selectedIndex].value});
  532. }else{
  533. var deleteItem = null;
  534. sortList.each(function(order){
  535. if (order.column==this.data.column){
  536. deleteItem = order;
  537. }
  538. }.bind(this));
  539. if (deleteItem) sortList.erase(deleteItem);
  540. }
  541. }.bind(this));
  542. var radios = node.getElements("input");
  543. var group = this.view.data.data.group;
  544. if (group.column==this.data.column) radios[0].set("checked", true);
  545. radios.addEvent("click", function(e){
  546. if (this.checked){
  547. if (this.value=="true") {
  548. _self.view.data.data.group.column = _self.data.column;
  549. _self.view.items.each(function(col){
  550. if (col.property){
  551. var groupRadios = col.property.propertyContent.getElement(".MWFColumnExportGroup").getElements("input");
  552. groupRadios.each(function(r){
  553. if (r.value=="true") r.set("checked", false);
  554. if (r.value=="false") r.set("checked", true);
  555. });
  556. }
  557. });
  558. this.set("checked", true);
  559. }else{
  560. if (group.column ==_self.data.column) _self.view.data.data.group = {};
  561. }
  562. }
  563. });
  564. }.bind(this));
  565. },
  566. loadViewFilter: function(){
  567. var nodes = this.propertyContent.getElements(".MWFViewFilter");
  568. var filtrData = this.view.data.data.restrictFilterEntryList;
  569. var customData = this.view.data.data.customFilterEntryList;
  570. nodes.each(function(node){
  571. MWF.xDesktop.requireApp("process.ViewDesigner", "widget.ViewFilter", function(){
  572. var _slef = this;
  573. new MWF.xApplication.process.ViewDesigner.widget.ViewFilter(node, this.view.designer, {"filtrData": filtrData, "customData": customData}, {
  574. "onChange": function(ids){
  575. var data = this.getData();
  576. _slef.changeJsonDate(["data", "restrictFilterEntryList"], data.data);
  577. _slef.changeJsonDate(["data", "customFilterEntryList"], data.customData);
  578. }
  579. });
  580. }.bind(this));
  581. }.bind(this));
  582. },
  583. loadColumnFilter: function(){
  584. var nodes = this.propertyContent.getElements(".MWFColumnFilter");
  585. nodes.each(function(node){
  586. this.module.filterAreaNode = node;
  587. var table = new Element("table", {
  588. "styles": {"width": "100%"},
  589. "border": "0px",
  590. "cellPadding": "0",
  591. "cellSpacing": "0"
  592. }).inject(node);
  593. var tr = new Element("tr", {"styles": this.module.css.filterTableTitle}).inject(table);
  594. var html = "<th style='width:24px;border-right:1px solid #CCC;border-bottom:1px solid #999;'></th>" +
  595. "<th style='border-right:1px solid #CCC;border-left:1px solid #FFF;border-bottom:1px solid #999;'>逻辑</th>" +
  596. "<th style='border-right:1px solid #CCC;border-left:1px solid #FFF;border-bottom:1px solid #999;'>路径</th>" +
  597. "<th style='border-right:1px solid #CCC;border-left:1px solid #FFF;border-bottom:1px solid #999;'>比较</th>" +
  598. "<th style='border-left:1px solid #FFF;border-bottom:1px solid #999;'>值</th>";
  599. tr.set("html", html);
  600. var addActionNode = new Element("div", {"styles": this.module.css.filterAddActionNode}).inject(tr.getFirst("th"));
  601. addActionNode.addEvent("click", function(){
  602. this.addFilter(table);
  603. }.bind(this));
  604. if (this.data.filterList) {
  605. this.data.filterList.each(function (op) {
  606. new MWF.xApplication.process.ViewDesigner.Property.Filter(op, table, this);
  607. }.bind(this));
  608. }
  609. }.bind(this));
  610. },
  611. addFilter: function(table){
  612. op = {
  613. "logic": "and",
  614. "comparison": "",
  615. "value": ""
  616. }
  617. if (!this.data.filterList) this.data.filterList = [];
  618. this.data.filterList.push(op);
  619. var filter = new MWF.xApplication.process.ViewDesigner.Property.Filter(op, table, this);
  620. filter.editMode();
  621. }
  622. //initWhereEntryData: function(){
  623. // if (!this.data.data.restrictWhereEntry) this.data.data.restrictWhereEntry = {
  624. // "applicationList": [],
  625. // "processList": [],
  626. // "companyList": [],
  627. // "departmentList": [],
  628. // "personList": [],
  629. // "identityList": []
  630. // };
  631. //},
  632. //loadApplicationSelector: function(){
  633. // var nodes = this.propertyContent.getElements(".MWFApplicationSelect");
  634. // if (nodes.length){
  635. // MWF.xDesktop.requireApp("Organization", "Selector.package", function(){
  636. // nodes.each(function(node){
  637. // var title = new Element("div", {"styles": this.view.css.applicationSelectTitle, "text": node.get("title")}).inject(node);
  638. // var content = new Element("div", {"styles": this.view.css.applicationSelectContent}).inject(node);
  639. // var action = new Element("div", {"styles": this.view.css.applicationSelectAction, "text": node.get("title")}).inject(node);
  640. // action.addEvent("click", function(e){
  641. // var values = [];
  642. // if (this.data.data.whereEntry){
  643. // if (this.data.data.whereEntry.applicationList.length){
  644. // this.data.data.whereEntry.applicationList.each(function(item){
  645. // values.push(item.id);
  646. // }.bind(this));
  647. // }
  648. // }
  649. // var options = {
  650. // "type": "application",
  651. // "count": 0,
  652. // "values": values,
  653. // //"title": this.app.lp.monthly.selectSortApplication,
  654. // "onComplete": function(items){
  655. // this.initWhereEntryData();
  656. // this.data.data.whereEntry.applicationList = [];
  657. // content.empty();
  658. // items.each(function(item){
  659. // this.data.data.whereEntry.applicationList.push({
  660. // "id": item.data.id,
  661. // "name": item.data.name
  662. // });
  663. // new Element("div", {
  664. // "styles": this.view.css.applicationSelectItem,
  665. // "text": item.data.name
  666. // }).inject(content);
  667. // }.bind(this));
  668. // }.bind(this)
  669. // };
  670. // var selector = new MWF.OrgSelector(this.view.designer.content, options);
  671. // }.bind(this));
  672. //
  673. // this.initWhereEntryData();
  674. // this.data.data.whereEntry.applicationList.each(function(app){
  675. // new Element("div", {
  676. // "styles": this.view.css.applicationSelectItem,
  677. // "text": app.name
  678. // }).inject(content);
  679. // }.bind(this));
  680. // }.bind(this));
  681. // }.bind(this));
  682. // }
  683. //},
  684. //loadApplicationSelector1: function(){
  685. // var nodes = this.propertyContent.getElements(".MWFApplicationSelect");
  686. // if (nodes.length){
  687. // this._getAppSelector(function(){
  688. // nodes.each(function(node){
  689. // var title = new Element("div", {"styles": this.view.css.applicationSelectTitle, "text": node.get("title")}).inject(node);
  690. // var content = new Element("div", {"styles": this.view.css.applicationSelectContent}).inject(node);
  691. // var action = new Element("div", {"styles": this.view.css.applicationSelectAction, "text": node.get("title")}).inject(node);
  692. // action.addEvent("click", function(e){
  693. // this.appSelector.load(function(apps){
  694. // if (!this.data.data.select) this.data.data.select = {"applicationRestrictList": [], "processRestrictList": []};
  695. // this.data.data.select.applicationRestrictList = [];
  696. // content.empty();
  697. // if (apps.length){
  698. // apps.each(function(app){
  699. // var o = {
  700. // "name": app.name,
  701. // "id": app.id,
  702. // "alias": app.alias
  703. // }
  704. // this.data.data.select.applicationRestrictList.push(o);
  705. //
  706. // new Element("div", {
  707. // "styles": this.view.css.applicationSelectItem,
  708. // "text": app.name
  709. // }).inject(content);
  710. //
  711. // }.bind(this));
  712. // }
  713. // }.bind(this));
  714. // }.bind(this));
  715. // if (!this.data.data.select) this.data.data.select = {"applicationRestrictList": [], "processRestrictList": []};
  716. // this.data.data.select.applicationRestrictList.each(function(app){
  717. // new Element("div", {
  718. // "styles": this.view.css.applicationSelectItem,
  719. // "text": app.name
  720. // }).inject(content);
  721. // }.bind(this));
  722. //
  723. // }.bind(this));
  724. // }.bind(this));
  725. // }
  726. //},
  727. //
  728. //_getAppSelector: function(callback){
  729. // if (!this.appSelector){
  730. // MWF.xDesktop.requireApp("process.ProcessManager", "widget.ApplicationSelector", function(){
  731. // this.appSelector = new MWF.xApplication.process.ProcessManager.widget.ApplicationSelector(this.view.designer, {"maskNode": this.view.designer.content});
  732. // if (callback) callback();
  733. // }.bind(this));
  734. // }else{
  735. // if (callback) callback();
  736. // }
  737. //},
  738. //this.initWhereEntryData();
  739. //loadProcessSelector: function(){
  740. // var nodes = this.propertyContent.getElements(".MWFApplicationSelect");
  741. // if (nodes.length){
  742. // MWF.xDesktop.requireApp("Organization", "Selector.package", function(){
  743. // nodes.each(function(node){
  744. // var title = new Element("div", {"styles": this.view.css.applicationSelectTitle, "text": node.get("title")}).inject(node);
  745. // var content = new Element("div", {"styles": this.view.css.applicationSelectContent}).inject(node);
  746. // var action = new Element("div", {"styles": this.view.css.applicationSelectAction, "text": node.get("title")}).inject(node);
  747. // action.addEvent("click", function(e){
  748. // var values = [];
  749. // if (this.data.data.whereEntry){
  750. // if (this.data.data.whereEntry.processList.length){
  751. // this.data.data.whereEntry.processList.each(function(item){
  752. // values.push(item.id);
  753. // }.bind(this));
  754. // }
  755. // }
  756. // var options = {
  757. // "type": "process",
  758. // "count": 0,
  759. // "values": values,
  760. // "onComplete": function(items){
  761. // this.initWhereEntryData();
  762. // this.data.data.whereEntry.processList = [];
  763. // content.empty();
  764. // items.each(function(item){
  765. // this.data.data.whereEntry.processList.push({
  766. // "id": item.data.id,
  767. // "name": item.data.name
  768. // });
  769. // new Element("div", {
  770. // "styles": this.view.css.applicationSelectItem,
  771. // "text": item.data.name
  772. // }).inject(content);
  773. // }.bind(this));
  774. // }.bind(this)
  775. // };
  776. // var selector = new MWF.OrgSelector(this.view.designer.content, options);
  777. // }.bind(this));
  778. //
  779. // this.initWhereEntryData();
  780. // this.data.data.whereEntry.processList.each(function(app){
  781. // new Element("div", {
  782. // "styles": this.view.css.applicationSelectItem,
  783. // "text": app.name
  784. // }).inject(content);
  785. // }.bind(this));
  786. // }.bind(this));
  787. // }.bind(this));
  788. // }
  789. //}
  790. //loadProcessSelector1: function(){
  791. // var nodes = this.propertyContent.getElements(".MWFProcessSelect");
  792. // if (nodes.length){
  793. // this._getProcessSelector(function(){
  794. // nodes.each(function(node){
  795. // var title = new Element("div", {"styles": this.view.css.applicationSelectTitle, "text": node.get("title")}).inject(node);
  796. // var content = new Element("div", {"styles": this.view.css.applicationSelectContent}).inject(node);
  797. // var action = new Element("div", {"styles": this.view.css.applicationSelectAction, "text": node.get("title")}).inject(node);
  798. // action.addEvent("click", function(e){
  799. // var ids=[];
  800. // this.data.data.select.applicationRestrictList.each(function(app){
  801. // ids.push(app.id);
  802. // });
  803. // this.processSelector.load(ids, function(apps){
  804. // if (!this.data.data.select) this.data.data.select = {"applicationRestrictList": [], "processRestrictList": []};
  805. // this.data.data.select.processRestrictList = [];
  806. // content.empty();
  807. // if (apps.length){
  808. // apps.each(function(app){
  809. // var o = {
  810. // "name": app.name,
  811. // "id": app.id,
  812. // "alias": app.alias
  813. // }
  814. // this.data.data.select.processRestrictList.push(o);
  815. //
  816. // new Element("div", {
  817. // "styles": this.view.css.applicationSelectItem,
  818. // "text": app.name
  819. // }).inject(content);
  820. //
  821. // }.bind(this));
  822. // }
  823. // }.bind(this));
  824. // }.bind(this));
  825. // if (!this.data.data.select) this.data.data.select = {"applicationRestrictList": [], "processRestrictList": []};
  826. // this.data.data.select.processRestrictList.each(function(app){
  827. // new Element("div", {
  828. // "styles": this.view.css.applicationSelectItem,
  829. // "text": app.name
  830. // }).inject(content);
  831. // }.bind(this));
  832. //
  833. // }.bind(this));
  834. // }.bind(this));
  835. // }
  836. //},
  837. //_getProcessSelector: function(callback){
  838. // if (!this.processSelector){
  839. // MWF.xDesktop.requireApp("process.ProcessManager", "widget.ProcessSelector", function(){
  840. // this.processSelector = new MWF.xApplication.process.ProcessManager.widget.ProcessSelector(this.view.designer, {"maskNode": this.view.designer.content});
  841. // if (callback) callback();
  842. // }.bind(this));
  843. // }else{
  844. // if (callback) callback();
  845. // }
  846. //}
  847. });
  848. MWF.xApplication.process.ViewDesigner.Property.Filter = new Class({
  849. Implements: [Events],
  850. initialize: function(json, table, property){
  851. this.property = property;
  852. this.module = property.module;
  853. this.table = table;
  854. this.data = json;
  855. this.load();
  856. },
  857. load: function(){
  858. this.node = new Element("tr", {"styles": this.module.css.filterTableTd}).inject(this.table);
  859. var html = "<td style='widtd:24px;border-right:1px solid #CCC;border-bottom:1px solid #999;'></td>" +
  860. "<td style='padding:3px;border-right:1px solid #CCC;border-bottom:1px solid #999; width:60px'>"+this.data.logic+"</td>" +
  861. "<td style='padding:3px;border-right:1px solid #CCC;border-bottom:1px solid #999; width:30px'>列值</td>" +
  862. "<td style='padding:3px;border-right:1px solid #CCC;border-bottom:1px solid #999;'>"+this.data.comparison+"</td>" +
  863. "<td style='padding:3px;border-bottom:1px solid #999;'>"+this.data.value+"</td>";
  864. this.node.set("html", html);
  865. var tds = this.node.getElements("td");
  866. this.delActionNode = new Element("div", {"styles": this.module.css.filterDelActionNode}).inject(tds[0]);
  867. this.delActionNode.addEvent("click", function(e){
  868. this.delFilter(e);
  869. e.stopPropagation();
  870. }.bind(this));
  871. this.logicNode = tds[1];
  872. this.comparisonNode = tds[3];
  873. this.valueNode = tds[4];
  874. this.node.addEvent("click", function(){
  875. if (!this.isEditMode) this.editMode();
  876. }.bind(this));
  877. this.node.addEvent("blur", function(){
  878. if (this.isEditMode) this.readMode();
  879. }.bind(this));
  880. },
  881. delFilter: function(e){
  882. var _self = this;
  883. this.property.designer.confirm("warn", e, MWF.APPVD.LP.notice.deleteFilterTitle, MWF.APPVD.LP.notice.deleteFilter, 300, 120, function(){
  884. _self.node.destroy();
  885. _self.property.data.filterList.erase(_self.data);
  886. MWF.release(_self);
  887. this.close();
  888. }, function(){
  889. this.close();
  890. }, null);
  891. },
  892. editMode: function(){
  893. if (this.property.editModeFilter){
  894. if (this.property.editModeFilter!=this) this.property.editModeFilter.readMode();
  895. }
  896. var width = this.logicNode.getSize().x-9;
  897. this.logicNode.empty();
  898. var logicSelect = new Element("select", {"styles": {"width": "90%"}}).inject(this.logicNode);
  899. var html = "";
  900. if (this.data.logic=="and"){
  901. html = "<option value=\"and\" selected>and</option><option value=\"or\">or</option>";
  902. }else{
  903. html = "<option value=\"and\">and</option><option value=\"or\" selected>or</option>";
  904. }
  905. logicSelect.set("html", html);
  906. logicSelect.addEvent("change", function(){
  907. this.data.logic = logicSelect.options[logicSelect.selectedIndex].value;
  908. }.bind(this));
  909. width = this.comparisonNode.getSize().x-9;
  910. this.comparisonNode.empty();
  911. var comparisonSelect = new Element("select", {"styles": {"width": "90%"}}).inject(this.comparisonNode);
  912. html = "";
  913. switch (this.property.data.type){
  914. case "text":
  915. html += "<option value=''></option><option value='==' "+((this.data.comparison=="==") ? "selected": "")+">等于(==)</option>" +
  916. "<option value='!=' "+((this.data.comparison=="!=") ? "selected": "")+">不等于(!=)</option>" +
  917. "<option value='@' "+((this.data.comparison=="@") ? "selected": "")+">包含(@)</option>";
  918. break;
  919. case "date":
  920. html += "<option value=''></option><option value='&gt;' "+((this.data.comparison==">") ? "selected": "")+">大于(&gt;)</option>" +
  921. "<option value='&lt;' "+((this.data.comparison=="<") ? "selected": "")+">小于(&lt;)</option>" +
  922. "<option value='&gt;=' "+((this.data.comparison==">=") ? "selected": "")+">大于等于(&gt;=)</option>" +
  923. "<option value='&lt;=' "+((this.data.comparison=="<=") ? "selected": "")+">小于等于(&lt;=)</option>";
  924. break;
  925. case "number":
  926. html += "<option value=''></option><option value='==' "+((this.data.comparison=="==") ? "selected": "")+">等于(==)</option>" +
  927. "<option value='!=' "+((this.data.comparison=="!=") ? "selected": "")+">不等于(!=)</option>" +
  928. "<option value='&gt;' "+((this.data.comparison==">") ? "selected": "")+">大于(&gt;)</option>" +
  929. "<option value='&lt;' "+((this.data.comparison=="<") ? "selected": "")+">小于(&lt;)</option>" +
  930. "<option value='&gt;=' "+((this.data.comparison==">=") ? "selected": "")+">大于等于(&gt;=)</option>" +
  931. "<option value='&lt;=' "+((this.data.comparison=="<=") ? "selected": "")+">小于等于(&lt;=)</option>";
  932. break;
  933. case "boolean":
  934. html += "<option value=''></option><option value='==' "+((this.data.comparison=="==") ? "selected": "")+">等于(==)</option>" +
  935. "<option value='!=' "+((this.data.comparison=="!=") ? "selected": "")+">不等于(!=)</option>";
  936. break;
  937. }
  938. comparisonSelect.set("html", html);
  939. comparisonSelect.addEvent("change", function(){
  940. this.data.comparison = comparisonSelect.options[comparisonSelect.selectedIndex].value;
  941. }.bind(this));
  942. width = this.valueNode.getSize().x-9;
  943. this.valueNode.empty();
  944. var type = "text";
  945. switch (this.property.data.type){
  946. case "date":
  947. var valueInput = new Element("input", {"styles": {"width": "90%"},
  948. "type": "text",
  949. "value": this.data.value
  950. }).inject(this.valueNode);
  951. MWF.require("MWF.widget.Calendar", function(){
  952. this.calendar = new MWF.widget.Calendar(valueInput, {
  953. "style": "xform",
  954. "isTime": true,
  955. "target": this.property.designer.content,
  956. "format": "%Y-%m-%d %H:%M:%S"
  957. });
  958. //this.calendar.show();
  959. }.bind(this));
  960. break;
  961. case "number":
  962. var valueInput = new Element("input", {"styles": {"width": "90%"},
  963. "type": "number",
  964. "value": this.data.value
  965. }).inject(this.valueNode);
  966. break;
  967. case "boolean":
  968. var valueInput = new Element("select", {"styles": {"width": ""+width+"px"},
  969. "html": "<option value=\"\"></option><option value=\"true\" "+((this.data.value) ? "selected": "")+">true</option><option value=\"false\" "+((!this.data.value) ? "selected": "")+">false</option>"
  970. }).inject(this.valueNode);
  971. break;
  972. default:
  973. var valueInput = new Element("input", {"styles": {"width": "90%"},
  974. "type": "text",
  975. "value": this.data.value
  976. }).inject(this.valueNode);
  977. }
  978. if (valueInput.tagName.toLowerCase()=="select"){
  979. valueInput.addEvent("change", function(){
  980. var v = valueInput.options[valueInput.selectedIndex].value;
  981. this.data.value = (v="true") ? true : false;
  982. }.bind(this));
  983. }else{
  984. valueInput.addEvent("change", function(e){
  985. this.data.value = valueInput.get("value");
  986. }.bind(this));
  987. valueInput.addEvent("blur", function(e){
  988. this.data.value = valueInput.get("value");
  989. }.bind(this));
  990. valueInput.addEvent("keydown", function(e){
  991. if (e.code==13){
  992. this.data.value = valueInput.get("value");
  993. this.readMode();
  994. }
  995. e.stopPropagation();
  996. }.bind(this));
  997. }
  998. this.isEditMode = true;
  999. this.property.editModeFilter = this;
  1000. },
  1001. readMode: function(){
  1002. if (this.isEditMode){
  1003. var logicSelect = this.logicNode.getElement("select");
  1004. this.data.logic = logicSelect.options[logicSelect.selectedIndex].value;
  1005. var comparisonSelect = this.comparisonNode.getElement("select");
  1006. this.data.comparison = comparisonSelect.options[comparisonSelect.selectedIndex].value;
  1007. var valueInput = this.valueNode.getFirst();
  1008. if (valueInput.tagName.toLowerCase()=="select"){
  1009. var v = valueInput.options[valueInput.selectedIndex].value;
  1010. this.data.value = (v="true") ? true : false;
  1011. }else{
  1012. this.data.value = valueInput.get("value");
  1013. }
  1014. this.logicNode.empty();
  1015. this.comparisonNode.empty();
  1016. this.valueNode.empty();
  1017. this.logicNode.set("text", this.data.logic);
  1018. this.comparisonNode.set("text", this.data.comparison);
  1019. this.valueNode.set("text", this.data.value);
  1020. this.isEditMode = false;
  1021. this.property.editModeFilter = null;
  1022. }
  1023. }
  1024. });