Property.js 20 KB

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