Property.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  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. debugger;
  300. var scriptAreas = this.propertyContent.getElements(".MWFScriptArea");
  301. var formulaAreas = this.propertyContent.getElements(".MWFFormulaArea");
  302. this.loadScriptEditor(scriptAreas);
  303. this.loadScriptEditor(formulaAreas, "formula");
  304. },
  305. loadScriptEditor: function(scriptAreas, style){
  306. scriptAreas.each(function(node){
  307. var title = node.get("title");
  308. var name = node.get("name");
  309. var scriptContent = this.data[name];
  310. MWF.require("MWF.widget.ScriptArea", function(){
  311. var scriptArea = new MWF.widget.ScriptArea(node, {
  312. "title": title,
  313. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  314. "maxObj": this.designer.editContentNode,
  315. "onChange": function(){
  316. this.data[name] = scriptArea.toJson().code;
  317. }.bind(this),
  318. "onSave": function(){
  319. this.designer.saveView();
  320. }.bind(this),
  321. "style": style || "default"
  322. });
  323. scriptArea.load({"code": scriptContent});
  324. }.bind(this));
  325. }.bind(this));
  326. },
  327. loadPersonInput: function(){
  328. var identityNodes = this.propertyContent.getElements(".MWFPersonIdentity");
  329. var personUnitNodes = this.propertyContent.getElements(".MWFPersonUnit");
  330. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  331. identityNodes.each(function(node){
  332. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  333. "type": "identity",
  334. "names": this.data[node.get("name")],
  335. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  336. });
  337. }.bind(this));
  338. personUnitNodes.each(function(node){
  339. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  340. "type": "unit",
  341. "names": this.data[node.get("name")],
  342. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  343. });
  344. }.bind(this));
  345. }.bind(this));
  346. },
  347. savePersonItem: function(node, ids){
  348. var values = [];
  349. ids.each(function(id){
  350. //values.push({"name": (id.data.distinguishedName || id.data.name), "id": id.data.id});
  351. values.push((id.data.distinguishedName || id.data.id || id.data.name));
  352. }.bind(this));
  353. var name = node.get("name");
  354. key = name.split(".");
  355. var o = this.data;
  356. var len = key.length-1;
  357. key.each(function(n, i){
  358. if (!o[n]) o[n] = {};
  359. if (i<len) o = o[n];
  360. }.bind(this));
  361. o[key[len]] = values;
  362. //this.data.data.restrictWhereEntry[node.get("name")] = values;
  363. },
  364. loadPersonSelectInput: function(){
  365. var applicationNodes = this.propertyContent.getElements(".MWFSelectApplication");
  366. var processNodes = this.propertyContent.getElements(".MWFSelectProcess");
  367. // var companyNodes = this.propertyContent.getElements(".MWFSelectCompany");
  368. // var departmentNodes = this.propertyContent.getElements(".MWFSelectDepartment");
  369. var personNodes = this.propertyContent.getElements(".MWFSelectPerson");
  370. var identityNodes = this.propertyContent.getElements(".MWFSelectIdentity");
  371. var personUnitNodes = this.propertyContent.getElements(".MWFSelectUnit");
  372. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  373. applicationNodes.each(function(node){
  374. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  375. "type": "application",
  376. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.applicationList : [],
  377. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  378. });
  379. }.bind(this));
  380. processNodes.each(function(node){
  381. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  382. "type": "process",
  383. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.processList : [],
  384. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  385. });
  386. }.bind(this));
  387. personUnitNodes.each(function(node){
  388. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  389. "type": "unit",
  390. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.unitList : [],
  391. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  392. });
  393. }.bind(this));
  394. personNodes.each(function(node){
  395. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  396. "type": "person",
  397. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.personList : [],
  398. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  399. });
  400. }.bind(this));
  401. identityNodes.each(function(node){
  402. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  403. "type": "identity",
  404. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.identityList : [],
  405. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  406. });
  407. }.bind(this));
  408. }.bind(this));
  409. },
  410. savePersonSelectItem: function(node, ids){
  411. //this.initWhereEntryData();
  412. debugger;
  413. var values = [];
  414. ids.each(function(id){
  415. values.push({"name": (id.data.distinguishedName || id.data.name), "id": id.data.id});
  416. //values.push((id.data.distinguishedName || id.data.id || id.data.name));
  417. }.bind(this));
  418. var name = node.get("name");
  419. key = name.split(".");
  420. var o = this.data;
  421. var len = key.length-1;
  422. key.each(function(n, i){
  423. if (!o[n]) o[n] = {};
  424. if (i<len) o = o[n];
  425. }.bind(this));
  426. o[key[len]] = values;
  427. //this.data.data.restrictWhereEntry[node.get("name")] = values;
  428. },
  429. //loadWorkDataEditor: function(){
  430. // var workDataNodes = this.propertyContent.getElements(".MWFWorkData");
  431. // workDataNodes.each(function(node){
  432. // var select = node.getElement("select");
  433. // for (var i=0; i<select.options.length; i++){
  434. // if (select.options[i].value==this.data.name){
  435. // select.options[i].set("selected", true);
  436. // break;
  437. // }
  438. // }
  439. // if (!this.data.type) this.data.type = "text";
  440. // select.addEvent("change", function(e){
  441. // delete this.data.path;
  442. // this.data.name = select.options[select.selectedIndex].value;
  443. // this.module.listNode.getLast().set("text", this.data.text+"("+this.data.name+")");
  444. // this.setDataType();
  445. // }.bind(this));
  446. //
  447. // this.setDataType();
  448. // }.bind(this));
  449. // var nodes = this.propertyContent.getElements(".MWFWorkDataCheck");
  450. // nodes.each(function(node){
  451. // if (this.data.name) node.set("checked", true);
  452. // }.bind(this));
  453. //},
  454. //setDataType: function(){
  455. // switch (this.data.name){
  456. // case "startTime":case "completedTime":
  457. // this.data.type ="date";
  458. // break;
  459. // case "completed":
  460. // this.data.type ="boolean";
  461. // break;
  462. // default:
  463. // this.data.type ="text";
  464. // }
  465. //},
  466. //loadDataDataEditor: function(){
  467. // var nodes = this.propertyContent.getElements(".MWFDataData");
  468. // nodes.each(function(node){
  469. // var input = node.getElement("input");
  470. // input.set("value", this.data.path);
  471. // input.addEvent("change", function(e){
  472. // delete this.data.name;
  473. // this.data.path = input.get("value");
  474. // this.module.listNode.getLast().set("text", this.data.text+"("+this.data.path+")");
  475. // }.bind(this));
  476. // input.addEvent("blur", function(e){
  477. // delete this.data.name;
  478. // this.data.path = input.get("value");
  479. // this.module.listNode.getLast().set("text", this.data.text+"("+this.data.path+")");
  480. // }.bind(this));
  481. // input.addEvent("keydown", function(e){
  482. // if (e.code==13){
  483. // delete this.data.name;
  484. // this.data.path = input.get("value");
  485. // this.module.listNode.getLast().set("text", this.data.text+"("+this.data.path+")");
  486. // }
  487. // e.stopPropagation();
  488. // }.bind(this));
  489. //
  490. // var select = node.getElement("select");
  491. // for (var i=0; i<select.options.length; i++){
  492. // if (select.options[i].value==this.data.type){
  493. // select.options[i].set("selected", true);
  494. // break;
  495. // }
  496. // }
  497. // if (!this.data.type) this.data.type = "text";
  498. // select.addEvent("change", function(e){
  499. // this.data.type = select.options[select.selectedIndex].value;
  500. // }.bind(this));
  501. //
  502. // }.bind(this));
  503. // var nodes = this.propertyContent.getElements(".MWFDataDataCheck");
  504. // nodes.each(function(node){
  505. // if (this.data.path) node.set("checked", true);
  506. // }.bind(this));
  507. //},
  508. loadColumnExportEditor: function(){
  509. var _self = this;
  510. var nodes = this.propertyContent.getElements(".MWFColumnExport");
  511. nodes.each(function(node){
  512. //if (!this.data.export) this.data.export = {};
  513. //var sort = this.data.export.sort || "";
  514. //var sortOrder = this.data.export.sortOrder || "1";
  515. var select = node.getElement("select");
  516. var sortList = this.view.data.data.orderEntryList;
  517. sortList.each(function(order){
  518. if (order.column==this.data.column){
  519. if (order.orderType=="asc") select.options[1].set("selected", true);
  520. if (order.orderType=="desc") select.options[1].set("selected", false);
  521. }
  522. }.bind(this));
  523. select.addEvent("change", function(e){
  524. var v = select.options[select.selectedIndex].value;
  525. if (v!="none"){
  526. var flag = false;
  527. sortList.each(function(order){
  528. if (order.column==this.data.column){
  529. flag = true;
  530. order.orderType=select.options[select.selectedIndex].value;
  531. }
  532. }.bind(this));
  533. if (!flag) sortList.push({"column": this.data.column, "orderType": select.options[select.selectedIndex].value});
  534. }else{
  535. var deleteItem = null;
  536. sortList.each(function(order){
  537. if (order.column==this.data.column){
  538. deleteItem = order;
  539. }
  540. }.bind(this));
  541. if (deleteItem) sortList.erase(deleteItem);
  542. }
  543. }.bind(this));
  544. var radios = node.getElements("input");
  545. var group = this.view.data.data.group;
  546. if (group.column==this.data.column) radios[0].set("checked", true);
  547. radios.addEvent("click", function(e){
  548. if (this.checked){
  549. if (this.value=="true") {
  550. _self.view.data.data.group.column = _self.data.column;
  551. _self.view.items.each(function(col){
  552. if (col.property){
  553. var groupRadios = col.property.propertyContent.getElement(".MWFColumnExportGroup").getElements("input");
  554. groupRadios.each(function(r){
  555. if (r.value=="true") r.set("checked", false);
  556. if (r.value=="false") r.set("checked", true);
  557. });
  558. }
  559. });
  560. this.set("checked", true);
  561. }else{
  562. if (group.column ==_self.data.column) _self.view.data.data.group = {};
  563. }
  564. }
  565. });
  566. }.bind(this));
  567. },
  568. loadViewFilter: function(){
  569. var nodes = this.propertyContent.getElements(".MWFViewFilter");
  570. var filtrData = this.view.data.data.restrictFilterEntryList;
  571. var customData = this.view.data.data.customFilterEntryList;
  572. nodes.each(function(node){
  573. MWF.xDesktop.requireApp("process.ViewDesigner", "widget.ViewFilter", function(){
  574. var _slef = this;
  575. new MWF.xApplication.process.ViewDesigner.widget.ViewFilter(node, this.view.designer, {"filtrData": filtrData, "customData": customData}, {
  576. "onChange": function(ids){
  577. debugger;
  578. var data = this.getData();
  579. _slef.changeJsonDate(["data", "restrictFilterEntryList"], data.data);
  580. _slef.changeJsonDate(["data", "customFilterEntryList"], data.customData);
  581. }
  582. });
  583. }.bind(this));
  584. }.bind(this));
  585. },
  586. loadColumnFilter: function(){
  587. var nodes = this.propertyContent.getElements(".MWFColumnFilter");
  588. nodes.each(function(node){
  589. this.module.filterAreaNode = node;
  590. var table = new Element("table", {
  591. "styles": {"width": "100%"},
  592. "border": "0px",
  593. "cellPadding": "0",
  594. "cellSpacing": "0"
  595. }).inject(node);
  596. var tr = new Element("tr", {"styles": this.module.css.filterTableTitle}).inject(table);
  597. var html = "<th style='width:24px;border-right:1px solid #CCC;border-bottom:1px solid #999;'></th>" +
  598. "<th style='border-right:1px solid #CCC;border-left:1px solid #FFF;border-bottom:1px solid #999;'>逻辑</th>" +
  599. "<th style='border-right:1px solid #CCC;border-left:1px solid #FFF;border-bottom:1px solid #999;'>路径</th>" +
  600. "<th style='border-right:1px solid #CCC;border-left:1px solid #FFF;border-bottom:1px solid #999;'>比较</th>" +
  601. "<th style='border-left:1px solid #FFF;border-bottom:1px solid #999;'>值</th>";
  602. tr.set("html", html);
  603. var addActionNode = new Element("div", {"styles": this.module.css.filterAddActionNode}).inject(tr.getFirst("th"));
  604. addActionNode.addEvent("click", function(){
  605. this.addFilter(table);
  606. }.bind(this));
  607. if (this.data.filterList) {
  608. this.data.filterList.each(function (op) {
  609. new MWF.xApplication.process.ViewDesigner.Property.Filter(op, table, this);
  610. }.bind(this));
  611. }
  612. }.bind(this));
  613. },
  614. addFilter: function(table){
  615. op = {
  616. "logic": "and",
  617. "comparison": "",
  618. "value": ""
  619. }
  620. if (!this.data.filterList) this.data.filterList = [];
  621. this.data.filterList.push(op);
  622. var filter = new MWF.xApplication.process.ViewDesigner.Property.Filter(op, table, this);
  623. filter.editMode();
  624. }
  625. //initWhereEntryData: function(){
  626. // if (!this.data.data.restrictWhereEntry) this.data.data.restrictWhereEntry = {
  627. // "applicationList": [],
  628. // "processList": [],
  629. // "companyList": [],
  630. // "departmentList": [],
  631. // "personList": [],
  632. // "identityList": []
  633. // };
  634. //},
  635. //loadApplicationSelector: function(){
  636. // var nodes = this.propertyContent.getElements(".MWFApplicationSelect");
  637. // if (nodes.length){
  638. // MWF.xDesktop.requireApp("Organization", "Selector.package", function(){
  639. // nodes.each(function(node){
  640. // var title = new Element("div", {"styles": this.view.css.applicationSelectTitle, "text": node.get("title")}).inject(node);
  641. // var content = new Element("div", {"styles": this.view.css.applicationSelectContent}).inject(node);
  642. // var action = new Element("div", {"styles": this.view.css.applicationSelectAction, "text": node.get("title")}).inject(node);
  643. // action.addEvent("click", function(e){
  644. // var values = [];
  645. // if (this.data.data.whereEntry){
  646. // if (this.data.data.whereEntry.applicationList.length){
  647. // this.data.data.whereEntry.applicationList.each(function(item){
  648. // values.push(item.id);
  649. // }.bind(this));
  650. // }
  651. // }
  652. // var options = {
  653. // "type": "application",
  654. // "count": 0,
  655. // "values": values,
  656. // //"title": this.app.lp.monthly.selectSortApplication,
  657. // "onComplete": function(items){
  658. // this.initWhereEntryData();
  659. // this.data.data.whereEntry.applicationList = [];
  660. // content.empty();
  661. // items.each(function(item){
  662. // this.data.data.whereEntry.applicationList.push({
  663. // "id": item.data.id,
  664. // "name": item.data.name
  665. // });
  666. // new Element("div", {
  667. // "styles": this.view.css.applicationSelectItem,
  668. // "text": item.data.name
  669. // }).inject(content);
  670. // }.bind(this));
  671. // }.bind(this)
  672. // };
  673. // var selector = new MWF.OrgSelector(this.view.designer.content, options);
  674. // }.bind(this));
  675. //
  676. // this.initWhereEntryData();
  677. // this.data.data.whereEntry.applicationList.each(function(app){
  678. // new Element("div", {
  679. // "styles": this.view.css.applicationSelectItem,
  680. // "text": app.name
  681. // }).inject(content);
  682. // }.bind(this));
  683. // }.bind(this));
  684. // }.bind(this));
  685. // }
  686. //},
  687. //loadApplicationSelector1: function(){
  688. // var nodes = this.propertyContent.getElements(".MWFApplicationSelect");
  689. // if (nodes.length){
  690. // this._getAppSelector(function(){
  691. // nodes.each(function(node){
  692. // var title = new Element("div", {"styles": this.view.css.applicationSelectTitle, "text": node.get("title")}).inject(node);
  693. // var content = new Element("div", {"styles": this.view.css.applicationSelectContent}).inject(node);
  694. // var action = new Element("div", {"styles": this.view.css.applicationSelectAction, "text": node.get("title")}).inject(node);
  695. // action.addEvent("click", function(e){
  696. // this.appSelector.load(function(apps){
  697. // if (!this.data.data.select) this.data.data.select = {"applicationRestrictList": [], "processRestrictList": []};
  698. // this.data.data.select.applicationRestrictList = [];
  699. // content.empty();
  700. // if (apps.length){
  701. // apps.each(function(app){
  702. // var o = {
  703. // "name": app.name,
  704. // "id": app.id,
  705. // "alias": app.alias
  706. // }
  707. // this.data.data.select.applicationRestrictList.push(o);
  708. //
  709. // new Element("div", {
  710. // "styles": this.view.css.applicationSelectItem,
  711. // "text": app.name
  712. // }).inject(content);
  713. //
  714. // }.bind(this));
  715. // }
  716. // }.bind(this));
  717. // }.bind(this));
  718. // if (!this.data.data.select) this.data.data.select = {"applicationRestrictList": [], "processRestrictList": []};
  719. // this.data.data.select.applicationRestrictList.each(function(app){
  720. // new Element("div", {
  721. // "styles": this.view.css.applicationSelectItem,
  722. // "text": app.name
  723. // }).inject(content);
  724. // }.bind(this));
  725. //
  726. // }.bind(this));
  727. // }.bind(this));
  728. // }
  729. //},
  730. //
  731. //_getAppSelector: function(callback){
  732. // if (!this.appSelector){
  733. // MWF.xDesktop.requireApp("process.ProcessManager", "widget.ApplicationSelector", function(){
  734. // this.appSelector = new MWF.xApplication.process.ProcessManager.widget.ApplicationSelector(this.view.designer, {"maskNode": this.view.designer.content});
  735. // if (callback) callback();
  736. // }.bind(this));
  737. // }else{
  738. // if (callback) callback();
  739. // }
  740. //},
  741. //this.initWhereEntryData();
  742. //loadProcessSelector: function(){
  743. // var nodes = this.propertyContent.getElements(".MWFApplicationSelect");
  744. // if (nodes.length){
  745. // MWF.xDesktop.requireApp("Organization", "Selector.package", function(){
  746. // nodes.each(function(node){
  747. // var title = new Element("div", {"styles": this.view.css.applicationSelectTitle, "text": node.get("title")}).inject(node);
  748. // var content = new Element("div", {"styles": this.view.css.applicationSelectContent}).inject(node);
  749. // var action = new Element("div", {"styles": this.view.css.applicationSelectAction, "text": node.get("title")}).inject(node);
  750. // action.addEvent("click", function(e){
  751. // var values = [];
  752. // if (this.data.data.whereEntry){
  753. // if (this.data.data.whereEntry.processList.length){
  754. // this.data.data.whereEntry.processList.each(function(item){
  755. // values.push(item.id);
  756. // }.bind(this));
  757. // }
  758. // }
  759. // var options = {
  760. // "type": "process",
  761. // "count": 0,
  762. // "values": values,
  763. // "onComplete": function(items){
  764. // this.initWhereEntryData();
  765. // this.data.data.whereEntry.processList = [];
  766. // content.empty();
  767. // items.each(function(item){
  768. // this.data.data.whereEntry.processList.push({
  769. // "id": item.data.id,
  770. // "name": item.data.name
  771. // });
  772. // new Element("div", {
  773. // "styles": this.view.css.applicationSelectItem,
  774. // "text": item.data.name
  775. // }).inject(content);
  776. // }.bind(this));
  777. // }.bind(this)
  778. // };
  779. // var selector = new MWF.OrgSelector(this.view.designer.content, options);
  780. // }.bind(this));
  781. //
  782. // this.initWhereEntryData();
  783. // this.data.data.whereEntry.processList.each(function(app){
  784. // new Element("div", {
  785. // "styles": this.view.css.applicationSelectItem,
  786. // "text": app.name
  787. // }).inject(content);
  788. // }.bind(this));
  789. // }.bind(this));
  790. // }.bind(this));
  791. // }
  792. //}
  793. //loadProcessSelector1: function(){
  794. // var nodes = this.propertyContent.getElements(".MWFProcessSelect");
  795. // if (nodes.length){
  796. // this._getProcessSelector(function(){
  797. // nodes.each(function(node){
  798. // var title = new Element("div", {"styles": this.view.css.applicationSelectTitle, "text": node.get("title")}).inject(node);
  799. // var content = new Element("div", {"styles": this.view.css.applicationSelectContent}).inject(node);
  800. // var action = new Element("div", {"styles": this.view.css.applicationSelectAction, "text": node.get("title")}).inject(node);
  801. // action.addEvent("click", function(e){
  802. // var ids=[];
  803. // this.data.data.select.applicationRestrictList.each(function(app){
  804. // ids.push(app.id);
  805. // });
  806. // this.processSelector.load(ids, function(apps){
  807. // if (!this.data.data.select) this.data.data.select = {"applicationRestrictList": [], "processRestrictList": []};
  808. // this.data.data.select.processRestrictList = [];
  809. // content.empty();
  810. // if (apps.length){
  811. // apps.each(function(app){
  812. // var o = {
  813. // "name": app.name,
  814. // "id": app.id,
  815. // "alias": app.alias
  816. // }
  817. // this.data.data.select.processRestrictList.push(o);
  818. //
  819. // new Element("div", {
  820. // "styles": this.view.css.applicationSelectItem,
  821. // "text": app.name
  822. // }).inject(content);
  823. //
  824. // }.bind(this));
  825. // }
  826. // }.bind(this));
  827. // }.bind(this));
  828. // if (!this.data.data.select) this.data.data.select = {"applicationRestrictList": [], "processRestrictList": []};
  829. // this.data.data.select.processRestrictList.each(function(app){
  830. // new Element("div", {
  831. // "styles": this.view.css.applicationSelectItem,
  832. // "text": app.name
  833. // }).inject(content);
  834. // }.bind(this));
  835. //
  836. // }.bind(this));
  837. // }.bind(this));
  838. // }
  839. //},
  840. //_getProcessSelector: function(callback){
  841. // if (!this.processSelector){
  842. // MWF.xDesktop.requireApp("process.ProcessManager", "widget.ProcessSelector", function(){
  843. // this.processSelector = new MWF.xApplication.process.ProcessManager.widget.ProcessSelector(this.view.designer, {"maskNode": this.view.designer.content});
  844. // if (callback) callback();
  845. // }.bind(this));
  846. // }else{
  847. // if (callback) callback();
  848. // }
  849. //}
  850. });
  851. MWF.xApplication.process.ViewDesigner.Property.Filter = new Class({
  852. Implements: [Events],
  853. initialize: function(json, table, property){
  854. this.property = property;
  855. this.module = property.module;
  856. this.table = table;
  857. this.data = json;
  858. this.load();
  859. },
  860. load: function(){
  861. this.node = new Element("tr", {"styles": this.module.css.filterTableTd}).inject(this.table);
  862. var html = "<td style='widtd:24px;border-right:1px solid #CCC;border-bottom:1px solid #999;'></td>" +
  863. "<td style='padding:3px;border-right:1px solid #CCC;border-bottom:1px solid #999; width:60px'>"+this.data.logic+"</td>" +
  864. "<td style='padding:3px;border-right:1px solid #CCC;border-bottom:1px solid #999; width:30px'>列值</td>" +
  865. "<td style='padding:3px;border-right:1px solid #CCC;border-bottom:1px solid #999;'>"+this.data.comparison+"</td>" +
  866. "<td style='padding:3px;border-bottom:1px solid #999;'>"+this.data.value+"</td>";
  867. this.node.set("html", html);
  868. var tds = this.node.getElements("td");
  869. this.delActionNode = new Element("div", {"styles": this.module.css.filterDelActionNode}).inject(tds[0]);
  870. this.delActionNode.addEvent("click", function(e){
  871. this.delFilter(e);
  872. e.stopPropagation();
  873. }.bind(this));
  874. this.logicNode = tds[1];
  875. this.comparisonNode = tds[3];
  876. this.valueNode = tds[4];
  877. this.node.addEvent("click", function(){
  878. if (!this.isEditMode) this.editMode();
  879. }.bind(this));
  880. this.node.addEvent("blur", function(){
  881. if (this.isEditMode) this.readMode();
  882. }.bind(this));
  883. },
  884. delFilter: function(e){
  885. var _self = this;
  886. this.property.designer.confirm("warn", e, MWF.APPVD.LP.notice.deleteFilterTitle, MWF.APPVD.LP.notice.deleteFilter, 300, 120, function(){
  887. _self.node.destroy();
  888. _self.property.data.filterList.erase(_self.data);
  889. MWF.release(_self);
  890. this.close();
  891. }, function(){
  892. this.close();
  893. }, null);
  894. },
  895. editMode: function(){
  896. if (this.property.editModeFilter){
  897. if (this.property.editModeFilter!=this) this.property.editModeFilter.readMode();
  898. }
  899. var width = this.logicNode.getSize().x-9;
  900. this.logicNode.empty();
  901. var logicSelect = new Element("select", {"styles": {"width": "90%"}}).inject(this.logicNode);
  902. var html = "";
  903. if (this.data.logic=="and"){
  904. html = "<option value=\"and\" selected>and</option><option value=\"or\">or</option>";
  905. }else{
  906. html = "<option value=\"and\">and</option><option value=\"or\" selected>or</option>";
  907. }
  908. logicSelect.set("html", html);
  909. logicSelect.addEvent("change", function(){
  910. this.data.logic = logicSelect.options[logicSelect.selectedIndex].value;
  911. }.bind(this));
  912. width = this.comparisonNode.getSize().x-9;
  913. this.comparisonNode.empty();
  914. var comparisonSelect = new Element("select", {"styles": {"width": "90%"}}).inject(this.comparisonNode);
  915. html = "";
  916. switch (this.property.data.type){
  917. case "text":
  918. html += "<option value=''></option><option value='==' "+((this.data.comparison=="==") ? "selected": "")+">等于(==)</option>" +
  919. "<option value='!=' "+((this.data.comparison=="!=") ? "selected": "")+">不等于(!=)</option>" +
  920. "<option value='@' "+((this.data.comparison=="@") ? "selected": "")+">包含(@)</option>";
  921. break;
  922. case "date":
  923. html += "<option value=''></option><option value='&gt;' "+((this.data.comparison==">") ? "selected": "")+">大于(&gt;)</option>" +
  924. "<option value='&lt;' "+((this.data.comparison=="<") ? "selected": "")+">小于(&lt;)</option>" +
  925. "<option value='&gt;=' "+((this.data.comparison==">=") ? "selected": "")+">大于等于(&gt;=)</option>" +
  926. "<option value='&lt;=' "+((this.data.comparison=="<=") ? "selected": "")+">小于等于(&lt;=)</option>";
  927. break;
  928. case "number":
  929. html += "<option value=''></option><option value='==' "+((this.data.comparison=="==") ? "selected": "")+">等于(==)</option>" +
  930. "<option value='!=' "+((this.data.comparison=="!=") ? "selected": "")+">不等于(!=)</option>" +
  931. "<option value='&gt;' "+((this.data.comparison==">") ? "selected": "")+">大于(&gt;)</option>" +
  932. "<option value='&lt;' "+((this.data.comparison=="<") ? "selected": "")+">小于(&lt;)</option>" +
  933. "<option value='&gt;=' "+((this.data.comparison==">=") ? "selected": "")+">大于等于(&gt;=)</option>" +
  934. "<option value='&lt;=' "+((this.data.comparison=="<=") ? "selected": "")+">小于等于(&lt;=)</option>";
  935. break;
  936. case "boolean":
  937. html += "<option value=''></option><option value='==' "+((this.data.comparison=="==") ? "selected": "")+">等于(==)</option>" +
  938. "<option value='!=' "+((this.data.comparison=="!=") ? "selected": "")+">不等于(!=)</option>";
  939. break;
  940. }
  941. comparisonSelect.set("html", html);
  942. comparisonSelect.addEvent("change", function(){
  943. this.data.comparison = comparisonSelect.options[comparisonSelect.selectedIndex].value;
  944. }.bind(this));
  945. width = this.valueNode.getSize().x-9;
  946. this.valueNode.empty();
  947. var type = "text";
  948. switch (this.property.data.type){
  949. case "date":
  950. var valueInput = new Element("input", {"styles": {"width": "90%"},
  951. "type": "text",
  952. "value": this.data.value
  953. }).inject(this.valueNode);
  954. MWF.require("MWF.widget.Calendar", function(){
  955. this.calendar = new MWF.widget.Calendar(valueInput, {
  956. "style": "xform",
  957. "isTime": true,
  958. "target": this.property.designer.content,
  959. "format": "%Y-%m-%d %H:%M:%S"
  960. });
  961. //this.calendar.show();
  962. }.bind(this));
  963. break;
  964. case "number":
  965. var valueInput = new Element("input", {"styles": {"width": "90%"},
  966. "type": "number",
  967. "value": this.data.value
  968. }).inject(this.valueNode);
  969. break;
  970. case "boolean":
  971. var valueInput = new Element("select", {"styles": {"width": ""+width+"px"},
  972. "html": "<option value=\"\"></option><option value=\"true\" "+((this.data.value) ? "selected": "")+">true</option><option value=\"false\" "+((!this.data.value) ? "selected": "")+">false</option>"
  973. }).inject(this.valueNode);
  974. break;
  975. default:
  976. var valueInput = new Element("input", {"styles": {"width": "90%"},
  977. "type": "text",
  978. "value": this.data.value
  979. }).inject(this.valueNode);
  980. }
  981. if (valueInput.tagName.toLowerCase()=="select"){
  982. valueInput.addEvent("change", function(){
  983. var v = valueInput.options[valueInput.selectedIndex].value;
  984. this.data.value = (v="true") ? true : false;
  985. }.bind(this));
  986. }else{
  987. valueInput.addEvent("change", function(e){
  988. this.data.value = valueInput.get("value");
  989. }.bind(this));
  990. valueInput.addEvent("blur", function(e){
  991. this.data.value = valueInput.get("value");
  992. }.bind(this));
  993. valueInput.addEvent("keydown", function(e){
  994. if (e.code==13){
  995. this.data.value = valueInput.get("value");
  996. this.readMode();
  997. }
  998. e.stopPropagation();
  999. }.bind(this));
  1000. }
  1001. this.isEditMode = true;
  1002. this.property.editModeFilter = this;
  1003. },
  1004. readMode: function(){
  1005. if (this.isEditMode){
  1006. var logicSelect = this.logicNode.getElement("select");
  1007. this.data.logic = logicSelect.options[logicSelect.selectedIndex].value;
  1008. var comparisonSelect = this.comparisonNode.getElement("select");
  1009. this.data.comparison = comparisonSelect.options[comparisonSelect.selectedIndex].value;
  1010. var valueInput = this.valueNode.getFirst();
  1011. if (valueInput.tagName.toLowerCase()=="select"){
  1012. var v = valueInput.options[valueInput.selectedIndex].value;
  1013. this.data.value = (v="true") ? true : false;
  1014. }else{
  1015. this.data.value = valueInput.get("value");
  1016. }
  1017. this.logicNode.empty();
  1018. this.comparisonNode.empty();
  1019. this.valueNode.empty();
  1020. this.logicNode.set("text", this.data.logic);
  1021. this.comparisonNode.set("text", this.data.comparison);
  1022. this.valueNode.set("text", this.data.value);
  1023. this.isEditMode = false;
  1024. this.property.editModeFilter = null;
  1025. }
  1026. }
  1027. });