Property.js 49 KB

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