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 id = this.module.json.id;
  243. var checkboxList = $$("input[name='"+id+name+"']");
  244. var values = [];
  245. checkboxList.each(function(checkbox){
  246. if (checkbox.get("checked")){
  247. values.push(checkbox.value);
  248. }
  249. });
  250. var oldValue = this.data[name];
  251. //this.data[name] = values;
  252. this.changeJsonDate(name, values);
  253. this.changeData(name, input, oldValue);
  254. },
  255. setSelectValue: function(name, select){
  256. var idx = select.selectedIndex;
  257. var options = select.getElements("option");
  258. var value = "";
  259. if (options[idx]){
  260. value = options[idx].get("value");
  261. }
  262. var oldValue = this.data[name];
  263. //this.data[name] = value;
  264. this.changeJsonDate(name, value);
  265. this.changeData(name, select, oldValue);
  266. },
  267. setValue: function(name, value, obj){
  268. var names = name.split(".");
  269. var oldValue = this.data;
  270. for (var idx = 0; idx<names.length; idx++){
  271. if (!oldValue[names[idx]]){
  272. oldValue = null;
  273. break;
  274. }else{
  275. oldValue = oldValue[names[idx]];
  276. }
  277. }
  278. //var oldValue = this.data[name];
  279. //this.data[name] = value;
  280. this.changeJsonDate(names, value);
  281. this.changeData(name, obj, oldValue);
  282. },
  283. setEditNodeStyles: function(node){
  284. var nodes = node.getChildren();
  285. if (nodes.length){
  286. nodes.each(function(el){
  287. var cName = el.get("class");
  288. if (cName){
  289. if (this.view.css[cName]) el.setStyles(this.view.css[cName]);
  290. }
  291. this.setEditNodeStyles(el);
  292. }.bind(this));
  293. }
  294. },
  295. loadPersonInput: function(){
  296. var applicationNodes = this.propertyContent.getElements(".MWFSelectApplication");
  297. var processNodes = this.propertyContent.getElements(".MWFSelectProcess");
  298. var companyNodes = this.propertyContent.getElements(".MWFSelectCompany");
  299. var departmentNodes = this.propertyContent.getElements(".MWFSelectDepartment");
  300. var personNodes = this.propertyContent.getElements(".MWFSelectPerson");
  301. var identityNodes = this.propertyContent.getElements(".MWFSelectIdentity");
  302. MWF.xDesktop.requireApp("process.StatDesigner", "widget.PersonSelector", function(){
  303. applicationNodes.each(function(node){
  304. new MWF.xApplication.process.StatDesigner.widget.PersonSelector(node, this.view.designer, {
  305. "type": "application",
  306. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry[node.get("name")] : [],
  307. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  308. });
  309. }.bind(this));
  310. processNodes.each(function(node){
  311. new MWF.xApplication.process.StatDesigner.widget.PersonSelector(node, this.view.designer, {
  312. "type": "process",
  313. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry[node.get("name")] : [],
  314. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  315. });
  316. }.bind(this));
  317. companyNodes.each(function(node){
  318. new MWF.xApplication.process.StatDesigner.widget.PersonSelector(node, this.view.designer, {
  319. "type": "company",
  320. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry[node.get("name")] : [],
  321. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  322. });
  323. }.bind(this));
  324. departmentNodes.each(function(node){
  325. new MWF.xApplication.process.StatDesigner.widget.PersonSelector(node, this.view.designer, {
  326. "type": "department",
  327. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry[node.get("name")] : [],
  328. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  329. });
  330. }.bind(this));
  331. personNodes.each(function(node){
  332. new MWF.xApplication.process.StatDesigner.widget.PersonSelector(node, this.view.designer, {
  333. "type": "person",
  334. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry[node.get("name")] : [],
  335. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  336. });
  337. }.bind(this));
  338. identityNodes.each(function(node){
  339. new MWF.xApplication.process.StatDesigner.widget.PersonSelector(node, this.view.designer, {
  340. "type": "identity",
  341. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry[node.get("name")] : [],
  342. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  343. });
  344. }.bind(this));
  345. }.bind(this));
  346. },
  347. savePersonItem: function(node, ids){
  348. //this.initWhereEntryData();
  349. debugger;
  350. var values = [];
  351. ids.each(function(id){
  352. values.push({"name": id.data.name, "id": id.data.id});
  353. }.bind(this));
  354. var name = node.get("name");
  355. key = name.split(".");
  356. var o = this.data;
  357. var len = key.length-1;
  358. key.each(function(n, i){
  359. if (!o[n]) o[n] = {};
  360. if (i<len) o = o[n];
  361. }.bind(this));
  362. o[key[len]] = values;
  363. //this.data.data.restrictWhereEntry[node.get("name")] = values;
  364. },
  365. loadViewSelect: function(){
  366. var viewNodes = this.propertyContent.getElements(".MWFViewSelect");
  367. if (viewNodes.length){
  368. this.getViewList(function(){
  369. viewNodes.each(function(node){
  370. var select = new Element("select").inject(node);
  371. select.addEvent("change", function(e){
  372. var viewId = e.target.options[e.target.selectedIndex].value;
  373. var viewName = e.target.options[e.target.selectedIndex].get("text");
  374. this.setValue(e.target.getParent("div").get("name"), viewId);
  375. this.setValue(e.target.getParent("div").get("name")+"Name", viewName);
  376. }.bind(this));
  377. this.setViewSelectOptions(node, select);
  378. var refreshNode = new Element("div", {"styles": this.view.css.propertyRefreshFormNode}).inject(node);
  379. refreshNode.addEvent("click", function(e){
  380. this.getViewList(function(){
  381. this.setViewSelectOptions(node, select);
  382. }.bind(this), true);
  383. }.bind(this));
  384. //select.addEvent("click", function(e){
  385. // this.setFormSelectOptions(node, select);
  386. //}.bind(this));
  387. }.bind(this));
  388. }.bind(this));
  389. }
  390. },
  391. setViewSelectOptions: function(node, select){
  392. var name = node.get("name");
  393. select.empty();
  394. var option = new Element("option", {"text": "(none)"}).inject(select);
  395. this.views.each(function(view){
  396. var option = new Element("option", {
  397. "text": view.name,
  398. "value": view.id,
  399. "selected": (this.data[name]==view.id)
  400. }).inject(select);
  401. }.bind(this));
  402. },
  403. getViewList: function(callback, refresh){
  404. if (!this.views || refresh){
  405. this.view.designer.actions.listView(this.view.designer.application.id, function(json){
  406. this.views = json.data;
  407. if (callback) callback();
  408. }.bind(this));
  409. }else{
  410. if (callback) callback();
  411. }
  412. }
  413. });