Property.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. MWF.require("MWF.widget.Common", null, false);
  2. MWF.require("MWF.widget.JsonTemplate", null, false);
  3. MWF.xApplication.process.StatDesigner.Property = MWF.FVProperty = new Class({
  4. Extends: MWF.widget.Common,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "path": "../x_component_process_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.htmlPath = this.options.path;
  16. this.designer = designer;
  17. this.propertyNode = propertyNode;
  18. },
  19. load: function(){
  20. if (this.fireEvent("queryLoad")){
  21. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  22. this.htmlString = responseText;
  23. this.fireEvent("postLoad");
  24. }.bind(this));
  25. }
  26. this.propertyNode.addEvent("keydown", function(e){e.stopPropagation();});
  27. },
  28. editProperty: function(td){
  29. },
  30. getHtmlString: function(callback){
  31. if (!this.htmlString){
  32. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  33. this.htmlString = responseText;
  34. if (callback) callback();
  35. }.bind(this));
  36. }else{
  37. if (callback) callback();
  38. }
  39. },
  40. show: function(){
  41. if (!this.propertyContent){
  42. this.getHtmlString(function(){
  43. if (this.htmlString){
  44. this.JsonTemplate = new MWF.widget.JsonTemplate(this.data, this.htmlString);
  45. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyNode);
  46. this.propertyContent.set("html", this.JsonTemplate.load());
  47. this.setEditNodeEvent();
  48. this.setEditNodeStyles(this.propertyContent);
  49. this.loadPropertyTab();
  50. this.loadPersonInput();
  51. this.loadPersonSelectInput();
  52. this.loadViewSelect();
  53. this.loadScriptArea();
  54. this.loadJSONArea();
  55. //this.view.changeViewSelected();
  56. this.module.changeViewSelected();
  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. this.module._setEditStyle(name, input, oldValue);
  212. },
  213. changeJsonDate: function(key, value){
  214. if (typeOf(key)!="array") key = [key];
  215. var o = this.data;
  216. var len = key.length-1;
  217. key.each(function(n, i){
  218. if (!o[n]) o[n] = {};
  219. if (i<len) o = o[n];
  220. }.bind(this));
  221. o[key[len]] = value;
  222. },
  223. setRadioValue: function(name, input){
  224. if (input.checked){
  225. var i = name.indexOf("*");
  226. var names = (i==-1) ? name.split(".") : name.substr(i+1, name.length).split(".");
  227. var value = input.value;
  228. if (value=="false") value = false;
  229. if (value=="true") value = true;
  230. var oldValue = this.data;
  231. for (var idx = 0; idx<names.length; idx++){
  232. if (!oldValue[names[idx]]){
  233. oldValue = null;
  234. break;
  235. }else{
  236. oldValue = oldValue[names[idx]];
  237. }
  238. }
  239. //var oldValue = this.data[name];
  240. this.changeJsonDate(names, value);
  241. this.changeData(name, input, oldValue);
  242. }
  243. },
  244. setCheckboxValue: function(name, input){
  245. var id = this.module.json.id;
  246. var checkboxList = $$("input[name='"+id+name+"']");
  247. var values = [];
  248. checkboxList.each(function(checkbox){
  249. if (checkbox.get("checked")){
  250. values.push(checkbox.value);
  251. }
  252. });
  253. var oldValue = this.data[name];
  254. //this.data[name] = values;
  255. this.changeJsonDate(name, values);
  256. this.changeData(name, input, oldValue);
  257. },
  258. setSelectValue: function(name, select){
  259. var idx = select.selectedIndex;
  260. var options = select.getElements("option");
  261. var value = "";
  262. if (options[idx]){
  263. value = options[idx].get("value");
  264. }
  265. var i = name.indexOf("*");
  266. var names = (i==-1) ? name.split(".") : name.substr(i+1, name.length).split(".");
  267. //var oldValue = this.data[name];
  268. var oldValue = this.data;
  269. for (var idx = 0; idx<names.length; idx++){
  270. if (!oldValue[names[idx]]){
  271. oldValue = null;
  272. break;
  273. }else{
  274. oldValue = oldValue[names[idx]];
  275. }
  276. }
  277. //var oldValue = this.data[name];
  278. //this.data[name] = value;
  279. this.changeJsonDate(names, value);
  280. this.changeData(name, select, oldValue);
  281. },
  282. setValue: function(name, value, obj){
  283. var names = name.split(".");
  284. var oldValue = this.data;
  285. for (var idx = 0; idx<names.length; idx++){
  286. if (!oldValue[names[idx]]){
  287. oldValue = null;
  288. break;
  289. }else{
  290. oldValue = oldValue[names[idx]];
  291. }
  292. }
  293. //var oldValue = this.data[name];
  294. //this.data[name] = value;
  295. this.changeJsonDate(names, value);
  296. this.changeData(name, obj, oldValue);
  297. },
  298. setEditNodeStyles: function(node){
  299. var nodes = node.getChildren();
  300. if (nodes.length){
  301. nodes.each(function(el){
  302. var cName = el.get("class");
  303. if (cName){
  304. if (this.view.css[cName]) el.setStyles(this.view.css[cName]);
  305. }
  306. this.setEditNodeStyles(el);
  307. }.bind(this));
  308. }
  309. },
  310. loadPersonInput: function(){
  311. var identityNodes = this.propertyContent.getElements(".MWFPersonIdentity");
  312. var personUnitNodes = this.propertyContent.getElements(".MWFPersonUnit");
  313. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  314. identityNodes.each(function(node){
  315. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  316. "type": "identity",
  317. "names": this.data[node.get("name")],
  318. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  319. });
  320. }.bind(this));
  321. personUnitNodes.each(function(node){
  322. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  323. "type": "unit",
  324. "names": this.data[node.get("name")],
  325. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  326. });
  327. }.bind(this));
  328. }.bind(this));
  329. },
  330. savePersonItem: function(node, ids){
  331. var values = [];
  332. ids.each(function(id){
  333. //values.push({"name": (id.data.distinguishedName || id.data.name), "id": id.data.id});
  334. values.push((id.data.distinguishedName || id.data.id || id.data.name));
  335. }.bind(this));
  336. var name = node.get("name");
  337. key = name.split(".");
  338. var o = this.data;
  339. var len = key.length-1;
  340. key.each(function(n, i){
  341. if (!o[n]) o[n] = {};
  342. if (i<len) o = o[n];
  343. }.bind(this));
  344. o[key[len]] = values;
  345. //this.data.data.restrictWhereEntry[node.get("name")] = values;
  346. },
  347. loadPersonSelectInput: function(){
  348. var applicationNodes = this.propertyContent.getElements(".MWFSelectApplication");
  349. var processNodes = this.propertyContent.getElements(".MWFSelectProcess");
  350. // var companyNodes = this.propertyContent.getElements(".MWFSelectCompany");
  351. // var departmentNodes = this.propertyContent.getElements(".MWFSelectDepartment");
  352. var personNodes = this.propertyContent.getElements(".MWFSelectPerson");
  353. var identityNodes = this.propertyContent.getElements(".MWFSelectIdentity");
  354. var personUnitNodes = this.propertyContent.getElements(".MWFSelectUnit");
  355. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  356. applicationNodes.each(function(node){
  357. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  358. "type": "application",
  359. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.applicationList : [],
  360. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  361. });
  362. }.bind(this));
  363. processNodes.each(function(node){
  364. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  365. "type": "process",
  366. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.processList : [],
  367. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  368. });
  369. }.bind(this));
  370. personUnitNodes.each(function(node){
  371. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  372. "type": "unit",
  373. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.unitList : [],
  374. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  375. });
  376. }.bind(this));
  377. personNodes.each(function(node){
  378. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  379. "type": "person",
  380. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.personList : [],
  381. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  382. });
  383. }.bind(this));
  384. identityNodes.each(function(node){
  385. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  386. "type": "identity",
  387. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.identityList : [],
  388. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  389. });
  390. }.bind(this));
  391. }.bind(this));
  392. },
  393. savePersonSelectItem: function(node, ids){
  394. //this.initWhereEntryData();
  395. var values = [];
  396. ids.each(function(id){
  397. values.push({"name": id.data.name, "id": id.data.id});
  398. }.bind(this));
  399. var name = node.get("name");
  400. key = name.split(".");
  401. var o = this.data;
  402. var len = key.length-1;
  403. key.each(function(n, i){
  404. if (!o[n]) o[n] = {};
  405. if (i<len) o = o[n];
  406. }.bind(this));
  407. o[key[len]] = values;
  408. //this.data.data.restrictWhereEntry[node.get("name")] = values;
  409. },
  410. loadViewSelect: function(){
  411. var viewNodes = this.propertyContent.getElements(".MWFViewSelect");
  412. if (viewNodes.length){
  413. this.getViewList(function(){
  414. viewNodes.each(function(node){
  415. var select = new Element("select").inject(node);
  416. select.addEvent("change", function(e){
  417. var viewId = e.target.options[e.target.selectedIndex].value;
  418. var viewName = e.target.options[e.target.selectedIndex].get("text");
  419. this.setValue(e.target.getParent("div").get("name"), viewId);
  420. this.setValue(e.target.getParent("div").get("name")+"Name", viewName);
  421. }.bind(this));
  422. this.setViewSelectOptions(node, select);
  423. var refreshNode = new Element("div", {"styles": this.view.css.propertyRefreshFormNode}).inject(node);
  424. refreshNode.addEvent("click", function(e){
  425. this.getViewList(function(){
  426. this.setViewSelectOptions(node, select);
  427. }.bind(this), true);
  428. }.bind(this));
  429. //select.addEvent("click", function(e){
  430. // this.setFormSelectOptions(node, select);
  431. //}.bind(this));
  432. }.bind(this));
  433. }.bind(this));
  434. }
  435. },
  436. setViewSelectOptions: function(node, select){
  437. var name = node.get("name");
  438. select.empty();
  439. var option = new Element("option", {"text": "(none)"}).inject(select);
  440. this.views.each(function(view){
  441. var option = new Element("option", {
  442. "text": view.name,
  443. "value": view.id,
  444. "selected": (this.data[name]==view.id)
  445. }).inject(select);
  446. }.bind(this));
  447. },
  448. getViewList: function(callback, refresh){
  449. if (!this.views || refresh){
  450. this.view.designer.actions.listView(this.view.designer.application.id, function(json){
  451. this.views = json.data;
  452. if (callback) callback();
  453. }.bind(this));
  454. }else{
  455. if (callback) callback();
  456. }
  457. },
  458. loadScriptArea: function(){
  459. var scriptAreas = this.propertyContent.getElements(".MWFScriptArea");
  460. var formulaAreas = this.propertyContent.getElements(".MWFFormulaArea");
  461. this.loadScriptEditor(scriptAreas);
  462. this.loadScriptEditor(formulaAreas, "formula");
  463. },
  464. loadScriptEditor: function(scriptAreas, style){
  465. scriptAreas.each(function(node){
  466. var title = node.get("title");
  467. var name = node.get("name");
  468. var scriptContent = this.data[name];
  469. MWF.require("MWF.widget.ScriptArea", function(){
  470. var scriptArea = new MWF.widget.ScriptArea(node, {
  471. "title": title,
  472. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  473. "maxObj": this.designer.editContentNode,
  474. "onChange": function(){
  475. this.data[name] = scriptArea.toJson().code;
  476. }.bind(this),
  477. "onSave": function(){
  478. this.designer.saveView();
  479. }.bind(this),
  480. "style": style || "default"
  481. });
  482. scriptArea.load({"code": scriptContent});
  483. }.bind(this));
  484. }.bind(this));
  485. }
  486. });