Property.js 49 KB

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