Property.js 49 KB

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