Property.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. MWF.require("MWF.widget.Common", null, false);
  2. MWF.require("MWF.widget.JsonTemplate", null, false);
  3. MWF.xApplication.process.FormDesigner.Property = MWF.FCProperty = 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.form = module.form;
  14. this.data = module.json;
  15. this.htmlPath = this.options.path;
  16. this.designer = designer;
  17. this.maplists = {};
  18. this.propertyNode = propertyNode;
  19. },
  20. load: function(){
  21. if (this.fireEvent("queryLoad")){
  22. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  23. this.htmlString = responseText;
  24. this.fireEvent("postLoad");
  25. }.bind(this));
  26. }
  27. this.propertyNode.addEvent("keydown", function(e){e.stopPropagation();});
  28. },
  29. editProperty: function(td){
  30. },
  31. getHtmlString: function(callback){
  32. if (!this.htmlString){
  33. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  34. this.htmlString = responseText;
  35. if (callback) callback();
  36. }.bind(this));
  37. }else{
  38. if (callback) callback();
  39. }
  40. },
  41. show: function(){
  42. if (!this.propertyContent){
  43. this.getHtmlString(function(){
  44. if (this.htmlString){
  45. this.JsonTemplate = new MWF.widget.JsonTemplate(this.data, this.htmlString);
  46. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyNode);
  47. this.propertyContent.set("html", this.JsonTemplate.load());
  48. this.setEditNodeEvent();
  49. this.setEditNodeStyles(this.propertyContent);
  50. this.loadPropertyTab();
  51. this.loadMaplist();
  52. this.loadStylesList();
  53. this.loadDivTemplateType();
  54. this.loadPersonInput();
  55. this.loadFormFieldInput();
  56. this.loadScriptArea();
  57. this.loadHtmlEditorArea();
  58. this.loadTreeData();
  59. this.loadArrayList();
  60. this.loadEventsEditor();
  61. this.loadActionArea();
  62. this.loadHTMLArea();
  63. this.loadJSONArea();
  64. this.loadFormSelect();
  65. this.loadViewSelect();
  66. this.loadValidation();
  67. this.loadIconSelect();
  68. this.loadImageClipper();
  69. // this.loadScriptInput();
  70. //MWF.process.widget.EventsEditor
  71. }
  72. }.bind(this));
  73. }else{
  74. this.propertyContent.setStyle("display", "block");
  75. }
  76. (new Fx.Scroll(layout.desktop.node)).toTop();
  77. },
  78. hide: function(){
  79. //this.JsonTemplate = null;
  80. //this.propertyNode.set("html", "");
  81. if (this.propertyContent) this.propertyContent.setStyle("display", "none");
  82. },
  83. loadTreeData: function(){
  84. var arrays = this.propertyContent.getElements(".MWFTreeData");
  85. arrays.each(function(node){
  86. var title = node.get("title");
  87. var name = node.get("name");
  88. var json = this.data[name];
  89. if (!json) json = [];
  90. MWF.require("MWF.widget.TreeEditor", function(){
  91. var treeEditor = new MWF.widget.TreeEditor(node, {
  92. "title": title,
  93. "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  94. "onChange": function(){
  95. this.data[name] = treeEditor.toJson();
  96. this.module.json[name] = this.data[name];
  97. this.module._refreshTree();
  98. }.bind(this)
  99. });
  100. treeEditor.load(json);
  101. }.bind(this));
  102. node.addEvent("keydown", function(e){e.stopPropagation();});
  103. }.bind(this));
  104. },
  105. loadJSONArea: function(){
  106. var jsonNode = this.propertyContent.getElement(".MWFJSONArea");
  107. if (jsonNode){
  108. this.propertyTab.pages.each(function(page){
  109. if (page.contentNode == jsonNode.parentElement){
  110. page.setOptions({
  111. "onShow": function(){
  112. jsonNode.empty();
  113. MWF.require("MWF.widget.JsonParse", function(){
  114. this.json = new MWF.widget.JsonParse(this.module.json, jsonNode, null);
  115. this.json.load();
  116. }.bind(this));
  117. }.bind(this)
  118. });
  119. }
  120. }.bind(this));
  121. }
  122. },
  123. loadHTMLArea: function(){
  124. var htmlNode = this.propertyContent.getElement(".MWFHTMLArea");
  125. if (htmlNode){
  126. var copy = this.module.node.clone(true, true);
  127. copy.clearStyles(true);
  128. htmlNode.set("text", copy.outerHTML);
  129. copy.destroy();
  130. this.propertyTab.pages.each(function(page){
  131. if (page.contentNode == htmlNode.parentElement){
  132. page.setOptions({
  133. "onShow": function(){
  134. var copy = this.module.node.clone(true, true);
  135. copy.clearStyles(true);
  136. htmlNode.set("text", copy.outerHTML);
  137. copy.destroy();
  138. }.bind(this)
  139. });
  140. }
  141. }.bind(this));
  142. }
  143. },
  144. loadFormSelect: function(){
  145. var formNodes = this.propertyContent.getElements(".MWFFormSelect");
  146. if (formNodes.length){
  147. this.getFormList(function(){
  148. formNodes.each(function(node){
  149. var select = new Element("select").inject(node);
  150. select.addEvent("change", function(e){
  151. this.setValue(e.target.getParent("div").get("name"), e.target.options[e.target.selectedIndex].value);
  152. }.bind(this));
  153. this.setFormSelectOptions(node, select);
  154. var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  155. refreshNode.addEvent("click", function(e){
  156. this.getFormList(function(){
  157. this.setFormSelectOptions(node, select);
  158. }.bind(this), true);
  159. }.bind(this));
  160. //select.addEvent("click", function(e){
  161. // this.setFormSelectOptions(node, select);
  162. //}.bind(this));
  163. }.bind(this));
  164. }.bind(this));
  165. }
  166. },
  167. setFormSelectOptions: function(node, select){
  168. var name = node.get("name");
  169. select.empty();
  170. var option = new Element("option", {"text": "none"}).inject(select);
  171. this.forms.each(function(form){
  172. var option = new Element("option", {
  173. "text": form.name,
  174. "value": form.id,
  175. "selected": (this.data[name]==form.id)
  176. }).inject(select);
  177. }.bind(this));
  178. },
  179. getFormList: function(callback, refresh){
  180. if (!this.forms || refresh){
  181. this.form.designer.actions.listForm(this.form.designer.application.id, function(json){
  182. this.forms = json.data;
  183. if (callback) callback();
  184. }.bind(this));
  185. }else{
  186. if (callback) callback();
  187. }
  188. },
  189. // clearStyles: function(node){
  190. // node.removeProperty("style");
  191. // var subNode = node.getFirst();
  192. // while (subNode){
  193. // this.clearStyles(subNode);
  194. // subNode = subNode.getNext();
  195. // }
  196. // },
  197. loadViewSelect: function(){
  198. var viewNodes = this.propertyContent.getElements(".MWFViewSelect");
  199. if (viewNodes.length){
  200. this.getViewList(function(){
  201. viewNodes.each(function(node){
  202. var select = new Element("select").inject(node);
  203. select.addEvent("change", function(e){
  204. var viewId = e.target.options[e.target.selectedIndex].value;
  205. var viewName = e.target.options[e.target.selectedIndex].get("text");
  206. this.setValue(e.target.getParent("div").get("name"), viewId);
  207. this.setValue(e.target.getParent("div").get("name")+"Name", viewName);
  208. }.bind(this));
  209. this.setViewSelectOptions(node, select);
  210. var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  211. refreshNode.addEvent("click", function(e){
  212. this.getViewList(function(){
  213. this.setViewSelectOptions(node, select);
  214. }.bind(this), true);
  215. }.bind(this));
  216. //select.addEvent("click", function(e){
  217. // this.setFormSelectOptions(node, select);
  218. //}.bind(this));
  219. }.bind(this));
  220. }.bind(this));
  221. }
  222. },
  223. setViewSelectOptions: function(node, select){
  224. var name = node.get("name");
  225. select.empty();
  226. var option = new Element("option", {"text": "none"}).inject(select);
  227. this.views.each(function(view){
  228. var option = new Element("option", {
  229. "text": view.name,
  230. "value": view.id,
  231. "selected": (this.data[name]==view.id)
  232. }).inject(select);
  233. }.bind(this));
  234. },
  235. getViewList: function(callback, refresh){
  236. if (!this.views || refresh){
  237. this.form.designer.actions.listView(this.form.designer.application.id, function(json){
  238. this.views = json.data;
  239. if (callback) callback();
  240. }.bind(this));
  241. }else{
  242. if (callback) callback();
  243. }
  244. },
  245. loadValidation: function(){
  246. var nodes = this.propertyContent.getElements(".MWFValidation");
  247. if (nodes.length){
  248. nodes.each(function(node){
  249. var name = node.get("name");
  250. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ValidationEditor", function(){
  251. var validationEditor = new MWF.xApplication.process.FormDesigner.widget.ValidationEditor(node, this.designer, {
  252. "onChange": function(){
  253. var data = validationEditor.getValidationData();
  254. this.data[name] = data;
  255. }.bind(this)
  256. });
  257. validationEditor.load(this.data[name])
  258. }.bind(this));
  259. //new MWF.xApplication.process.FormDesigner.widget.ValidationEditor(node, this.designer);
  260. }.bind(this));
  261. }
  262. },
  263. loadIconSelect: function(){
  264. var nodes = this.propertyContent.getElements(".MWFIcon");
  265. if (nodes.length){
  266. nodes.each(function(node){
  267. var id = node.get("name");
  268. var icon = this.data[id];
  269. var iconNode = new Element("div", {"styles": this.form.css.processIconNode}).inject(node);
  270. if (icon) iconNode.setStyles({"background": "url("+icon+") center center no-repeat"});
  271. var selectNode = new Element("div", {"styles": this.form.css.processIconSelectNode, "text": this.form.designer.lp.selectIcon}).inject(node);
  272. selectNode.addEvent("click", function(){
  273. this.selectIcon(node);
  274. }.bind(this));
  275. }.bind(this));
  276. }
  277. },
  278. selectIcon: function(node){
  279. if (!node.iconMenu){
  280. var iconSelectMenu = new MWF.widget.Menu(node, {"event": "click", "style": "processIcon"});
  281. iconSelectMenu.load();
  282. node.iconMenu = iconSelectMenu;
  283. var _self = this;
  284. for (var i=0; i<=48; i++){
  285. var icon = "/x_component_process_ProcessManager/$Explorer/default/processIcon/process_icon_"+i+".png";
  286. var item = iconSelectMenu.addMenuItem("", "click", function(){
  287. var id = node.get("name");
  288. var src = this.item.getElement("img").get("src");
  289. _self.data[id] = src;
  290. node.getFirst("div").setStyle("background-image", "url("+src+")");
  291. }, icon);
  292. item.iconName = icon;
  293. }
  294. }
  295. },
  296. loadImageClipper: function(){
  297. var nodes = this.propertyContent.getElements(".MWFImageClipper");
  298. if (nodes.length){
  299. nodes.each(function(node){
  300. var id = node.get("name");
  301. var selectNode = new Element("div", {"styles": this.form.css.processIconSelectNode, "text": this.form.designer.lp.selectImage}).inject(node);
  302. selectNode.addEvent("click", function(){
  303. this.selectImage(node, id);
  304. }.bind(this));
  305. }.bind(this));
  306. }
  307. },
  308. selectImage: function(node, name){
  309. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ImageClipper", function(){
  310. var size = this.module.node.getSize();
  311. var image = new MWF.xApplication.process.FormDesigner.widget.ImageClipper(this.designer, {
  312. "title": this.form.designer.lp.selectImage,
  313. "width": (this.data.styles.width) ? size.x : 0,
  314. "height": (this.data.styles.height) ? size.y : 0,
  315. "onChange": function(){
  316. debugger;
  317. var data = image.data;
  318. this.changeJsonDate(name, data);
  319. this.changeData(name, node, null);
  320. }.bind(this)
  321. });
  322. image.load(this.data[name])
  323. }.bind(this));
  324. },
  325. loadEventsEditor: function(){
  326. var events = this.propertyContent.getElement(".MWFEventsArea");
  327. if (events){
  328. var name = events.get("name");
  329. var eventsObj = this.data[name];
  330. MWF.xDesktop.requireApp("process.FormDesigner", "widget.EventsEditor", function(){
  331. var eventsEditor = new MWF.xApplication.process.FormDesigner.widget.EventsEditor(events, this.designer, {
  332. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  333. "maxObj": this.designer.formContentNode
  334. });
  335. eventsEditor.load(eventsObj);
  336. }.bind(this));
  337. }
  338. },
  339. loadArrayList: function(){
  340. var arrays = this.propertyContent.getElements(".MWFArraylist");
  341. arrays.each(function(node){
  342. var title = node.get("title");
  343. var name = node.get("name");
  344. var arr = this.data[name];
  345. if (!arr) arr = [];
  346. MWF.require("MWF.widget.Arraylist", function(){
  347. var arraylist = new MWF.widget.Arraylist(node, {
  348. "title": title,
  349. "onChange": function(){
  350. this.data[name] = arraylist.toArray();
  351. }.bind(this)
  352. });
  353. arraylist.load(arr);
  354. }.bind(this));
  355. node.addEvent("keydown", function(e){e.stopPropagation();});
  356. }.bind(this));
  357. },
  358. loadHtmlEditorArea: function(){
  359. var htmlAreas = this.propertyContent.getElements(".MWFHtmlEditorArea");
  360. htmlAreas.each(function(node){
  361. var title = node.get("title");
  362. var name = node.get("name");
  363. var scriptContent = this.data[name];
  364. MWF.require("MWF.widget.HtmlEditorArea", function(){
  365. var htmlArea = new MWF.widget.HtmlEditorArea(node, {
  366. "title": title,
  367. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  368. "maxObj": this.designer.formContentNode,
  369. "onChange": function(){
  370. this.data[name] = htmlArea.getValue();
  371. this.changeData(name);
  372. }.bind(this),
  373. "onSave": function(){
  374. this.designer.saveForm();
  375. }.bind(this)
  376. });
  377. htmlArea.load({"code": scriptContent});
  378. }.bind(this));
  379. }.bind(this));
  380. },
  381. loadStylesList: function(){
  382. var styleSelNodes = this.propertyContent.getElements(".MWFFormStyle");
  383. styleSelNodes.each(function(node){
  384. if (this.module.form.stylesList){
  385. if (!this.data.formStyleType) this.data.formStyleType = "default";
  386. Object.each(this.module.form.stylesList, function(s, key){
  387. new Element("option", {
  388. "text": s.name,
  389. "value": key,
  390. "selected": ((!this.data.formStyleType && key=="default") || (this.data.formStyleType==key))
  391. }).inject(node)
  392. }.bind(this));
  393. }else{
  394. node.getParent("tr").setStyle("display", "none");
  395. }
  396. }.bind(this));
  397. },
  398. loadDivTemplateType: function(){
  399. var nodes = this.propertyContent.getElements(".MWFDivTemplate");
  400. if (nodes.length){
  401. var keys = [];
  402. if (this.module.form.stylesList) {
  403. if (this.module.form.stylesList[this.module.form.json.formStyleType]){
  404. var styles = this.module.form.stylesList[this.module.form.json.formStyleType][this.module.moduleName];
  405. if (styles) {
  406. Object.each(styles, function (v, k) {
  407. keys.push(k);
  408. }.bind(this));
  409. }
  410. }
  411. }
  412. nodes.each(function(node){
  413. node.empty();
  414. new Element("option", {
  415. "text": "default",
  416. "value": "default",
  417. "selected": (!this.data.templateType || this.data.templateType=="default")
  418. }).inject(node);
  419. if (keys.length){
  420. keys.each(function(k){
  421. new Element("option", {
  422. "text": styles[k].name,
  423. "value": k,
  424. "selected": (this.data.templateType==k)
  425. }).inject(node)
  426. }.bind(this));
  427. }else{
  428. node.getParent("tr").setStyle("display", "none");
  429. }
  430. }.bind(this));
  431. }
  432. },
  433. loadPersonInput: function(){
  434. var personIdentityNodes = this.propertyContent.getElements(".MWFPersonIdentity");
  435. var personDepartmentNodes = this.propertyContent.getElements(".MWFPersonDepartment");
  436. var personCompanyNodes = this.propertyContent.getElements(".MWFPersonCompany");
  437. var dutyNodes = this.propertyContent.getElements(".MWFDutySelector");
  438. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  439. personIdentityNodes.each(function(node){
  440. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  441. "type": "identity",
  442. "names": this.data[node.get("name")],
  443. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  444. });
  445. }.bind(this));
  446. personDepartmentNodes.each(function(node){
  447. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  448. "type": "department",
  449. "names": this.data[node.get("name")],
  450. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  451. });
  452. }.bind(this));
  453. personCompanyNodes.each(function(node){
  454. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  455. "type": "company",
  456. "names": this.data[node.get("name")],
  457. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  458. });
  459. }.bind(this));
  460. dutyNodes.each(function(node){
  461. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  462. "type": "duty",
  463. "names": this.data[node.get("name")],
  464. "onChange": function(ids){this.addDutyItem(node, ids);}.bind(this),
  465. "onRemoveDuty": function(item){this.removeDutyItem(node, item);}.bind(this)
  466. });
  467. }.bind(this));
  468. }.bind(this));
  469. },
  470. removeDutyItem: function(node, item){
  471. if (item.data.id){
  472. var values = this.data[node.get("name")] || [];
  473. var value = values.filter(function(v){
  474. return v.id == item.data.id;
  475. });
  476. value.each(function(v) {
  477. values = values.erase(v);
  478. });
  479. this.data[node.get("name")] = values;
  480. }
  481. item.node.destroy();
  482. MWF.release(item);
  483. delete item;
  484. },
  485. addDutyItem: function(node, ids){
  486. var value = this.data[node.get("name")] || "";
  487. if (!value) value = "[]";
  488. var values = JSON.decode(value);
  489. ids.each(function(id){
  490. if (id.data.id){
  491. for (var i=0; i<values.length; i++){
  492. if (values[i].id==id.data.id){
  493. values[i].name = id.data.name;
  494. values[i].code = id.data.code;
  495. break;
  496. }
  497. }
  498. }else{
  499. id.data.id = new MWF.widget.UUID().toString();
  500. values.push({"name": id.data.name, "id": id.data.id, "code": id.data.code});
  501. }
  502. }.bind(this));
  503. this.data[node.get("name")] = JSON.encode(values);
  504. },
  505. loadFormFieldInput: function(){
  506. var fieldNodes = this.propertyContent.getElements(".MWFFormFieldPerson");
  507. MWF.xDesktop.requireApp("process.ViewDesigner", "widget.PersonSelector", function(){
  508. fieldNodes.each(function(node){
  509. new MWF.xApplication.process.ViewDesigner.widget.PersonSelector(node, this.form.designer, {
  510. "type": "formField",
  511. "application": this.form.json.application,
  512. "fieldType": "person",
  513. "names": this.data[node.get("name")],
  514. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  515. });
  516. }.bind(this));
  517. }.bind(this));
  518. },
  519. savePersonItem: function(node, ids){
  520. var values = [];
  521. ids.each(function(id){
  522. values.push(id.data.name);
  523. }.bind(this));
  524. this.data[node.get("name")] = values;
  525. },
  526. loadScriptArea: function(){
  527. var scriptAreas = this.propertyContent.getElements(".MWFScriptArea");
  528. var formulaAreas = this.propertyContent.getElements(".MWFFormulaArea");
  529. this.loadScriptEditor(scriptAreas);
  530. this.loadScriptEditor(formulaAreas, "formula");
  531. },
  532. loadScriptEditor: function(scriptAreas, style){
  533. scriptAreas.each(function(node){
  534. var title = node.get("title");
  535. var name = node.get("name");
  536. var scriptContent = this.data[name];
  537. MWF.require("MWF.widget.ScriptArea", function(){
  538. var scriptArea = new MWF.widget.ScriptArea(node, {
  539. "title": title,
  540. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  541. "maxObj": this.designer.formContentNode,
  542. "onChange": function(){
  543. this.data[name] = scriptArea.toJson();
  544. }.bind(this),
  545. "onSave": function(){
  546. this.designer.saveForm();
  547. }.bind(this),
  548. "style": style || "default"
  549. });
  550. scriptArea.load(scriptContent);
  551. }.bind(this));
  552. }.bind(this));
  553. },
  554. loadActionArea: function(){
  555. var actionAreas = this.propertyContent.getElements(".MWFActionArea");
  556. actionAreas.each(function(node){
  557. var name = node.get("name");
  558. var actionContent = this.data[name];
  559. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ActionsEditor", function(){
  560. var actionEditor = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor(node, this.designer, {
  561. "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  562. "onChange": function(){
  563. this.data[name] = actionEditor.data;
  564. }.bind(this)
  565. });
  566. actionEditor.load(actionContent);
  567. }.bind(this));
  568. }.bind(this));
  569. },
  570. loadMaplist: function(){
  571. var maplists = this.propertyContent.getElements(".MWFMaplist");
  572. maplists.each(function(node){
  573. var title = node.get("title");
  574. var name = node.get("name");
  575. var collapse = node.get("collapse");
  576. var mapObj = this.data[name];
  577. if (!mapObj) mapObj = {};
  578. MWF.require("MWF.widget.Maplist", function(){
  579. var maplist = new MWF.widget.Maplist(node, {
  580. "title": title,
  581. "collapse": (collapse) ? true : false,
  582. "onChange": function(){
  583. //this.data[name] = maplist.toJson();
  584. //
  585. this.changeJsonDate(name, maplist.toJson());
  586. this.changeStyle(name);
  587. this.changeData(name);
  588. }.bind(this)
  589. });
  590. maplist.load(mapObj);
  591. this.maplists[name] = maplist;
  592. }.bind(this));
  593. }.bind(this));
  594. },
  595. loadPropertyTab: function(){
  596. var tabNodes = this.propertyContent.getElements(".MWFTab");
  597. if (tabNodes.length){
  598. var tmpNode = this.propertyContent.getFirst();
  599. var tabAreaNode = new Element("div", {
  600. "styles": this.form.css.propertyTabNode
  601. }).inject(tmpNode, "before");
  602. MWF.require("MWF.widget.Tab", function(){
  603. var tab = new MWF.widget.Tab(tabAreaNode, {"style": "formPropertyList"});
  604. tab.load();
  605. var tabPages = [];
  606. tabNodes.each(function(node){
  607. var page = tab.addTab(node, node.get("title"), false);
  608. tabPages.push(page);
  609. this.setScrollBar(page.contentNodeArea, "small", null, null);
  610. }.bind(this));
  611. tabPages[0].showTab();
  612. this.propertyTab = tab;
  613. this.designer.resizeNode();
  614. }.bind(this), false);
  615. }
  616. },
  617. setEditNodeEvent: function(){
  618. var property = this;
  619. // var inputs = this.process.propertyListNode.getElements(".editTableInput");
  620. var inputs = this.propertyContent.getElements("input");
  621. inputs.each(function(input){
  622. var jsondata = input.get("name");
  623. if (this.module){
  624. var id = this.module.json.id;
  625. input.set("name", id+jsondata);
  626. }
  627. if (jsondata){
  628. var inputType = input.get("type").toLowerCase();
  629. switch (inputType){
  630. case "radio":
  631. input.addEvent("change", function(e){
  632. property.setRadioValue(jsondata, this);
  633. });
  634. input.addEvent("blur", function(e){
  635. property.setRadioValue(jsondata, this);
  636. });
  637. input.addEvent("keydown", function(e){
  638. e.stopPropagation();
  639. });
  640. property.setRadioValue(jsondata, input);
  641. break;
  642. case "checkbox":
  643. input.addEvent("change", function(e){
  644. property.setCheckboxValue(jsondata, this);
  645. });
  646. input.addEvent("click", function(e){
  647. property.setCheckboxValue(jsondata, this);
  648. });
  649. input.addEvent("keydown", function(e){
  650. e.stopPropagation();
  651. });
  652. break;
  653. default:
  654. input.addEvent("change", function(e){
  655. property.setValue(jsondata, this.value, this);
  656. });
  657. input.addEvent("blur", function(e){
  658. property.setValue(jsondata, this.value, this);
  659. });
  660. input.addEvent("keydown", function(e){
  661. if (e.code==13){
  662. property.setValue(jsondata, this.value, this);
  663. }
  664. e.stopPropagation();
  665. });
  666. }
  667. }
  668. }.bind(this));
  669. var selects = this.propertyContent.getElements("select");
  670. selects.each(function(select){
  671. var jsondata = select.get("name");
  672. if (jsondata){
  673. select.addEvent("change", function(e){
  674. property.setSelectValue(jsondata, this);
  675. });
  676. }
  677. });
  678. var textareas = this.propertyContent.getElements("textarea");
  679. textareas.each(function(input){
  680. var jsondata = input.get("name");
  681. if (jsondata){
  682. input.addEvent("change", function(e){
  683. property.setValue(jsondata, this.value);
  684. });
  685. input.addEvent("blur", function(e){
  686. property.setValue(jsondata, this.value);
  687. });
  688. input.addEvent("keydown", function(e){
  689. e.stopPropagation();
  690. });
  691. }
  692. }.bind(this));
  693. },
  694. changeStyle: function(name){
  695. this.module.setPropertiesOrStyles(name);
  696. },
  697. changeData: function(name, input, oldValue){
  698. this.module._setEditStyle(name, input, oldValue);
  699. },
  700. changeJsonDate: function(key, value){
  701. this.data[key] = value;
  702. },
  703. setRadioValue: function(name, input){
  704. if (input.checked){
  705. var value = input.value;
  706. if (value=="false") value = false;
  707. if (value=="true") value = true;
  708. var oldValue = this.data[name];
  709. this.changeJsonDate(name, value);
  710. this.changeData(name, input, oldValue);
  711. }
  712. },
  713. setCheckboxValue: function(name, input){
  714. var id = this.module.json.id;
  715. var checkboxList = $$("input[name='"+id+name+"']");
  716. var values = [];
  717. checkboxList.each(function(checkbox){
  718. if (checkbox.get("checked")){
  719. values.push(checkbox.value);
  720. }
  721. });
  722. var oldValue = this.data[name];
  723. //this.data[name] = values;
  724. this.changeJsonDate(name, values);
  725. this.changeData(name, input, oldValue);
  726. },
  727. setSelectValue: function(name, select){
  728. var idx = select.selectedIndex;
  729. var options = select.getElements("option");
  730. var value = "";
  731. if (options[idx]){
  732. value = options[idx].get("value");
  733. }
  734. var oldValue = this.data[name];
  735. //this.data[name] = value;
  736. this.changeJsonDate(name, value);
  737. this.changeData(name, select, oldValue);
  738. },
  739. setValue: function(name, value, obj){
  740. debugger;
  741. if (name=="id"){
  742. if (value!=this.module.json.id){
  743. if (!value){
  744. this.designer.notice(MWF.APPFD.LP.notNullId, "error", this.module.form.designer.propertyContentArea, {x:"right", y:"bottom"});
  745. obj.focus();
  746. return false;
  747. }else if (this.module.form.json.moduleList[value]){
  748. this.designer.notice(MWF.APPFD.LP.repetitionsId, "error", this.module.form.designer.propertyContentArea, {x:"right", y:"bottom"});
  749. obj.focus();
  750. return false;
  751. }else{
  752. var json = this.module.form.json.moduleList[this.module.json.id];
  753. this.module.form.json.moduleList[value]=json;
  754. delete this.module.form.json.moduleList[this.module.json.id];
  755. }
  756. }
  757. }
  758. var oldValue = this.data[name];
  759. //this.data[name] = value;
  760. this.changeJsonDate(name, value);
  761. this.changeData(name, obj, oldValue);
  762. },
  763. setEditNodeStyles: function(node){
  764. var nodes = node.getChildren();
  765. if (nodes.length){
  766. nodes.each(function(el){
  767. var cName = el.get("class");
  768. if (cName){
  769. if (this.form.css[cName]) el.setStyles(this.form.css[cName]);
  770. }
  771. this.setEditNodeStyles(el);
  772. }.bind(this));
  773. }
  774. },
  775. loadScriptInput: function(){
  776. var scriptNodes = this.propertyContent.getElements(".MWFScript");
  777. scriptNodes.each(function(node){
  778. MWF.require("MWF.widget.ScriptEditor", function(){
  779. var script = new MWF.widget.ScriptEditor(node, {
  780. "onPostSave": function(script){
  781. this.saveScriptItem(node, script);
  782. }.bind(this),
  783. "onQueryDelete": function(script){
  784. this.deleteScriptItem(node, script);
  785. }.bind(this)
  786. });
  787. this.setScriptItems(script, node);
  788. }.bind(this));
  789. }.bind(this));
  790. },
  791. deleteScriptItem: function(node, script){
  792. var jsondata = node.get("name");
  793. this.data[jsondata].erase(script.data.id);
  794. this.process.scripts[script.data.id] = null;
  795. delete this.process.scripts[script.data.id];
  796. this.process.process.scriptList.erase(script.data);
  797. },
  798. saveScriptItem: function(node, script){
  799. var jsondata = node.get("name");
  800. var scriptList = this.data[jsondata];
  801. var data = script.data;
  802. var scriptData = this.process.scripts[script.data.id];
  803. if (!scriptData){
  804. this.process.process.scriptList.push(data);
  805. this.process.scripts[script.data.id] = data;
  806. }
  807. if (scriptList.indexOf(data.id) == -1){
  808. this.data[jsondata].push(data.id);
  809. }
  810. },
  811. setScriptItems: function(script, node){
  812. var jsondata = node.get("name");
  813. var scriptList = this.data[jsondata];
  814. scriptList.each(function(id){
  815. if (id){
  816. var data = this.process.scripts[id];
  817. if (data) script.setScriptItem(data);
  818. }
  819. }.bind(this));
  820. }
  821. });
  822. MWF.xApplication.process.FormDesigner.PropertyMulti = new Class({
  823. Extends: MWF.xApplication.process.FormDesigner.Property,
  824. Implements: [Options, Events],
  825. initialize: function(form, modules, propertyNode, designer, options){
  826. this.setOptions(options);
  827. this.modules = modules;
  828. this.form = form;
  829. // this.data = module.json;
  830. this.data = {};
  831. this.htmlPath = this.options.path;
  832. this.designer = designer;
  833. this.maplists = {};
  834. this.propertyNode = propertyNode;
  835. },
  836. load: function(){
  837. if (this.fireEvent("queryLoad")){
  838. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  839. this.htmlString = responseText;
  840. MWF.require("MWF.widget.JsonTemplate", function(){
  841. this.fireEvent("postLoad");
  842. }.bind(this));
  843. }.bind(this));
  844. }
  845. },
  846. show: function(){
  847. if (!this.propertyContent){
  848. if (this.htmlString){
  849. this.JsonTemplate = new MWF.widget.JsonTemplate({}, this.htmlString);
  850. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyNode);
  851. this.propertyContent.set("html", this.JsonTemplate.load());
  852. this.setEditNodeEvent();
  853. this.setEditNodeStyles(this.propertyContent);
  854. this.loadPropertyTab();
  855. this.loadMaplist();
  856. this.loadScriptArea();
  857. this.loadTreeData();
  858. this.loadArrayList();
  859. //this.loadEventsEditor();
  860. //this.loadHTMLArea();
  861. //this.loadJSONArea();
  862. // this.loadScriptInput();
  863. //MWF.process.widget.EventsEditor
  864. }
  865. }else{
  866. this.propertyContent.setStyle("display", "block");
  867. }
  868. },
  869. hide: function(){
  870. if (this.propertyContent) this.propertyContent.destroy();
  871. },
  872. changeStyle: function(name){
  873. this.modules.each(function(module){
  874. module.setPropertiesOrStyles(name);
  875. }.bind(this));
  876. },
  877. changeData: function(name, input, oldValue){
  878. this.modules.each(function(module){
  879. module._setEditStyle(name, input, oldValue);
  880. }.bind(this));
  881. },
  882. changeJsonDate: function(key, value){
  883. //alert(key+": "+value );
  884. this.modules.each(function(module){
  885. module.json[key] = value;
  886. }.bind(this));
  887. },
  888. });