Property.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. debugger;
  225. if (input.checked){
  226. var i = name.indexOf("*");
  227. var names = (i==-1) ? name.split(".") : name.substr(i+1, name.length).split(".");
  228. var value = input.value;
  229. if (value=="false") value = false;
  230. if (value=="true") value = true;
  231. var oldValue = this.data;
  232. for (var idx = 0; idx<names.length; idx++){
  233. if (!oldValue[names[idx]]){
  234. oldValue = null;
  235. break;
  236. }else{
  237. oldValue = oldValue[names[idx]];
  238. }
  239. }
  240. //var oldValue = this.data[name];
  241. this.changeJsonDate(names, value);
  242. this.changeData(name, input, oldValue);
  243. }
  244. },
  245. setCheckboxValue: function(name, input){
  246. var id = this.module.json.id;
  247. var checkboxList = $$("input[name='"+id+name+"']");
  248. var values = [];
  249. checkboxList.each(function(checkbox){
  250. if (checkbox.get("checked")){
  251. values.push(checkbox.value);
  252. }
  253. });
  254. var oldValue = this.data[name];
  255. //this.data[name] = values;
  256. this.changeJsonDate(name, values);
  257. this.changeData(name, input, oldValue);
  258. },
  259. setSelectValue: function(name, select){
  260. var idx = select.selectedIndex;
  261. var options = select.getElements("option");
  262. var value = "";
  263. if (options[idx]){
  264. value = options[idx].get("value");
  265. }
  266. var oldValue = this.data[name];
  267. //this.data[name] = value;
  268. this.changeJsonDate(name, value);
  269. this.changeData(name, select, oldValue);
  270. },
  271. setValue: function(name, value, obj){
  272. var names = name.split(".");
  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, obj, oldValue);
  286. },
  287. setEditNodeStyles: function(node){
  288. var nodes = node.getChildren();
  289. if (nodes.length){
  290. nodes.each(function(el){
  291. var cName = el.get("class");
  292. if (cName){
  293. if (this.view.css[cName]) el.setStyles(this.view.css[cName]);
  294. }
  295. this.setEditNodeStyles(el);
  296. }.bind(this));
  297. }
  298. },
  299. loadPersonInput: function(){
  300. var identityNodes = this.propertyContent.getElements(".MWFPersonIdentity");
  301. var personUnitNodes = this.propertyContent.getElements(".MWFPersonUnit");
  302. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  303. identityNodes.each(function(node){
  304. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  305. "type": "identity",
  306. "names": this.data[node.get("name")],
  307. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  308. });
  309. }.bind(this));
  310. personUnitNodes.each(function(node){
  311. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  312. "type": "unit",
  313. "names": this.data[node.get("name")],
  314. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  315. });
  316. }.bind(this));
  317. }.bind(this));
  318. },
  319. savePersonItem: function(node, ids){
  320. var values = [];
  321. ids.each(function(id){
  322. //values.push({"name": (id.data.distinguishedName || id.data.name), "id": id.data.id});
  323. values.push((id.data.distinguishedName || id.data.id || id.data.name));
  324. }.bind(this));
  325. var name = node.get("name");
  326. key = name.split(".");
  327. var o = this.data;
  328. var len = key.length-1;
  329. key.each(function(n, i){
  330. if (!o[n]) o[n] = {};
  331. if (i<len) o = o[n];
  332. }.bind(this));
  333. o[key[len]] = values;
  334. //this.data.data.restrictWhereEntry[node.get("name")] = values;
  335. },
  336. loadPersonSelectInput: function(){
  337. var applicationNodes = this.propertyContent.getElements(".MWFSelectApplication");
  338. var processNodes = this.propertyContent.getElements(".MWFSelectProcess");
  339. // var companyNodes = this.propertyContent.getElements(".MWFSelectCompany");
  340. // var departmentNodes = this.propertyContent.getElements(".MWFSelectDepartment");
  341. var personNodes = this.propertyContent.getElements(".MWFSelectPerson");
  342. var identityNodes = this.propertyContent.getElements(".MWFSelectIdentity");
  343. var personUnitNodes = this.propertyContent.getElements(".MWFSelectUnit");
  344. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  345. applicationNodes.each(function(node){
  346. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  347. "type": "application",
  348. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.applicationList : [],
  349. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  350. });
  351. }.bind(this));
  352. processNodes.each(function(node){
  353. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  354. "type": "process",
  355. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.processList : [],
  356. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  357. });
  358. }.bind(this));
  359. personUnitNodes.each(function(node){
  360. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  361. "type": "unit",
  362. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.unitList : [],
  363. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  364. });
  365. }.bind(this));
  366. personNodes.each(function(node){
  367. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  368. "type": "person",
  369. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.personList : [],
  370. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  371. });
  372. }.bind(this));
  373. identityNodes.each(function(node){
  374. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  375. "type": "identity",
  376. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.identityList : [],
  377. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  378. });
  379. }.bind(this));
  380. }.bind(this));
  381. },
  382. savePersonSelectItem: function(node, ids){
  383. //this.initWhereEntryData();
  384. debugger;
  385. var values = [];
  386. ids.each(function(id){
  387. values.push({"name": id.data.name, "id": id.data.id});
  388. }.bind(this));
  389. var name = node.get("name");
  390. key = name.split(".");
  391. var o = this.data;
  392. var len = key.length-1;
  393. key.each(function(n, i){
  394. if (!o[n]) o[n] = {};
  395. if (i<len) o = o[n];
  396. }.bind(this));
  397. o[key[len]] = values;
  398. //this.data.data.restrictWhereEntry[node.get("name")] = values;
  399. },
  400. loadViewSelect: function(){
  401. var viewNodes = this.propertyContent.getElements(".MWFViewSelect");
  402. if (viewNodes.length){
  403. this.getViewList(function(){
  404. viewNodes.each(function(node){
  405. var select = new Element("select").inject(node);
  406. select.addEvent("change", function(e){
  407. var viewId = e.target.options[e.target.selectedIndex].value;
  408. var viewName = e.target.options[e.target.selectedIndex].get("text");
  409. this.setValue(e.target.getParent("div").get("name"), viewId);
  410. this.setValue(e.target.getParent("div").get("name")+"Name", viewName);
  411. }.bind(this));
  412. this.setViewSelectOptions(node, select);
  413. var refreshNode = new Element("div", {"styles": this.view.css.propertyRefreshFormNode}).inject(node);
  414. refreshNode.addEvent("click", function(e){
  415. this.getViewList(function(){
  416. this.setViewSelectOptions(node, select);
  417. }.bind(this), true);
  418. }.bind(this));
  419. //select.addEvent("click", function(e){
  420. // this.setFormSelectOptions(node, select);
  421. //}.bind(this));
  422. }.bind(this));
  423. }.bind(this));
  424. }
  425. },
  426. setViewSelectOptions: function(node, select){
  427. var name = node.get("name");
  428. select.empty();
  429. var option = new Element("option", {"text": "(none)"}).inject(select);
  430. this.views.each(function(view){
  431. var option = new Element("option", {
  432. "text": view.name,
  433. "value": view.id,
  434. "selected": (this.data[name]==view.id)
  435. }).inject(select);
  436. }.bind(this));
  437. },
  438. getViewList: function(callback, refresh){
  439. if (!this.views || refresh){
  440. this.view.designer.actions.listView(this.view.designer.application.id, function(json){
  441. this.views = json.data;
  442. if (callback) callback();
  443. }.bind(this));
  444. }else{
  445. if (callback) callback();
  446. }
  447. },
  448. loadScriptArea: function(){
  449. debugger;
  450. var scriptAreas = this.propertyContent.getElements(".MWFScriptArea");
  451. var formulaAreas = this.propertyContent.getElements(".MWFFormulaArea");
  452. this.loadScriptEditor(scriptAreas);
  453. this.loadScriptEditor(formulaAreas, "formula");
  454. },
  455. loadScriptEditor: function(scriptAreas, style){
  456. scriptAreas.each(function(node){
  457. var title = node.get("title");
  458. var name = node.get("name");
  459. var scriptContent = this.data[name];
  460. MWF.require("MWF.widget.ScriptArea", function(){
  461. var scriptArea = new MWF.widget.ScriptArea(node, {
  462. "title": title,
  463. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  464. "maxObj": this.designer.editContentNode,
  465. "onChange": function(){
  466. this.data[name] = scriptArea.toJson().code;
  467. }.bind(this),
  468. "onSave": function(){
  469. this.designer.saveView();
  470. }.bind(this),
  471. "style": style || "default"
  472. });
  473. scriptArea.load({"code": scriptContent});
  474. }.bind(this));
  475. }.bind(this));
  476. }
  477. });