Property.js 50 KB

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