Property.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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.loadViewSelect();
  52. this.loadJSONArea();
  53. this.view.changeViewSelected()
  54. }
  55. }.bind(this));
  56. }else{
  57. this.propertyContent.setStyle("display", "block");
  58. }
  59. },
  60. hide: function(){
  61. //this.JsonTemplate = null;
  62. //this.propertyNode.set("html", "");
  63. if (this.propertyContent) this.propertyContent.setStyle("display", "none");
  64. },
  65. loadJSONArea: function(){
  66. var jsonNode = this.propertyContent.getElement(".MWFJSONArea");
  67. if (jsonNode){
  68. this.propertyTab.pages.each(function(page){
  69. if (page.contentNode == jsonNode.parentElement){
  70. page.setOptions({
  71. "onShow": function(){
  72. jsonNode.empty();
  73. MWF.require("MWF.widget.JsonParse", function(){
  74. this.json = new MWF.widget.JsonParse(this.module.json, jsonNode, null);
  75. this.json.load();
  76. }.bind(this));
  77. }.bind(this)
  78. });
  79. }
  80. }.bind(this));
  81. }
  82. },
  83. loadPropertyTab: function(){
  84. var tabNodes = this.propertyContent.getElements(".MWFTab");
  85. if (tabNodes.length){
  86. var tmpNode = this.propertyContent.getFirst();
  87. var tabAreaNode = new Element("div", {
  88. "styles": this.view.css.propertyTabNode
  89. }).inject(tmpNode, "before");
  90. MWF.require("MWF.widget.Tab", function(){
  91. var tab = new MWF.widget.Tab(tabAreaNode, {"style": "formPropertyList"});
  92. tab.load();
  93. var tabPages = [];
  94. tabNodes.each(function(node){
  95. var page = tab.addTab(node, node.get("title"), false);
  96. tabPages.push(page);
  97. this.setScrollBar(page.contentNodeArea, "small", null, null);
  98. }.bind(this));
  99. tabPages[0].showTab();
  100. this.propertyTab = tab;
  101. this.designer.resizeNode();
  102. }.bind(this), false);
  103. }
  104. },
  105. setEditNodeEvent: function(){
  106. var property = this;
  107. // var inputs = this.process.propertyListNode.getElements(".editTableInput");
  108. var inputs = this.propertyContent.getElements("input");
  109. inputs.each(function(input){
  110. var jsondata = input.get("name");
  111. if (jsondata && jsondata.substr(0,1)!="_"){
  112. if (this.module){
  113. var id = this.module.json.id;
  114. input.set("name", id+jsondata);
  115. }
  116. if (jsondata){
  117. var inputType = input.get("type").toLowerCase();
  118. switch (inputType){
  119. case "radio":
  120. input.addEvent("change", function(e){
  121. property.setRadioValue(jsondata, this);
  122. });
  123. //input.addEvent("blur", function(e){
  124. // property.setRadioValue(jsondata, this);
  125. //});
  126. input.addEvent("keydown", function(e){
  127. e.stopPropagation();
  128. });
  129. property.setRadioValue(jsondata, input);
  130. break;
  131. case "checkbox":
  132. input.addEvent("change", function(e){
  133. property.setCheckboxValue(jsondata, this);
  134. });
  135. input.addEvent("click", function(e){
  136. property.setCheckboxValue(jsondata, this);
  137. });
  138. input.addEvent("keydown", function(e){
  139. e.stopPropagation();
  140. });
  141. break;
  142. default:
  143. input.addEvent("change", function(e){
  144. property.setValue(jsondata, this.value, this);
  145. });
  146. input.addEvent("blur", function(e){
  147. property.setValue(jsondata, this.value, this);
  148. });
  149. input.addEvent("keydown", function(e){
  150. if (e.code==13){
  151. property.setValue(jsondata, this.value, this);
  152. }
  153. e.stopPropagation();
  154. });
  155. if (input.hasClass("editTableInputDate")){
  156. this.loadCalendar(input);
  157. }
  158. }
  159. }
  160. }
  161. }.bind(this));
  162. var selects = this.propertyContent.getElements("select");
  163. selects.each(function(select){
  164. var jsondata = select.get("name");
  165. if (jsondata){
  166. select.addEvent("change", function(e){
  167. property.setSelectValue(jsondata, this);
  168. });
  169. }
  170. });
  171. var textareas = this.propertyContent.getElements("textarea");
  172. textareas.each(function(input){
  173. var jsondata = input.get("name");
  174. if (jsondata){
  175. input.addEvent("change", function(e){
  176. property.setValue(jsondata, this.value);
  177. });
  178. input.addEvent("blur", function(e){
  179. property.setValue(jsondata, this.value);
  180. });
  181. input.addEvent("keydown", function(e){
  182. e.stopPropagation();
  183. });
  184. }
  185. }.bind(this));
  186. },
  187. loadCalendar: function(node){
  188. MWF.require("MWF.widget.Calendar", function(){
  189. this.calendar = new MWF.widget.Calendar(node, {
  190. "style": "xform",
  191. "isTime": false,
  192. "target": this.module.designer.content,
  193. "format": "%Y-%m-%d",
  194. "onComplate": function(){
  195. //this.validationMode();
  196. //this.validation();
  197. //this.fireEvent("complete");
  198. }.bind(this)
  199. });
  200. //this.calendar.show();
  201. }.bind(this));
  202. },
  203. changeStyle: function(name){
  204. this.module.setPropertiesOrStyles(name);
  205. },
  206. changeData: function(name, input, oldValue){
  207. this.module._setEditStyle(name, input, oldValue);
  208. },
  209. changeJsonDate: function(key, value){
  210. if (typeOf(key)!="array") key = [key];
  211. var o = this.data;
  212. var len = key.length-1;
  213. key.each(function(n, i){
  214. if (!o[n]) o[n] = {};
  215. if (i<len) o = o[n];
  216. }.bind(this));
  217. o[key[len]] = value;
  218. },
  219. setRadioValue: function(name, input){
  220. debugger;
  221. if (input.checked){
  222. var i = name.indexOf("*");
  223. var names = (i==-1) ? name.split(".") : name.substr(i+1, name.length).split(".");
  224. var value = input.value;
  225. if (value=="false") value = false;
  226. if (value=="true") value = true;
  227. var oldValue = this.data;
  228. for (var idx = 0; idx<names.length; idx++){
  229. if (!oldValue[names[idx]]){
  230. oldValue = null;
  231. break;
  232. }else{
  233. oldValue = oldValue[names[idx]];
  234. }
  235. }
  236. //var oldValue = this.data[name];
  237. this.changeJsonDate(names, value);
  238. this.changeData(name, input, oldValue);
  239. }
  240. },
  241. setCheckboxValue: function(name, input){
  242. var checkboxList = $$("input:[name='"+name+"']");
  243. var values = [];
  244. checkboxList.each(function(checkbox){
  245. if (checkbox.get("checked")){
  246. values.push(checkbox.value);
  247. }
  248. });
  249. var oldValue = this.data[name];
  250. //this.data[name] = values;
  251. this.changeJsonDate(name, values);
  252. this.changeData(name, input, oldValue);
  253. },
  254. setSelectValue: function(name, select){
  255. var idx = select.selectedIndex;
  256. var options = select.getElements("option");
  257. var value = "";
  258. if (options[idx]){
  259. value = options[idx].get("value");
  260. }
  261. var oldValue = this.data[name];
  262. //this.data[name] = value;
  263. this.changeJsonDate(name, value);
  264. this.changeData(name, select, oldValue);
  265. },
  266. setValue: function(name, value, obj){
  267. var names = name.split(".");
  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, obj, oldValue);
  281. },
  282. setEditNodeStyles: function(node){
  283. var nodes = node.getChildren();
  284. if (nodes.length){
  285. nodes.each(function(el){
  286. var cName = el.get("class");
  287. if (cName){
  288. if (this.view.css[cName]) el.setStyles(this.view.css[cName]);
  289. }
  290. this.setEditNodeStyles(el);
  291. }.bind(this));
  292. }
  293. },
  294. loadPersonInput: function(){
  295. var applicationNodes = this.propertyContent.getElements(".MWFSelectApplication");
  296. var processNodes = this.propertyContent.getElements(".MWFSelectProcess");
  297. var companyNodes = this.propertyContent.getElements(".MWFSelectCompany");
  298. var departmentNodes = this.propertyContent.getElements(".MWFSelectDepartment");
  299. var personNodes = this.propertyContent.getElements(".MWFSelectPerson");
  300. var identityNodes = this.propertyContent.getElements(".MWFSelectIdentity");
  301. MWF.xDesktop.requireApp("process.StatDesigner", "widget.PersonSelector", function(){
  302. applicationNodes.each(function(node){
  303. new MWF.xApplication.process.StatDesigner.widget.PersonSelector(node, this.view.designer, {
  304. "type": "application",
  305. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry[node.get("name")] : [],
  306. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  307. });
  308. }.bind(this));
  309. processNodes.each(function(node){
  310. new MWF.xApplication.process.StatDesigner.widget.PersonSelector(node, this.view.designer, {
  311. "type": "process",
  312. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry[node.get("name")] : [],
  313. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  314. });
  315. }.bind(this));
  316. companyNodes.each(function(node){
  317. new MWF.xApplication.process.StatDesigner.widget.PersonSelector(node, this.view.designer, {
  318. "type": "company",
  319. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry[node.get("name")] : [],
  320. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  321. });
  322. }.bind(this));
  323. departmentNodes.each(function(node){
  324. new MWF.xApplication.process.StatDesigner.widget.PersonSelector(node, this.view.designer, {
  325. "type": "department",
  326. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry[node.get("name")] : [],
  327. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  328. });
  329. }.bind(this));
  330. personNodes.each(function(node){
  331. new MWF.xApplication.process.StatDesigner.widget.PersonSelector(node, this.view.designer, {
  332. "type": "person",
  333. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry[node.get("name")] : [],
  334. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  335. });
  336. }.bind(this));
  337. identityNodes.each(function(node){
  338. new MWF.xApplication.process.StatDesigner.widget.PersonSelector(node, this.view.designer, {
  339. "type": "identity",
  340. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry[node.get("name")] : [],
  341. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  342. });
  343. }.bind(this));
  344. }.bind(this));
  345. },
  346. savePersonItem: function(node, ids){
  347. //this.initWhereEntryData();
  348. debugger;
  349. var values = [];
  350. ids.each(function(id){
  351. values.push({"name": id.data.name, "id": id.data.id});
  352. }.bind(this));
  353. var name = node.get("name");
  354. key = name.split(".");
  355. var o = this.data;
  356. var len = key.length-1;
  357. key.each(function(n, i){
  358. if (!o[n]) o[n] = {};
  359. if (i<len) o = o[n];
  360. }.bind(this));
  361. o[key[len]] = values;
  362. //this.data.data.restrictWhereEntry[node.get("name")] = values;
  363. },
  364. loadViewSelect: function(){
  365. var viewNodes = this.propertyContent.getElements(".MWFViewSelect");
  366. if (viewNodes.length){
  367. this.getViewList(function(){
  368. viewNodes.each(function(node){
  369. var select = new Element("select").inject(node);
  370. select.addEvent("change", function(e){
  371. var viewId = e.target.options[e.target.selectedIndex].value;
  372. var viewName = e.target.options[e.target.selectedIndex].get("text");
  373. this.setValue(e.target.getParent("div").get("name"), viewId);
  374. this.setValue(e.target.getParent("div").get("name")+"Name", viewName);
  375. }.bind(this));
  376. this.setViewSelectOptions(node, select);
  377. var refreshNode = new Element("div", {"styles": this.view.css.propertyRefreshFormNode}).inject(node);
  378. refreshNode.addEvent("click", function(e){
  379. this.getViewList(function(){
  380. this.setViewSelectOptions(node, select);
  381. }.bind(this), true);
  382. }.bind(this));
  383. //select.addEvent("click", function(e){
  384. // this.setFormSelectOptions(node, select);
  385. //}.bind(this));
  386. }.bind(this));
  387. }.bind(this));
  388. }
  389. },
  390. setViewSelectOptions: function(node, select){
  391. var name = node.get("name");
  392. select.empty();
  393. var option = new Element("option", {"text": "(none)"}).inject(select);
  394. this.views.each(function(view){
  395. var option = new Element("option", {
  396. "text": view.name,
  397. "value": view.id,
  398. "selected": (this.data[name]==view.id)
  399. }).inject(select);
  400. }.bind(this));
  401. },
  402. getViewList: function(callback, refresh){
  403. if (!this.views || refresh){
  404. this.view.designer.actions.listView(this.view.designer.application.id, function(json){
  405. this.views = json.data;
  406. if (callback) callback();
  407. }.bind(this));
  408. }else{
  409. if (callback) callback();
  410. }
  411. }
  412. });