Property.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. MWF.require("MWF.widget.Common", null, false);
  2. MWF.xApplication.cms.FormDesigner.Property = MWF.CMSFCProperty = new Class({
  3. Extends: MWF.widget.Common,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "path": "/x_component_cms_FormDesigner/property/property.html"
  8. },
  9. initialize: function(module, propertyNode, designer, options){
  10. this.setOptions(options);
  11. this.module = module;
  12. this.form = module.form;
  13. this.data = module.json;
  14. this.htmlPath = this.options.path;
  15. this.designer = designer;
  16. this.propertyNode = propertyNode;
  17. },
  18. load: function(){
  19. if (this.fireEvent("queryLoad")){
  20. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  21. this.htmlString = responseText;
  22. MWF.require("MWF.widget.JsonTemplate", function(){
  23. this.fireEvent("postLoad");
  24. }.bind(this));
  25. }.bind(this));
  26. }
  27. this.propertyNode.addEvent("keydown", function(e){e.stopPropagation();});
  28. },
  29. editProperty: function(td){
  30. },
  31. show: function(){
  32. if (!this.propertyContent){
  33. if (this.htmlString){
  34. this.JsonTemplate = new MWF.widget.JsonTemplate(this.data, this.htmlString);
  35. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyNode);
  36. this.propertyContent.set("html", this.JsonTemplate.load());
  37. this.setEditNodeEvent();
  38. this.setEditNodeStyles(this.propertyContent);
  39. this.loadPropertyTab();
  40. this.loadMaplist();
  41. this.loadScriptArea();
  42. this.loadHtmlEditorArea();
  43. this.loadTreeData();
  44. this.loadArrayList();
  45. this.loadEventsEditor();
  46. this.loadQueryViewSelect();
  47. this.loadActionArea();
  48. this.loadHTMLArea();
  49. this.loadJSONArea();
  50. // this.loadScriptInput();
  51. //MWF.cms.widget.EventsEditor
  52. }
  53. }else{
  54. this.propertyContent.setStyle("display", "block");
  55. }
  56. },
  57. hide: function(){
  58. //this.JsonTemplate = null;
  59. //this.propertyNode.set("html", "");
  60. if (this.propertyContent) this.propertyContent.setStyle("display", "none");
  61. },
  62. loadTreeData: function(){
  63. var arrays = this.propertyContent.getElements(".MWFTreeData");
  64. arrays.each(function(node){
  65. var title = node.get("title");
  66. var name = node.get("name");
  67. var json = this.data[name];
  68. if (!json) json = [];
  69. MWF.require("MWF.widget.TreeEditor", function(){
  70. var treeEditor = new MWF.widget.TreeEditor(node, {
  71. "title": title,
  72. "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  73. "onChange": function(){
  74. this.data[name] = treeEditor.toJson();
  75. this.module.json[name] = this.data[name];
  76. this.module._refreshTree();
  77. }.bind(this)
  78. });
  79. treeEditor.load(json);
  80. }.bind(this));
  81. node.addEvent("keydown", function(e){e.stopPropagation();});
  82. }.bind(this));
  83. },
  84. loadJSONArea: function(){
  85. var jsonNode = this.propertyContent.getElement(".MWFJSONArea");
  86. // MWF.require("MWF.widget.JsonParse", function(){
  87. // this.json = new MWF.widget.JsonParse(this.module.json, jsonNode, null);
  88. // this.objectTree.load();
  89. // }.bind(this));
  90. if (jsonNode){
  91. this.propertyTab.pages.each(function(page){
  92. if (page.contentNode == jsonNode.parentElement){
  93. page.setOptions({
  94. "onShow": function(){
  95. MWF.require("MWF.widget.JsonParse", function(){
  96. this.json = new MWF.widget.JsonParse(this.module.json, jsonNode, null);
  97. this.json.load();
  98. }.bind(this));
  99. }.bind(this)
  100. });
  101. }
  102. }.bind(this));
  103. }
  104. },
  105. loadHTMLArea: function(){
  106. var htmlNode = this.propertyContent.getElement(".MWFHTMLArea");
  107. if (htmlNode){
  108. var copy = this.module.node.clone(true, true);
  109. copy.clearStyles(true);
  110. htmlNode.set("text", copy.outerHTML);
  111. copy.destroy();
  112. this.propertyTab.pages.each(function(page){
  113. if (page.contentNode == htmlNode.parentElement){
  114. page.setOptions({
  115. "onShow": function(){
  116. var copy = this.module.node.clone(true, true);
  117. copy.clearStyles(true);
  118. htmlNode.set("text", copy.outerHTML);
  119. copy.destroy();
  120. }.bind(this)
  121. });
  122. }
  123. }.bind(this));
  124. }
  125. },
  126. loadQueryViewSelect: function(){
  127. var queryViewNodes = this.propertyContent.getElements(".MWFQueryViewSelect");
  128. if (queryViewNodes.length){
  129. this.getQueryViewList(function(){
  130. queryViewNodes.each(function(node){
  131. var select = new Element("select").inject(node);
  132. select.addEvent("change", function(e){
  133. var queryviewId = e.target.options[e.target.selectedIndex].value;
  134. var queryviewName = e.target.options[e.target.selectedIndex].get("text");
  135. this.setValue(e.target.getParent("div").get("name"), queryviewId);
  136. this.setValue(e.target.getParent("div").get("name")+"Name", queryviewName);
  137. }.bind(this));
  138. this.setQueryViewSelectOptions(node, select);
  139. var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  140. refreshNode.addEvent("click", function(e){
  141. this.getQueryViewList(function(){
  142. this.setQueryViewSelectOptions(node, select);
  143. }.bind(this), true);
  144. }.bind(this));
  145. //select.addEvent("click", function(e){
  146. // this.setFormSelectOptions(node, select);
  147. //}.bind(this));
  148. }.bind(this));
  149. }.bind(this));
  150. }
  151. },
  152. setQueryViewSelectOptions: function(node, select){
  153. var name = node.get("name");
  154. select.empty();
  155. var option = new Element("option", {"text": "none"}).inject(select);
  156. this.queryviews.each(function(queryview){
  157. var option = new Element("option", {
  158. "text": queryview.name,
  159. "value": queryview.id,
  160. "selected": (this.data[name]==queryview.id)
  161. }).inject(select);
  162. }.bind(this));
  163. },
  164. getQueryViewList: function(callback, refresh){
  165. if (!this.queryviews || refresh){
  166. this.form.designer.actions.listQueryView(this.form.designer.application.id, function(json){
  167. this.queryviews = json.data;
  168. if (callback) callback();
  169. }.bind(this));
  170. }else{
  171. if (callback) callback();
  172. }
  173. },
  174. // clearStyles: function(node){
  175. // node.removeProperty("style");
  176. // var subNode = node.getFirst();
  177. // while (subNode){
  178. // this.clearStyles(subNode);
  179. // subNode = subNode.getNext();
  180. // }
  181. // },
  182. loadEventsEditor: function(){
  183. var events = this.propertyContent.getElement(".MWFEventsArea");
  184. if (events){
  185. var name = events.get("name");
  186. var eventsObj = this.data[name];
  187. MWF.xDesktop.requireApp("cms.FormDesigner", "widget.EventsEditor", function(){
  188. var eventsEditor = new MWF.xApplication.cms.FormDesigner.widget.EventsEditor(events, this.designer, {
  189. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  190. "maxObj": this.designer.formContentNode
  191. });
  192. eventsEditor.load(eventsObj);
  193. }.bind(this));
  194. }
  195. },
  196. loadArrayList: function(){
  197. var arrays = this.propertyContent.getElements(".MWFArraylist");
  198. arrays.each(function(node){
  199. var title = node.get("title");
  200. var name = node.get("name");
  201. var arr = this.data[name];
  202. if (!arr) arr = [];
  203. MWF.require("MWF.widget.Arraylist", function(){
  204. var arraylist = new MWF.widget.Arraylist(node, {
  205. "title": title,
  206. "onChange": function(){
  207. this.data[name] = arraylist.toArray();
  208. }.bind(this)
  209. });
  210. arraylist.load(arr);
  211. }.bind(this));
  212. node.addEvent("keydown", function(e){e.stopPropagation();});
  213. }.bind(this));
  214. },
  215. loadHtmlEditorArea: function(){
  216. var htmlAreas = this.propertyContent.getElements(".MWFHtmlEditorArea");
  217. htmlAreas.each(function(node){
  218. var title = node.get("title");
  219. var name = node.get("name");
  220. var scriptContent = this.data[name];
  221. MWF.require("MWF.widget.HtmlEditorArea", function(){
  222. var htmlArea = new MWF.widget.HtmlEditorArea(node, {
  223. "title": title,
  224. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  225. "maxObj": this.designer.formContentNode,
  226. "onChange": function(){
  227. this.data[name] = htmlArea.getValue();
  228. this.changeData(name);
  229. }.bind(this),
  230. "onSave": function(){
  231. this.designer.saveForm();
  232. }.bind(this)
  233. });
  234. htmlArea.load({"code": scriptContent});
  235. }.bind(this));
  236. }.bind(this));
  237. },
  238. loadScriptArea: function(){
  239. var scriptAreas = this.propertyContent.getElements(".MWFScriptArea");
  240. var formulaAreas = this.propertyContent.getElements(".MWFFormulaArea");
  241. this.loadScriptEditor(scriptAreas);
  242. this.loadScriptEditor(formulaAreas, "formula");
  243. },
  244. loadScriptEditor: function(scriptAreas, style){
  245. scriptAreas.each(function(node){
  246. var title = node.get("title");
  247. var name = node.get("name");
  248. var scriptContent = this.data[name];
  249. MWF.require("MWF.widget.ScriptArea", function(){
  250. var scriptArea = new MWF.widget.ScriptArea(node, {
  251. "title": title,
  252. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  253. "maxObj": this.designer.formContentNode,
  254. "onChange": function(){
  255. this.data[name] = scriptArea.toJson();
  256. }.bind(this),
  257. "onSave": function(){
  258. this.designer.saveForm();
  259. }.bind(this),
  260. "style": style || "default",
  261. "helpStyle" : "cms"
  262. });
  263. scriptArea.load(scriptContent);
  264. }.bind(this));
  265. }.bind(this));
  266. },
  267. loadActionArea: function(){
  268. var actionAreas = this.propertyContent.getElements(".MWFActionArea");
  269. actionAreas.each(function(node){
  270. var name = node.get("name");
  271. var actionContent = this.data[name];
  272. MWF.xDesktop.requireApp("cms.FormDesigner", "widget.ActionsEditor", function(){
  273. var actionEditor = new MWF.xApplication.cms.FormDesigner.widget.ActionsEditor(node, this.designer, {
  274. "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  275. "onChange": function(){
  276. this.data[name] = actionEditor.data;
  277. }.bind(this)
  278. });
  279. actionEditor.load(actionContent);
  280. }.bind(this));
  281. }.bind(this));
  282. },
  283. loadMaplist: function(){
  284. var maplists = this.propertyContent.getElements(".MWFMaplist");
  285. maplists.each(function(node){
  286. var title = node.get("title");
  287. var name = node.get("name");
  288. var collapse = node.get("collapse");
  289. var mapObj = this.data[name];
  290. if (!mapObj) mapObj = {};
  291. MWF.require("MWF.widget.Maplist", function(){
  292. var maplist = new MWF.widget.Maplist(node, {
  293. "title": title,
  294. "collapse": (collapse) ? true : false,
  295. "onChange": function(){
  296. //this.data[name] = maplist.toJson();
  297. //
  298. this.changeJsonDate(name, maplist.toJson());
  299. this.changeStyle(name);
  300. this.changeData(name);
  301. }.bind(this)
  302. });
  303. maplist.load(mapObj);
  304. }.bind(this));
  305. }.bind(this));
  306. },
  307. loadPropertyTab: function(){
  308. var tabNodes = this.propertyContent.getElements(".MWFTab");
  309. if (tabNodes.length){
  310. var tmpNode = this.propertyContent.getFirst();
  311. var tabAreaNode = new Element("div", {
  312. "styles": this.form.css.propertyTabNode
  313. }).inject(tmpNode, "before");
  314. MWF.require("MWF.widget.Tab", function(){
  315. var tab = new MWF.widget.Tab(tabAreaNode, {"style": "formPropertyList"});
  316. tab.load();
  317. var tabPages = [];
  318. tabNodes.each(function(node){
  319. var page = tab.addTab(node, node.get("title"), false);
  320. tabPages.push(page);
  321. this.setScrollBar(page.contentNodeArea, "small", null, null);
  322. }.bind(this));
  323. tabPages[0].showTab();
  324. this.propertyTab = tab;
  325. this.designer.resizeNode();
  326. }.bind(this), false);
  327. }
  328. },
  329. setEditNodeEvent: function(){
  330. var property = this;
  331. // var inputs = this.cms.propertyListNode.getElements(".editTableInput");
  332. var inputs = this.propertyContent.getElements("input");
  333. inputs.each(function(input){
  334. var jsondata = input.get("name");
  335. if (this.module){
  336. var id = this.module.json.id;
  337. input.set("name", id+jsondata);
  338. }
  339. if (jsondata){
  340. var inputType = input.get("type").toLowerCase();
  341. switch (inputType){
  342. case "radio":
  343. input.addEvent("change", function(e){
  344. property.setRadioValue(jsondata, this);
  345. });
  346. input.addEvent("blur", function(e){
  347. property.setRadioValue(jsondata, this);
  348. });
  349. input.addEvent("keydown", function(e){
  350. e.stopPropagation();
  351. });
  352. break;
  353. case "checkbox":
  354. input.addEvent("change", function(e){
  355. property.setCheckboxValue(jsondata, this);
  356. });
  357. input.addEvent("click", function(e){
  358. property.setCheckboxValue(jsondata, this);
  359. });
  360. input.addEvent("keydown", function(e){
  361. e.stopPropagation();
  362. });
  363. break;
  364. default:
  365. input.addEvent("change", function(e){
  366. property.setValue(jsondata, this.value, this);
  367. });
  368. input.addEvent("blur", function(e){
  369. property.setValue(jsondata, this.value, this);
  370. });
  371. input.addEvent("keydown", function(e){
  372. if (e.code==13){
  373. property.setValue(jsondata, this.value, this);
  374. }
  375. e.stopPropagation();
  376. });
  377. }
  378. }
  379. }.bind(this));
  380. var selects = this.propertyContent.getElements("select");
  381. selects.each(function(select){
  382. var jsondata = select.get("name");
  383. if (jsondata){
  384. select.addEvent("change", function(e){
  385. property.setSelectValue(jsondata, this);
  386. });
  387. }
  388. });
  389. var textareas = this.propertyContent.getElements("textarea");
  390. textareas.each(function(input){
  391. var jsondata = input.get("name");
  392. if (jsondata){
  393. input.addEvent("change", function(e){
  394. property.setValue(jsondata, this.value);
  395. });
  396. input.addEvent("blur", function(e){
  397. property.setValue(jsondata, this.value);
  398. });
  399. input.addEvent("keydown", function(e){
  400. e.stopPropagation();
  401. });
  402. }
  403. }.bind(this));
  404. },
  405. changeStyle: function(name){
  406. this.module.setPropertiesOrStyles(name);
  407. },
  408. changeData: function(name, input, oldValue){
  409. this.module._setEditStyle(name, input, oldValue);
  410. },
  411. changeJsonDate: function(key, value){
  412. this.data[key] = value;
  413. },
  414. setRadioValue: function(name, input){
  415. if (input.checked){
  416. var value = input.value;
  417. if (value=="false") value = false;
  418. if (value=="true") value = true;
  419. var oldValue = this.data[name];
  420. this.changeJsonDate(name, value);
  421. this.changeData(name, input, oldValue);
  422. }
  423. },
  424. setCheckboxValue: function(name, input){
  425. var checkboxList = $$("input:[name='"+name+"']");
  426. var values = [];
  427. checkboxList.each(function(checkbox){
  428. if (checkbox.get("checked")){
  429. values.push(checkbox.value);
  430. }
  431. });
  432. var oldValue = this.data[name];
  433. //this.data[name] = values;
  434. this.changeJsonDate(name, values);
  435. this.changeData(name, input, oldValue);
  436. },
  437. setSelectValue: function(name, select){
  438. var idx = select.selectedIndex;
  439. var options = select.getElements("option");
  440. var value = "";
  441. if (options[idx]){
  442. value = options[idx].get("value");
  443. }
  444. var oldValue = this.data[name];
  445. //this.data[name] = value;
  446. this.changeJsonDate(name, value);
  447. this.changeData(name, select, oldValue);
  448. },
  449. setValue: function(name, value, obj){
  450. if (name=="id"){
  451. if (value!=this.module.json.id){
  452. if (!value){
  453. this.designer.notice(MWF.CMSFD.LP.notNullId, "error", this.module.form.designer.propertyContentArea, {x:"right", y:"bottom"});
  454. obj.focus();
  455. return false;
  456. }else if (this.module.form.json.moduleList[value]){
  457. this.designer.notice("error", MWF.CMSFD.LP.repetitionsId, this.module.form.designer.propertyContentArea, {x:"right", y:"bottom"});
  458. obj.focus();
  459. return false;
  460. }else{
  461. var json = this.module.form.json.moduleList[this.module.json.id];
  462. this.module.form.json.moduleList[value]=json;
  463. delete this.module.form.json.moduleList[this.module.json.id];
  464. }
  465. }
  466. }
  467. var oldValue = this.data[name];
  468. //this.data[name] = value;
  469. this.changeJsonDate(name, value);
  470. this.changeData(name, obj, oldValue);
  471. },
  472. setEditNodeStyles: function(node){
  473. var nodes = node.getChildren();
  474. if (nodes.length){
  475. nodes.each(function(el){
  476. var cName = el.get("class");
  477. if (cName){
  478. if (this.form.css[cName]) el.setStyles(this.form.css[cName]);
  479. }
  480. this.setEditNodeStyles(el);
  481. }.bind(this));
  482. }
  483. },
  484. loadScriptInput: function(){
  485. var scriptNodes = this.propertyContent.getElements(".MWFScript");
  486. scriptNodes.each(function(node){
  487. MWF.require("MWF.widget.ScriptEditor", function(){
  488. var script = new MWF.widget.ScriptEditor(node, {
  489. "onPostSave": function(script){
  490. this.saveScriptItem(node, script);
  491. }.bind(this),
  492. "onQueryDelete": function(script){
  493. this.deleteScriptItem(node, script);
  494. }.bind(this)
  495. });
  496. this.setScriptItems(script, node);
  497. }.bind(this));
  498. }.bind(this));
  499. },
  500. deleteScriptItem: function(node, script){
  501. var jsondata = node.get("name");
  502. this.data[jsondata].erase(script.data.id);
  503. this.cms.scripts[script.data.id] = null;
  504. delete this.cms.scripts[script.data.id];
  505. this.cms.cms.scriptList.erase(script.data);
  506. },
  507. saveScriptItem: function(node, script){
  508. var jsondata = node.get("name");
  509. var scriptList = this.data[jsondata];
  510. var data = script.data;
  511. var scriptData = this.cms.scripts[script.data.id];
  512. if (!scriptData){
  513. this.cms.cms.scriptList.push(data);
  514. this.cms.scripts[script.data.id] = data;
  515. }
  516. if (scriptList.indexOf(data.id) == -1){
  517. this.data[jsondata].push(data.id);
  518. }
  519. },
  520. setScriptItems: function(script, node){
  521. var jsondata = node.get("name");
  522. var scriptList = this.data[jsondata];
  523. scriptList.each(function(id){
  524. if (id){
  525. var data = this.cms.scripts[id];
  526. if (data) script.setScriptItem(data);
  527. }
  528. }.bind(this));
  529. }
  530. });
  531. MWF.xApplication.cms.FormDesigner.PropertyMulti = new Class({
  532. Extends: MWF.xApplication.cms.FormDesigner.Property,
  533. Implements: [Options, Events],
  534. initialize: function(form, modules, propertyNode, designer, options){
  535. this.setOptions(options);
  536. this.modules = modules;
  537. this.form = form;
  538. // this.data = module.json;
  539. this.data = {};
  540. this.htmlPath = this.options.path;
  541. this.designer = designer;
  542. this.propertyNode = propertyNode;
  543. },
  544. load: function(){
  545. if (this.fireEvent("queryLoad")){
  546. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  547. this.htmlString = responseText;
  548. MWF.require("MWF.widget.JsonTemplate", function(){
  549. this.fireEvent("postLoad");
  550. }.bind(this));
  551. }.bind(this));
  552. }
  553. },
  554. show: function(){
  555. if (!this.propertyContent){
  556. if (this.htmlString){
  557. this.JsonTemplate = new MWF.widget.JsonTemplate({}, this.htmlString);
  558. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyNode);
  559. this.propertyContent.set("html", this.JsonTemplate.load());
  560. this.setEditNodeEvent();
  561. this.setEditNodeStyles(this.propertyContent);
  562. this.loadPropertyTab();
  563. this.loadMaplist();
  564. this.loadScriptArea();
  565. this.loadTreeData();
  566. this.loadArrayList();
  567. //this.loadEventsEditor();
  568. //this.loadHTMLArea();
  569. //this.loadJSONArea();
  570. // this.loadScriptInput();
  571. //MWF.cms.widget.EventsEditor
  572. }
  573. }else{
  574. this.propertyContent.setStyle("display", "block");
  575. }
  576. },
  577. hide: function(){
  578. if (this.propertyContent) this.propertyContent.destroy();
  579. },
  580. changeStyle: function(name){
  581. this.modules.each(function(module){
  582. module.setPropertiesOrStyles(name);
  583. }.bind(this));
  584. },
  585. changeData: function(name, input, oldValue){
  586. this.modules.each(function(module){
  587. module._setEditStyle(name, input, oldValue);
  588. }.bind(this));
  589. },
  590. changeJsonDate: function(key, value){
  591. this.modules.each(function(module){
  592. module.json[key] = value;
  593. }.bind(this));
  594. },
  595. });