Property.js 49 KB

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