Property.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512
  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.data.pid = this.form.json.id+this.data.id;
  16. this.htmlPath = this.options.path;
  17. this.designer = designer;
  18. this.maplists = {};
  19. this.propertyNode = propertyNode;
  20. },
  21. load: function(){
  22. if (this.fireEvent("queryLoad")){
  23. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  24. this.htmlString = responseText;
  25. this.fireEvent("postLoad");
  26. }.bind(this));
  27. }
  28. this.propertyNode.addEvent("keydown", function(e){e.stopPropagation();});
  29. },
  30. editProperty: function(td){
  31. },
  32. getHtmlString: function(callback){
  33. if (!this.htmlString){
  34. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  35. this.htmlString = responseText;
  36. if (callback) callback();
  37. }.bind(this));
  38. }else{
  39. if (callback) callback();
  40. }
  41. },
  42. show: function(){
  43. if (!this.propertyContent){
  44. this.getHtmlString(function(){
  45. if (this.htmlString){
  46. this.JsonTemplate = new MWF.widget.JsonTemplate(this.data, this.htmlString);
  47. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyNode);
  48. this.propertyContent.set("html", this.JsonTemplate.load());
  49. this.setEditNodeEvent();
  50. this.setEditNodeStyles(this.propertyContent);
  51. this.loadPropertyTab();
  52. this.loadMaplist();
  53. this.loadStylesList();
  54. this.loadDivTemplateType();
  55. this.loadPersonInput();
  56. this.loadFormFieldInput();
  57. this.loadScriptArea();
  58. this.loadCssArea();
  59. this.loadHtmlEditorArea();
  60. this.loadTreeData();
  61. this.loadArrayList();
  62. this.loadEventsEditor();
  63. this.loadActionArea();
  64. this.loadHTMLArea();
  65. this.loadJSONArea();
  66. this.loadFormSelect();
  67. //this.loadViewSelect();
  68. this.loadValidation();
  69. this.loadIconSelect();
  70. this.loadLabelFlagSelect();
  71. this.loadImageClipper();
  72. this.loadParameterEditor();
  73. this.loadContextRoot();
  74. this.loadUnitTypeSelector();
  75. this.loadSourceTestRestful();
  76. this.loadSidebarPosition();
  77. this.loadViewFilter();
  78. //this.testRestful();
  79. // this.loadScriptInput();
  80. //MWF.process.widget.EventsEditor
  81. }
  82. }.bind(this));
  83. }else{
  84. this.propertyContent.setStyle("display", "block");
  85. }
  86. (new Fx.Scroll(layout.desktop.node)).toTop();
  87. },
  88. hide: function(){
  89. //this.JsonTemplate = null;
  90. //this.propertyNode.set("html", "");
  91. if (this.propertyContent) this.propertyContent.setStyle("display", "none");
  92. },
  93. destroy: function(){
  94. if (this.propertyContent){
  95. this.propertyContent.destroy();
  96. MWF.release(this);
  97. }
  98. },
  99. loadTreeData: function(){
  100. var arrays = this.propertyContent.getElements(".MWFTreeData");
  101. arrays.each(function(node){
  102. var title = node.get("title");
  103. var name = node.get("name");
  104. var json = this.data[name];
  105. if (!json) json = [];
  106. MWF.require("MWF.widget.TreeEditor", function(){
  107. var treeEditor = new MWF.widget.TreeEditor(node, {
  108. "title": title,
  109. "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  110. "onChange": function(){
  111. this.data[name] = treeEditor.toJson();
  112. this.module.json[name] = this.data[name];
  113. this.module._refreshTree();
  114. }.bind(this)
  115. });
  116. treeEditor.load(json);
  117. }.bind(this));
  118. node.addEvent("keydown", function(e){e.stopPropagation();});
  119. }.bind(this));
  120. },
  121. loadJSONArea: function(){
  122. var jsonNode = this.propertyContent.getElement(".MWFJSONArea");
  123. if (jsonNode){
  124. this.propertyTab.pages.each(function(page){
  125. if (page.contentNode === jsonNode.parentElement){
  126. page.setOptions({
  127. "onShow": function(){
  128. jsonNode.empty();
  129. MWF.require("MWF.widget.JsonParse", function(){
  130. this.json = new MWF.widget.JsonParse(this.module.json, jsonNode, null);
  131. this.json.load();
  132. }.bind(this));
  133. }.bind(this)
  134. });
  135. }
  136. }.bind(this));
  137. }
  138. },
  139. loadHTMLArea: function(){
  140. var htmlNode = this.propertyContent.getElement(".MWFHTMLArea");
  141. if (htmlNode){
  142. var copy = this.module.node.clone(true, true);
  143. copy.clearStyles(true);
  144. htmlNode.set("text", copy.outerHTML);
  145. copy.destroy();
  146. this.propertyTab.pages.each(function(page){
  147. if (page.contentNode == htmlNode.parentElement){
  148. page.setOptions({
  149. "onShow": function(){
  150. var copy = this.module.node.clone(true, true);
  151. copy.clearStyles(true);
  152. //MWF.require("MWF.widget.HtmlEditor", function(){
  153. // debugger;
  154. // var editor = new MWF.widget.HtmlEditor(htmlNode);
  155. // editor.load(function(){
  156. // editor.editor.setValue(copy.outerHTML)
  157. // }.bind(this));
  158. //}.bind(this));
  159. o2.load("JSBeautifier_html", function(){
  160. htmlNode.set("text", html_beautify(copy.outerHTML, {"indent_size":1}));
  161. }.bind(this));
  162. MWF.widget.ace.load(function(){
  163. COMMON.AjaxModule.loadDom(COMMON.contentPath+"/res/framework/ace/src-min-noconflict/ext-static_highlight.js", function(){
  164. var highlight = ace.require("ace/ext/static_highlight");
  165. highlight(htmlNode, {mode: "ace/mode/html", theme: "ace/theme/eclipse", "fontSize": 16});
  166. }.bind(this));
  167. }.bind(this));
  168. copy.destroy();
  169. }.bind(this)
  170. });
  171. }
  172. }.bind(this));
  173. }
  174. },
  175. loadSidebarPosition: function(){
  176. var nodes = this.propertyContent.getElements(".MWFSidebarReposition");
  177. if (nodes.length){
  178. nodes.each(function(node){
  179. node.addEvent("click", function(){
  180. this.module.json.styles.top = "";
  181. this.module.loadPosition();
  182. }.bind(this));
  183. }.bind(this));
  184. }
  185. },
  186. loadFormSelect: function(){
  187. var formNodes = this.propertyContent.getElements(".MWFFormSelect");
  188. if (formNodes.length){
  189. this.getFormList(function(){
  190. formNodes.each(function(node){
  191. var select = new Element("select").inject(node);
  192. select.addEvent("change", function(e){
  193. this.setValue(e.target.getParent("div").get("name"), e.target.options[e.target.selectedIndex].value, select);
  194. }.bind(this));
  195. this.setFormSelectOptions(node, select);
  196. var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  197. refreshNode.addEvent("click", function(e){
  198. this.getFormList(function(){
  199. this.setFormSelectOptions(node, select);
  200. }.bind(this), true);
  201. }.bind(this));
  202. //select.addEvent("click", function(e){
  203. // this.setFormSelectOptions(node, select);
  204. //}.bind(this));
  205. }.bind(this));
  206. }.bind(this));
  207. }
  208. },
  209. setFormSelectOptions: function(node, select){
  210. var name = node.get("name");
  211. select.empty();
  212. var option = new Element("option", {"text": "none"}).inject(select);
  213. this.forms.each(function(form){
  214. var option = new Element("option", {
  215. "text": form.name,
  216. "value": form.id,
  217. "selected": (this.data[name]==form.id)
  218. }).inject(select);
  219. }.bind(this));
  220. },
  221. getFormList: function(callback, refresh){
  222. if (!this.forms || refresh){
  223. this.form.designer.actions.listForm(this.form.designer.application.id, function(json){
  224. this.forms = json.data;
  225. if (callback) callback();
  226. }.bind(this));
  227. }else{
  228. if (callback) callback();
  229. }
  230. },
  231. // clearStyles: function(node){
  232. // node.removeProperty("style");
  233. // var subNode = node.getFirst();
  234. // while (subNode){
  235. // this.clearStyles(subNode);
  236. // subNode = subNode.getNext();
  237. // }
  238. // },
  239. loadViewFilter: function(){
  240. var nodes = this.propertyContent.getElements(".MWFViewFilter");
  241. var filtrData = this.data.filterList;
  242. nodes.each(function(node){
  243. MWF.xDesktop.requireApp("query.ViewDesigner", "widget.ViewFilter", function(){
  244. var _slef = this;
  245. new MWF.xApplication.query.ViewDesigner.widget.ViewFilter(node, this.form.designer, {"filtrData": filtrData, "customData": null}, {
  246. "onChange": function(ids){
  247. var data = this.getData();
  248. _slef.changeJsonDate(["filterList"], data.data);
  249. //_slef.changeJsonDate(["data", "customFilterEntryList"], data.customData);
  250. }
  251. });
  252. }.bind(this));
  253. }.bind(this));
  254. },
  255. loadViewSelect: function(){
  256. var viewNodes = this.propertyContent.getElements(".MWFViewSelect");
  257. if (viewNodes.length){
  258. this.getViewList(function(){
  259. viewNodes.each(function(node){
  260. var select = new Element("select").inject(node);
  261. select.addEvent("change", function(e){
  262. var viewId = e.target.options[e.target.selectedIndex].value;
  263. var viewName = e.target.options[e.target.selectedIndex].get("text");
  264. this.setValue(e.target.getParent("div").get("name"), viewId);
  265. this.setValue(e.target.getParent("div").get("name")+"Name", viewName);
  266. }.bind(this));
  267. this.setViewSelectOptions(node, select);
  268. var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  269. refreshNode.addEvent("click", function(e){
  270. this.getViewList(function(){
  271. this.setViewSelectOptions(node, select);
  272. }.bind(this), true);
  273. }.bind(this));
  274. //select.addEvent("click", function(e){
  275. // this.setFormSelectOptions(node, select);
  276. //}.bind(this));
  277. }.bind(this));
  278. }.bind(this));
  279. }
  280. },
  281. setViewSelectOptions: function(node, select){
  282. var name = node.get("name");
  283. select.empty();
  284. var option = new Element("option", {"text": "none"}).inject(select);
  285. this.views.each(function(view){
  286. var option = new Element("option", {
  287. "text": view.name,
  288. "value": view.id,
  289. "selected": (this.data[name]==view.id)
  290. }).inject(select);
  291. }.bind(this));
  292. },
  293. getViewList: function(callback, refresh){
  294. if (!this.views || refresh){
  295. this.form.designer.actions.listView(this.form.designer.application.id, function(json){
  296. this.views = json.data;
  297. if (callback) callback();
  298. }.bind(this));
  299. }else{
  300. if (callback) callback();
  301. }
  302. },
  303. loadValidation: function(){
  304. var nodes = this.propertyContent.getElements(".MWFValidation");
  305. if (nodes.length){
  306. nodes.each(function(node){
  307. var name = node.get("name");
  308. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ValidationEditor", function(){
  309. var validationEditor = new MWF.xApplication.process.FormDesigner.widget.ValidationEditor(node, this.designer, {
  310. "onChange": function(){
  311. var data = validationEditor.getValidationData();
  312. this.data[name] = data;
  313. }.bind(this)
  314. });
  315. validationEditor.load(this.data[name])
  316. }.bind(this));
  317. //new MWF.xApplication.process.FormDesigner.widget.ValidationEditor(node, this.designer);
  318. }.bind(this));
  319. }
  320. },
  321. loadIconSelect: function(){
  322. var nodes = this.propertyContent.getElements(".MWFIcon");
  323. if (nodes.length){
  324. nodes.each(function(node){
  325. var id = node.get("name");
  326. var icon = this.data[id];
  327. var iconNode = new Element("div", {"styles": this.form.css.processIconNode}).inject(node);
  328. if (icon) iconNode.setStyles({"background": "url("+icon+") center center no-repeat"});
  329. var selectNode = new Element("div", {"styles": this.form.css.processIconSelectNode, "text": this.form.designer.lp.selectIcon}).inject(node);
  330. selectNode.addEvent("click", function(){
  331. this.selectIcon(node);
  332. }.bind(this));
  333. }.bind(this));
  334. }
  335. },
  336. selectIcon: function(node){
  337. if (!node.iconMenu){
  338. var iconSelectMenu = new MWF.widget.Menu(node, {"event": "click", "style": "processIcon"});
  339. iconSelectMenu.load();
  340. node.iconMenu = iconSelectMenu;
  341. var _self = this;
  342. for (var i=0; i<=48; i++){
  343. var icon = "/x_component_process_ProcessManager/$Explorer/default/processIcon/process_icon_"+i+".png";
  344. var item = iconSelectMenu.addMenuItem("", "click", function(){
  345. var id = node.get("name");
  346. var src = this.item.getElement("img").get("src");
  347. _self.data[id] = src;
  348. node.getFirst("div").setStyle("background-image", "url("+src+")");
  349. }, icon);
  350. item.iconName = icon;
  351. }
  352. }
  353. },
  354. loadLabelFlagSelect: function(){
  355. var nodes = this.propertyContent.getElements(".MWFLabelFlag");
  356. if (nodes.length){
  357. nodes.each(function(node){
  358. var id = node.get("name");
  359. var icon = this.data[id];
  360. var iconNode = new Element("div", {"styles": this.form.css.labelFlagNode}).inject(node);
  361. if (icon) iconNode.setStyles({"background": "url("+icon+") center center no-repeat"});
  362. var selectNode = new Element("div", {"styles": this.form.css.processIconSelectNode, "text": this.form.designer.lp.empty}).inject(node);
  363. selectNode.addEvent("click", function(e){
  364. var id = node.get("name");
  365. this.data[id] = "";
  366. node.getFirst("div").setStyle("background-image", "");
  367. this.changeData(id);
  368. e.stopPropagation();
  369. }.bind(this));
  370. var selectNode = new Element("div", {"styles": this.form.css.processIconSelectNode, "text": this.form.designer.lp.select}).inject(node);
  371. selectNode.addEvent("click", function(){
  372. this.selectLabelFlag(node);
  373. }.bind(this));
  374. }.bind(this));
  375. }
  376. },
  377. selectLabelFlag: function(node){
  378. if (!node.iconMenu){
  379. var iconSelectMenu = new MWF.widget.Menu(node, {"event": "click", "style": "labelFlag"});
  380. iconSelectMenu.load();
  381. node.iconMenu = iconSelectMenu;
  382. var _self = this;
  383. for (var i=1; i<=21; i++){
  384. var icon = "/x_component_process_FormDesigner/Module/Label/default/icon/flag/"+i+".png";
  385. var item = iconSelectMenu.addMenuItem("", "click", function(){
  386. var id = node.get("name");
  387. var src = this.item.getElement("img").get("src");
  388. _self.data[id] = src;
  389. node.getFirst("div").setStyle("background-image", "url("+src+")");
  390. _self.changeData(id);
  391. }, icon);
  392. item.iconName = icon;
  393. }
  394. }
  395. },
  396. loadImageClipper: function(){
  397. var nodes = this.propertyContent.getElements(".MWFImageClipper");
  398. if (nodes.length){
  399. nodes.each(function(node){
  400. var id = node.get("name");
  401. var selectNode = new Element("div", {"styles": this.form.css.processIconSelectNode, "text": this.form.designer.lp.selectImage}).inject(node);
  402. selectNode.addEvent("click", function(){
  403. this.selectImage(node, id);
  404. }.bind(this));
  405. }.bind(this));
  406. }
  407. },
  408. createUploadFileAreaNode: function(node, name){
  409. this.uploadFileAreaNode = new Element("div");
  410. var html = "<input name=\"file\" multiple type=\"file\" accept=\"images/*\" />";
  411. this.uploadFileAreaNode.set("html", html);
  412. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  413. this.fileUploadNode.addEvent("change", function(){
  414. //var fileId = attachment.data.id;
  415. var files = this.fileUploadNode.files;
  416. if (files.length){
  417. var count = files.length;
  418. for (var i = 0; i < files.length; i++) {
  419. var file = files.item(i);
  420. var formData = new FormData();
  421. formData.append('file', file);
  422. MWF.xDesktop.uploadImage(
  423. this.form.json.id,
  424. (this.module.form.moduleType=="page") ? "portalPage" : "processPlatformForm",
  425. formData,
  426. file,
  427. function(json){
  428. var id = json.id;
  429. var src = MWF.xDesktop.getImageSrc(id);
  430. var data = {"imageSrc": src, "imageId": id};
  431. this.changeJsonDate(name, data);
  432. this.changeData(name, node, null);
  433. }.bind(this)
  434. );
  435. }
  436. }
  437. }.bind(this));
  438. },
  439. selectImage: function(node, name){
  440. if (!this.uploadFileAreaNode){
  441. this.createUploadFileAreaNode(node, name);
  442. }
  443. //this.fileUploadNode.set("accept", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
  444. this.fileUploadNode.set("multiple", false);
  445. var fileNode = this.uploadFileAreaNode.getFirst();
  446. fileNode.set("accept", "images/*");
  447. fileNode.click();
  448. //MWF.xDesktop.requireApp("process.FormDesigner", "widget.ImageClipper", function(){
  449. // var size = this.module.node.getSize();
  450. // var image = new MWF.xApplication.process.FormDesigner.widget.ImageClipper(this.designer, {
  451. // "title": this.form.designer.lp.selectImage,
  452. // "width": (this.data.styles.width) ? size.x : 0,
  453. // "height": (this.data.styles.height) ? size.y : 0,
  454. // "imageUrl" : this.data.imageSrc,
  455. // "reference" : this.form.json.id,
  456. // "referenceType": (this.module.form.moduleType=="page") ? "portalPage" : "processPlatformForm",
  457. // "onChange": function(){
  458. // var data = {"imageSrc": image.imageSrc, "imageId": image.imageId};
  459. // this.changeJsonDate(name, data);
  460. // this.changeData(name, node, null);
  461. // }.bind(this)
  462. // });
  463. // image.load(this.data[name])
  464. //}.bind(this));
  465. },
  466. loadEventsEditor: function(){
  467. var events = this.propertyContent.getElement(".MWFEventsArea");
  468. if (events){
  469. var name = events.get("name");
  470. var eventsObj = this.data[name];
  471. MWF.xDesktop.requireApp("process.FormDesigner", "widget.EventsEditor", function(){
  472. var eventsEditor = new MWF.xApplication.process.FormDesigner.widget.EventsEditor(events, this.designer, {
  473. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  474. "maxObj": this.designer.formContentNode || this.designer.pageContentNode
  475. });
  476. eventsEditor.load(eventsObj, this.data, name);
  477. }.bind(this));
  478. }
  479. },
  480. testRestful: function(){
  481. var node = this.propertyContent.getElements(".MWFTestRestful");
  482. if (node){
  483. var resultNode = node.getLast();
  484. node.getFirst().addEvent("click", function(){
  485. }.bind(this));
  486. }
  487. },
  488. loadContextRoot: function(){
  489. var nodes = this.propertyContent.getElements(".MWFContextRoot");
  490. if (nodes){
  491. nodes.each(function(node){
  492. var name = node.get("name");
  493. var value = this.data[name];
  494. var select = new Element("select").inject(node);
  495. Object.each(layout.desktop.serviceAddressList, function(v, key){
  496. var option = new Element("option", {"value": key, "text": v.name, "selected": (value==key)}).inject(select);
  497. }.bind(this));
  498. select.addEvent("change", function(){
  499. var data = select.options[select.selectedIndex].value;
  500. this.changeJsonDate(name, data);
  501. this.changeData(name, node, value);
  502. }.bind(this));
  503. }.bind(this));
  504. }
  505. },
  506. loadSourceTestRestful: function(){
  507. var nodes = this.propertyContent.getElements(".MWFSourceTestRestful");
  508. if (nodes.length){
  509. nodes.each(function(node){
  510. var button = node.getFirst();
  511. var content = node.getLast();
  512. //var button = new Element("input", {"type": "button", "value": "Test"}).inject(node);
  513. button.addEvent("click", function(e){
  514. this.testSourceRestful(content);
  515. }.bind(this));
  516. }.bind(this));
  517. }
  518. },
  519. testSourceRestful: function(content){
  520. var address = this._getO2Address(this.module.json.contextRoot);
  521. var uri = this._getO2Uri(this.module, address);
  522. this._invoke(this.module, uri, function(json){
  523. content.empty();
  524. MWF.require("MWF.widget.JsonParse", function(){
  525. var jsonParse = new MWF.widget.JsonParse(json, content, null);
  526. jsonParse.load();
  527. }.bind(this));
  528. }.bind(this));
  529. },
  530. _getO2Address: function(contextRoot){
  531. var addressObj = layout.desktop.serviceAddressList[contextRoot];
  532. var address = "";
  533. if (addressObj){
  534. address = "http://"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+addressObj.context;
  535. }else{
  536. var host = layout.desktop.centerServer.host || window.location.hostname;
  537. var port = layout.desktop.centerServer.port;
  538. address = "http://"+host+(port=="80" ? "" : ":"+port)+"/x_program_center";
  539. }
  540. return address;
  541. },
  542. _getO2Uri: function(module, address){
  543. var uri = module.json.path;
  544. var pars = {};
  545. MWF.require("MWF.xScript.Macro", null, false);
  546. var macro = new MWF.Macro["PageContext"]({"businessData": {}, "json": {}, "options": {}});
  547. if (module.json.parameters){
  548. Object.each(module.json.parameters, function(v, key){
  549. if (uri.indexOf("{"+key+"}")!==-1){
  550. var reg = new RegExp("{"+key+"}", "g");
  551. uri = uri.replace(reg, encodeURIComponent((v && v.code) ? (macro.exec(v.code, this) || "") : v));
  552. }else{
  553. pars[key] = v;
  554. }
  555. }.bind(this));
  556. }
  557. var data = null;
  558. if (module.json.requestBody){
  559. if (module.json.requestBody.code){
  560. data = macro.exec(module.json.requestBody.code, this)
  561. }
  562. }
  563. if (module.json.httpMethod==="GET" || module.json.httpMethod==="OPTIONS" || module.json.httpMethod==="HEAD" || module.json.httpMethod==="DELETE"){
  564. var tag = "?";
  565. if (uri.indexOf("?")!==-1) tag = "&";
  566. Object.each(pars, function(v, k){
  567. var value = (v && v.code) ? (macro.exec(v.code, this) || "") : v;
  568. uri = uri+tag+k+"="+value;
  569. }.bind(this));
  570. }else{
  571. Object.each(pars, function(v, k){
  572. if (!data) data = {};
  573. var value = (v && v.code) ? (macro.exec(v.code, this) || "") : v;
  574. data[k] = value;
  575. }.bind(this));
  576. }
  577. this.body = data;
  578. return {"uri": address+uri, "body": data};
  579. },
  580. _invoke: function(module, uri, callback){
  581. MWF.restful(module.json.httpMethod, uri.uri, JSON.encode(uri.body), function(json){
  582. //this.data = json;
  583. if (callback) callback(json);
  584. }.bind(this), true, true);
  585. },
  586. loadUnitTypeSelector: function(){
  587. var nodes = this.propertyContent.getElements(".MWFFormUnitTypeSelector");
  588. if (nodes.length){
  589. this.getUnitTypeList(function(){
  590. nodes.each(function(node){
  591. var select = new Element("select").inject(node);
  592. select.addEvent("change", function(e){
  593. this.setValue(e.target.getParent("div").get("name"), e.target.options[e.target.selectedIndex].value);
  594. }.bind(this));
  595. this.setUnitTypeSelectOptions(node, select);
  596. this.setValue(select.getParent("div").get("name"), select.options[select.selectedIndex].value);
  597. // var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  598. // refreshNode.addEvent("click", function(e){
  599. // this.getUnitTypeList(function(){
  600. // this.setUnitTypeSelectOptions(node, select);
  601. // }.bind(this), true);
  602. // }.bind(this));
  603. }.bind(this));
  604. }.bind(this));
  605. }
  606. },
  607. setUnitTypeSelectOptions: function(node, select){
  608. var name = node.get("name");
  609. select.empty();
  610. var option = new Element("option", {"value":"all", "text": this.form.designer.lp.all, "selected": (!this.data[name] || this.data[name]==="all")}).inject(select);
  611. this.unitTypeList.each(function(unitType){
  612. var option = new Element("option", {
  613. "text": unitType,
  614. "value": unitType,
  615. "selected": (this.data[name]===unitType)
  616. }).inject(select);
  617. }.bind(this));
  618. },
  619. getUnitTypeList: function(callback, refresh){
  620. if (!this.unitTypeList || refresh){
  621. //MWF.xDesktop.requireApp("Org", "Actions.RestActions", function(){
  622. // var action = new MWF.xApplication.Org.Actions.RestActions();
  623. var action = MWF.Actions.get("x_organization_assemble_control");
  624. action.listUnitType(function(json){
  625. this.unitTypeList = json.data.valueList;
  626. if (callback) callback();
  627. }.bind(this));
  628. //}.bind(this));
  629. }else{
  630. if (callback) callback();
  631. }
  632. },
  633. loadParameterEditor: function(){
  634. var pars = this.propertyContent.getElements(".MWFParameterArea");
  635. if (pars){
  636. pars.each(function(par){
  637. var name = par.get("name");
  638. if (!this.data[name]) this.data[name] = {};
  639. var parObj = this.data[name];
  640. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ParameterEditor", function(){
  641. var parameterEditor = new MWF.xApplication.process.FormDesigner.widget.ParameterEditor(par, this.designer, {
  642. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  643. "maxObj": this.designer.formContentNode
  644. });
  645. parameterEditor.load(parObj, this.data, name);
  646. }.bind(this));
  647. }.bind(this));
  648. }
  649. },
  650. loadArrayList: function(){
  651. var arrays = this.propertyContent.getElements(".MWFArraylist");
  652. arrays.each(function(node){
  653. var title = node.get("title");
  654. var name = node.get("name");
  655. var arr = this.data[name];
  656. if (!arr) arr = [];
  657. MWF.require("MWF.widget.Arraylist", function(){
  658. var arraylist = new MWF.widget.Arraylist(node, {
  659. "title": title,
  660. "onChange": function(){
  661. this.data[name] = arraylist.toArray();
  662. }.bind(this)
  663. });
  664. arraylist.load(arr);
  665. }.bind(this));
  666. node.addEvent("keydown", function(e){e.stopPropagation();});
  667. }.bind(this));
  668. },
  669. loadHtmlEditorArea: function(){
  670. var htmlAreas = this.propertyContent.getElements(".MWFHtmlEditorArea");
  671. htmlAreas.each(function(node){
  672. var title = node.get("title");
  673. var name = node.get("name");
  674. var scriptContent = this.data[name];
  675. MWF.require("MWF.widget.HtmlEditorArea", function(){
  676. var htmlArea = new MWF.widget.HtmlEditorArea(node, {
  677. "title": title,
  678. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  679. "maxObj": this.designer.formContentNode,
  680. "onChange": function(){
  681. this.data[name] = htmlArea.getValue();
  682. this.changeData(name);
  683. }.bind(this),
  684. "onSave": function(){
  685. this.designer.saveForm();
  686. }.bind(this)
  687. });
  688. htmlArea.load({"code": scriptContent});
  689. }.bind(this));
  690. }.bind(this));
  691. },
  692. loadStylesList: function(){
  693. var styleSelNodes = this.propertyContent.getElements(".MWFFormStyle");
  694. styleSelNodes.each(function(node){
  695. if (this.module.form.stylesList){
  696. if (!this.data.formStyleType) this.data.formStyleType = "default";
  697. Object.each(this.module.form.stylesList, function(s, key){
  698. new Element("option", {
  699. "text": s.name,
  700. "value": key,
  701. "selected": ((!this.data.formStyleType && key=="default") || (this.data.formStyleType==key))
  702. }).inject(node)
  703. }.bind(this));
  704. }else{
  705. node.getParent("tr").setStyle("display", "none");
  706. }
  707. }.bind(this));
  708. },
  709. loadDivTemplateType: function(){
  710. var nodes = this.propertyContent.getElements(".MWFDivTemplate");
  711. if (nodes.length){
  712. var keys = [];
  713. if (this.module.form.stylesList) {
  714. if (this.module.form.stylesList[this.module.form.json.formStyleType]){
  715. var styles = this.module.form.stylesList[this.module.form.json.formStyleType][this.module.moduleName];
  716. if (styles) {
  717. Object.each(styles, function (v, k) {
  718. keys.push(k);
  719. }.bind(this));
  720. }
  721. }
  722. }
  723. nodes.each(function(node){
  724. node.empty();
  725. new Element("option", {
  726. "text": "default",
  727. "value": "default",
  728. "selected": (!this.data.templateType || this.data.templateType=="default")
  729. }).inject(node);
  730. if (keys.length){
  731. keys.each(function(k){
  732. new Element("option", {
  733. "text": styles[k].name,
  734. "value": k,
  735. "selected": (this.data.templateType==k)
  736. }).inject(node)
  737. }.bind(this));
  738. }else{
  739. node.getParent("tr").setStyle("display", "none");
  740. }
  741. }.bind(this));
  742. }
  743. },
  744. loadPersonInput: function(){
  745. var personIdentityNodes = this.propertyContent.getElements(".MWFPersonIdentity");
  746. var personUnitNodes = this.propertyContent.getElements(".MWFPersonUnit");
  747. var dutyNodes = this.propertyContent.getElements(".MWFDutySelector");
  748. var dutyNameNodes = this.propertyContent.getElements(".MWFPersonDuty");
  749. var viewNodes = this.propertyContent.getElements(".MWFViewSelect");
  750. var cmsviewNodes = this.propertyContent.getElements(".MWFCMSViewSelect");
  751. var queryviewNodes = this.propertyContent.getElements(".MWFQueryViewSelect");
  752. var querystatNodes = this.propertyContent.getElements(".MWFQueryStatSelect");
  753. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  754. personIdentityNodes.each(function(node){
  755. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  756. "type": "identity",
  757. "names": this.data[node.get("name")],
  758. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  759. });
  760. }.bind(this));
  761. personUnitNodes.each(function(node){
  762. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  763. "type": "unit",
  764. "names": this.data[node.get("name")],
  765. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  766. });
  767. }.bind(this));
  768. dutyNodes.each(function(node){
  769. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  770. "type": "duty",
  771. "names": this.data[node.get("name")],
  772. "onChange": function(ids){this.addDutyItem(node, ids);}.bind(this),
  773. "onRemoveDuty": function(item){this.removeDutyItem(node, item);}.bind(this)
  774. });
  775. }.bind(this));
  776. dutyNameNodes.each(function(node){
  777. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  778. "type": "dutyName",
  779. "names": this.data[node.get("name")],
  780. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  781. });
  782. }.bind(this));
  783. viewNodes.each(function(node){
  784. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  785. "type": "View",
  786. "count": 1,
  787. "names": [this.data[node.get("name")]],
  788. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  789. });
  790. }.bind(this));
  791. cmsviewNodes.each(function(node){
  792. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  793. "type": "CMSView",
  794. "count": 1,
  795. "names": [this.data[node.get("name")]],
  796. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  797. });
  798. }.bind(this));
  799. queryviewNodes.each(function(node){
  800. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  801. "type": "QueryView",
  802. "count": 1,
  803. "names": [this.data[node.get("name")]],
  804. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  805. });
  806. }.bind(this));
  807. querystatNodes.each(function(node){
  808. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  809. "type": "QueryStat",
  810. "count": 1,
  811. "names": [this.data[node.get("name")]],
  812. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  813. });
  814. }.bind(this));
  815. }.bind(this));
  816. },
  817. saveViewItem: function(node, ids){
  818. if (ids[0]){
  819. var view = ids[0].data;
  820. var data = {
  821. "name": view.name,
  822. "alias": view.alias,
  823. "id": view.id,
  824. "appName" : view.appName || view.applicationName || view.query,
  825. "appId": view.appId,
  826. "application": view.application || view.query
  827. };
  828. this.data[node.get("name")] = data;
  829. }else{
  830. this.data[node.get("name")] = null;
  831. }
  832. if (this.module._checkView) this.module._checkView();
  833. },
  834. removeViewItem: function(node, item){
  835. },
  836. removeDutyItem: function(node, item){
  837. if (item.data.id){
  838. var values = JSON.decode(this.data[node.get("name")] || []);
  839. var value = values.filter(function(v){
  840. return v.id == item.data.id;
  841. });
  842. value.each(function(v) {
  843. values = values.erase(v);
  844. });
  845. this.data[node.get("name")] = JSON.encode(values);
  846. }
  847. item.node.destroy();
  848. MWF.release(item);
  849. delete item;
  850. },
  851. addDutyItem: function(node, ids){
  852. var value = this.data[node.get("name")] || "";
  853. if (!value) value = "[]";
  854. var values = JSON.decode(value);
  855. ids.each(function(id){
  856. if (id.data.dutyId){
  857. for (var i=0; i<values.length; i++){
  858. if (values[i].dutyId===id.data.dutyId){
  859. values[i].name = id.data.name;
  860. values[i].code = id.data.code;
  861. break;
  862. }
  863. }
  864. }else{
  865. id.data.dutyId = new MWF.widget.UUID().toString();
  866. values.push({"name": id.data.name, "id": id.data.id, "dutyId": id.data.dutyId, "code": id.data.code});
  867. }
  868. }.bind(this));
  869. this.data[node.get("name")] = JSON.encode(values);
  870. },
  871. loadFormFieldInput: function(){
  872. var fieldNodes = this.propertyContent.getElements(".MWFFormFieldPerson");
  873. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  874. fieldNodes.each(function(node){
  875. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  876. "type": "formField",
  877. "application": this.form.json.application,
  878. "fieldType": "person",
  879. "names": this.data[node.get("name")],
  880. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  881. });
  882. }.bind(this));
  883. }.bind(this));
  884. },
  885. savePersonItem: function(node, ids){
  886. var values = [];
  887. ids.each(function(id){
  888. values.push(MWF.org.parseOrgData(id.data));
  889. }.bind(this));
  890. this.data[node.get("name")] = values;
  891. },
  892. loadScriptArea: function(){
  893. var scriptAreas = this.propertyContent.getElements(".MWFScriptArea");
  894. var formulaAreas = this.propertyContent.getElements(".MWFFormulaArea");
  895. this.loadScriptEditor(scriptAreas);
  896. this.loadScriptEditor(formulaAreas, "formula");
  897. },
  898. loadScriptEditor: function(scriptAreas, style){
  899. scriptAreas.each(function(node){
  900. var title = node.get("title");
  901. var name = node.get("name");
  902. if (!this.data[name]) this.data[name] = {"code": "", "html": ""};
  903. var scriptContent = this.data[name];
  904. MWF.require("MWF.widget.ScriptArea", function(){
  905. var scriptArea = new MWF.widget.ScriptArea(node, {
  906. "title": title,
  907. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  908. "maxObj": this.designer.formContentNode || this.designer.pageContentNode,
  909. "onChange": function(){
  910. //this.data[name] = scriptArea.toJson();
  911. if (!this.data[name]){
  912. this.data[name] = {"code": "", "html": ""};
  913. if (this.module.form.scriptDesigner) this.module.form.scriptDesigner.addScriptItem(this.data[name], "code", this.data, name);
  914. }
  915. var json = scriptArea.toJson();
  916. this.data[name].code = json.code;
  917. //this.data[name].html = json.html;
  918. }.bind(this),
  919. "onSave": function(){
  920. this.designer.saveForm();
  921. }.bind(this),
  922. "style": style || "default"
  923. });
  924. scriptArea.load(scriptContent);
  925. }.bind(this));
  926. }.bind(this));
  927. },
  928. loadCssArea: function(style){
  929. var cssAreas = this.propertyContent.getElements(".MWFCssArea");
  930. cssAreas.each(function(node){
  931. var title = node.get("title");
  932. var name = node.get("name");
  933. if (!this.data[name]) this.data[name] = {"code": "", "html": ""};
  934. var cssContent = this.data[name];
  935. MWF.require("MWF.widget.CssArea", function(){
  936. var cssArea = new MWF.widget.CssArea(node, {
  937. "title": title,
  938. "maxObj": this.designer.formContentNode || this.designer.pageContentNode,
  939. "onChange": function(){
  940. //this.data[name] = scriptArea.toJson();
  941. if (!this.data[name]){
  942. this.data[name] = {"code": "", "html": ""};
  943. if (this.module.form.scriptDesigner) this.module.form.scriptDesigner.addScriptItem(this.data[name], "code", this.data, name);
  944. }
  945. var json = cssArea.toJson();
  946. this.data[name].code = json.code;
  947. cssArea.isChanged = true;
  948. //this.data[name].html = json.html;
  949. }.bind(this),
  950. "onBlur": function(){
  951. if (cssArea.isChanged){
  952. this.changeData(name, node, "");
  953. cssArea.isChanged = false;
  954. }
  955. }.bind(this),
  956. "onSave": function(){
  957. this.designer.saveForm();
  958. }.bind(this),
  959. "style": style || "default"
  960. });
  961. cssArea.load(cssContent);
  962. }.bind(this));
  963. }.bind(this));
  964. },
  965. loadActionArea: function(){
  966. var actionAreas = this.propertyContent.getElements(".MWFActionArea");
  967. actionAreas.each(function(node){
  968. var name = node.get("name");
  969. var actionContent = this.data[name];
  970. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ActionsEditor", function(){
  971. // debugger;
  972. // var actionEditor = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor(node, this.designer, {
  973. // "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  974. // "noCreate": true,
  975. // "noDelete": true,
  976. // "noCode": true,
  977. // "onChange": function(){
  978. // this.data[name] = actionEditor.data;
  979. // }.bind(this)
  980. // });
  981. // actionEditor.load(this.module.defaultToolBarsData);
  982. var actionEditor = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor(node, this.designer, this.data, {
  983. "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  984. "onChange": function(){
  985. this.data[name] = actionEditor.data;
  986. this.changeData(name);
  987. }.bind(this)
  988. });
  989. actionEditor.load(actionContent);
  990. }.bind(this));
  991. }.bind(this));
  992. var actionAreas = this.propertyContent.getElements(".MWFDefaultActionArea");
  993. actionAreas.each(function(node){
  994. var name = node.get("name");
  995. var actionContent = this.data[name] || this.module.defaultToolBarsData;
  996. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ActionsEditor", function(){
  997. var actionEditor = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor(node, this.designer, this.data, {
  998. "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  999. "noCreate": true,
  1000. "noDelete": true,
  1001. "noCode": true,
  1002. "onChange": function(){
  1003. this.data[name] = actionEditor.data;
  1004. this.changeData(name);
  1005. }.bind(this)
  1006. });
  1007. actionEditor.load(actionContent);
  1008. // var actionEditor = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor(node, this.designer, {
  1009. // "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  1010. // "onChange": function(){
  1011. // this.data[name] = actionEditor.data;
  1012. // }.bind(this)
  1013. // });
  1014. // actionEditor.load(actionContent);
  1015. }.bind(this));
  1016. }.bind(this));
  1017. },
  1018. loadMaplist: function(){
  1019. var maplists = this.propertyContent.getElements(".MWFMaplist");
  1020. maplists.each(function(node){
  1021. var title = node.get("title");
  1022. var name = node.get("name");
  1023. var collapse = node.get("collapse");
  1024. var mapObj = this.data[name];
  1025. if (!mapObj) mapObj = {};
  1026. MWF.require("MWF.widget.Maplist", function(){
  1027. node.empty();
  1028. var maplist = new MWF.widget.Maplist(node, {
  1029. "title": title,
  1030. "collapse": (collapse) ? true : false,
  1031. "onChange": function(){
  1032. //this.data[name] = maplist.toJson();
  1033. //
  1034. var oldData = this.data[name];
  1035. this.changeJsonDate(name, maplist.toJson());
  1036. this.changeStyle(name, oldData);
  1037. this.changeData(name);
  1038. }.bind(this)
  1039. });
  1040. maplist.load(mapObj);
  1041. this.maplists[name] = maplist;
  1042. }.bind(this));
  1043. }.bind(this));
  1044. },
  1045. loadPropertyTab: function(){
  1046. var tabNodes = this.propertyContent.getElements(".MWFTab");
  1047. if (tabNodes.length){
  1048. var tmpNode = this.propertyContent.getFirst();
  1049. var tabAreaNode = new Element("div", {
  1050. "styles": this.form.css.propertyTabNode
  1051. }).inject(tmpNode, "before");
  1052. MWF.require("MWF.widget.Tab", function(){
  1053. var tab = new MWF.widget.Tab(tabAreaNode, {"style": "formPropertyList"});
  1054. tab.load();
  1055. var tabPages = [];
  1056. tabNodes.each(function(node){
  1057. var page = tab.addTab(node, node.get("title"), false);
  1058. tabPages.push(page);
  1059. page.contentScrollNode = new Element("div", {"styles": {"height": "100%", "overflow": "hidden"}}).inject(page.contentNodeArea);
  1060. node.inject(page.contentScrollNode);
  1061. this.setScrollBar(page.contentScrollNode, "small", null, null);
  1062. }.bind(this));
  1063. tabPages[0].showTab();
  1064. this.propertyTab = tab;
  1065. this.designer.resizeNode();
  1066. }.bind(this), false);
  1067. }
  1068. },
  1069. setEditNodeEvent: function(){
  1070. var property = this;
  1071. // var inputs = this.process.propertyListNode.getElements(".editTableInput");
  1072. var inputs = this.propertyContent.getElements("input");
  1073. inputs.each(function(input){
  1074. var jsondata = input.get("name");
  1075. if (this.module){
  1076. var id = this.data.pid;
  1077. //var id = this.form.json.id;
  1078. input.set("name", this.form.options.mode+id+jsondata);
  1079. }
  1080. if (jsondata){
  1081. var inputType = input.get("type").toLowerCase();
  1082. switch (inputType){
  1083. case "radio":
  1084. input.addEvent("change", function(e){
  1085. property.setRadioValue(jsondata, this);
  1086. });
  1087. input.addEvent("blur", function(e){
  1088. property.setRadioValue(jsondata, this);
  1089. });
  1090. input.addEvent("keydown", function(e){
  1091. e.stopPropagation();
  1092. });
  1093. property.setRadioValue(jsondata, input);
  1094. break;
  1095. case "checkbox":
  1096. input.addEvent("change", function(e){
  1097. property.setCheckboxValue(jsondata, this);
  1098. });
  1099. input.addEvent("click", function(e){
  1100. property.setCheckboxValue(jsondata, this);
  1101. });
  1102. input.addEvent("keydown", function(e){
  1103. e.stopPropagation();
  1104. });
  1105. break;
  1106. default:
  1107. input.addEvent("change", function(e){
  1108. property.setValue(jsondata, this.value, this);
  1109. });
  1110. input.addEvent("blur", function(e){
  1111. property.setValue(jsondata, this.value, this);
  1112. });
  1113. input.addEvent("keydown", function(e){
  1114. if (e.code==13){
  1115. property.setValue(jsondata, this.value, this);
  1116. }
  1117. e.stopPropagation();
  1118. });
  1119. }
  1120. }
  1121. }.bind(this));
  1122. var selects = this.propertyContent.getElements("select");
  1123. selects.each(function(select){
  1124. var jsondata = select.get("name");
  1125. if (jsondata){
  1126. select.addEvent("change", function(e){
  1127. property.setSelectValue(jsondata, this);
  1128. });
  1129. //property.setSelectValue(jsondata, select);
  1130. }
  1131. });
  1132. var textareas = this.propertyContent.getElements("textarea");
  1133. textareas.each(function(input){
  1134. var jsondata = input.get("name");
  1135. if (jsondata){
  1136. input.addEvent("change", function(e){
  1137. property.setValue(jsondata, this.value);
  1138. });
  1139. input.addEvent("blur", function(e){
  1140. property.setValue(jsondata, this.value);
  1141. });
  1142. input.addEvent("keydown", function(e){
  1143. e.stopPropagation();
  1144. });
  1145. }
  1146. }.bind(this));
  1147. },
  1148. changeStyle: function(name, oldData){
  1149. this.module.setPropertiesOrStyles(name, oldData);
  1150. },
  1151. changeData: function(name, input, oldValue){
  1152. this.module._setEditStyle(name, input, oldValue);
  1153. },
  1154. changeJsonDate: function(key, value){
  1155. if (typeOf(key)!=="array") key = [key];
  1156. var o = this.data;
  1157. var len = key.length-1;
  1158. key.each(function(n, i){
  1159. if (!o[n]) o[n] = {};
  1160. if (i<len) o = o[n];
  1161. }.bind(this));
  1162. o[key[len]] = value;
  1163. //this.data[key] = value;
  1164. },
  1165. setRadioValue: function(name, input){
  1166. if (input.checked){
  1167. var i = name.indexOf("*");
  1168. var names = (i==-1) ? name.split(".") : name.substr(i+1, name.length).split(".");
  1169. var value = input.value;
  1170. if (value=="false") value = false;
  1171. if (value=="true") value = true;
  1172. var oldValue = this.data;
  1173. for (var idx = 0; idx<names.length; idx++){
  1174. if (!oldValue[names[idx]]){
  1175. oldValue = null;
  1176. break;
  1177. }else{
  1178. oldValue = oldValue[names[idx]];
  1179. }
  1180. }
  1181. // var value = input.value;
  1182. // if (value==="false") value = false;
  1183. // if (value==="true") value = true;
  1184. //var oldValue = this.data[name];
  1185. this.changeJsonDate(names, value);
  1186. this.changeData(name, input, oldValue);
  1187. }
  1188. },
  1189. setCheckboxValue: function(name, input){
  1190. //var id = this.module.json.id;
  1191. //var id = this.form.json.id;
  1192. var id = this.data.pid;
  1193. var checkboxList = $$("input[name='"+this.form.options.mode+id+name+"']");
  1194. var values = [];
  1195. checkboxList.each(function(checkbox){
  1196. if (checkbox.get("checked")){
  1197. values.push(checkbox.value);
  1198. }
  1199. });
  1200. var oldValue = this.data[name];
  1201. //this.data[name] = values;
  1202. this.changeJsonDate(name, values);
  1203. this.changeData(name, input, oldValue);
  1204. },
  1205. setSelectValue: function(name, select){
  1206. var idx = select.selectedIndex;
  1207. var options = select.getElements("option");
  1208. var value = "";
  1209. if (options[idx]){
  1210. value = options[idx].get("value");
  1211. }
  1212. var oldValue = this.data[name];
  1213. //this.data[name] = value;
  1214. this.changeJsonDate(name, value);
  1215. this.changeData(name, select, oldValue);
  1216. },
  1217. setValue: function(name, value, obj){
  1218. if (name==="id"){
  1219. if (value!==this.module.json.id) {
  1220. if (!value) {
  1221. this.designer.notice(MWF.APPFD.LP.notNullId, "error", this.module.form.designer.propertyContentArea, {
  1222. x: "right",
  1223. y: "bottom"
  1224. });
  1225. obj.focus();
  1226. return false;
  1227. } else {
  1228. var check = this.module.form.checkModuleId(value, this.module.json.type);
  1229. if (check.elementConflict) {
  1230. this.designer.notice(MWF.APPFD.LP.repetitionsId, "error", this.module.form.designer.propertyContentArea, {
  1231. x: "right",
  1232. y: "bottom"
  1233. });
  1234. obj.focus();
  1235. return false;
  1236. } else {
  1237. var json = this.module.form.json.moduleList[this.module.json.id];
  1238. this.module.form.json.moduleList[value] = json;
  1239. delete this.module.form.json.moduleList[this.module.json.id];
  1240. }
  1241. }
  1242. // if (this.module.form.json.moduleList[value]){
  1243. // this.designer.notice(MWF.APPFD.LP.repetitionsId, "error", this.module.form.designer.propertyContentArea, {x:"right", y:"bottom"});
  1244. // obj.focus();
  1245. // return false;
  1246. // }else{
  1247. // var flag = false;
  1248. // if (this.module.form.subformList){
  1249. // Object.each(this.module.form.subformList, function(o, k){
  1250. // if (o.subformData.moduleList[value] && o.subformData.moduleList[value] ) flag = true;
  1251. // });
  1252. // }
  1253. // if (flag){
  1254. // this.designer.notice(MWF.APPFD.LP.repetitionsId, "error", this.module.form.designer.propertyContentArea, {x:"right", y:"bottom"});
  1255. // obj.focus();
  1256. // return false;
  1257. // }else{
  1258. // var json = this.module.form.json.moduleList[this.module.json.id];
  1259. // this.module.form.json.moduleList[value]=json;
  1260. // delete this.module.form.json.moduleList[this.module.json.id];
  1261. // }
  1262. // }
  1263. }
  1264. }
  1265. //var oldValue = this.data[name];
  1266. var names = name.split(".");
  1267. var oldValue = this.data;
  1268. for (var idx = 0; idx<names.length; idx++){
  1269. if (!oldValue[names[idx]]){
  1270. oldValue = null;
  1271. break;
  1272. }else{
  1273. oldValue = oldValue[names[idx]];
  1274. }
  1275. }
  1276. //this.data[name] = value;
  1277. this.changeJsonDate(names, value);
  1278. this.changeData(name, obj, oldValue);
  1279. },
  1280. setEditNodeStyles: function(node){
  1281. var nodes = node.getChildren();
  1282. if (nodes.length){
  1283. nodes.each(function(el){
  1284. var cName = el.get("class");
  1285. if (cName){
  1286. if (this.form.css[cName]) el.setStyles(this.form.css[cName]);
  1287. }
  1288. this.setEditNodeStyles(el);
  1289. }.bind(this));
  1290. }
  1291. },
  1292. loadScriptInput: function(){
  1293. var scriptNodes = this.propertyContent.getElements(".MWFScript");
  1294. scriptNodes.each(function(node){
  1295. MWF.require("MWF.widget.ScriptEditor", function(){
  1296. var script = new MWF.widget.ScriptEditor(node, {
  1297. "onPostSave": function(script){
  1298. this.saveScriptItem(node, script);
  1299. }.bind(this),
  1300. "onQueryDelete": function(script){
  1301. this.deleteScriptItem(node, script);
  1302. }.bind(this)
  1303. });
  1304. this.setScriptItems(script, node);
  1305. }.bind(this));
  1306. }.bind(this));
  1307. },
  1308. deleteScriptItem: function(node, script){
  1309. var jsondata = node.get("name");
  1310. this.data[jsondata].erase(script.data.id);
  1311. this.process.scripts[script.data.id] = null;
  1312. delete this.process.scripts[script.data.id];
  1313. this.process.process.scriptList.erase(script.data);
  1314. },
  1315. saveScriptItem: function(node, script){
  1316. var jsondata = node.get("name");
  1317. var scriptList = this.data[jsondata];
  1318. var data = script.data;
  1319. var scriptData = this.process.scripts[script.data.id];
  1320. if (!scriptData){
  1321. this.process.process.scriptList.push(data);
  1322. this.process.scripts[script.data.id] = data;
  1323. }
  1324. if (scriptList.indexOf(data.id) == -1){
  1325. this.data[jsondata].push(data.id);
  1326. }
  1327. },
  1328. setScriptItems: function(script, node){
  1329. var jsondata = node.get("name");
  1330. var scriptList = this.data[jsondata];
  1331. scriptList.each(function(id){
  1332. if (id){
  1333. var data = this.process.scripts[id];
  1334. if (data) script.setScriptItem(data);
  1335. }
  1336. }.bind(this));
  1337. }
  1338. });
  1339. MWF.xApplication.process.FormDesigner.PropertyMulti = new Class({
  1340. Extends: MWF.xApplication.process.FormDesigner.Property,
  1341. Implements: [Options, Events],
  1342. initialize: function(form, modules, propertyNode, designer, options){
  1343. this.setOptions(options);
  1344. this.modules = modules;
  1345. this.form = form;
  1346. // this.data = module.json;
  1347. this.data = {};
  1348. this.htmlPath = this.options.path;
  1349. this.designer = designer;
  1350. this.maplists = {};
  1351. this.propertyNode = propertyNode;
  1352. },
  1353. load: function(){
  1354. if (this.fireEvent("queryLoad")){
  1355. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  1356. this.htmlString = responseText;
  1357. MWF.require("MWF.widget.JsonTemplate", function(){
  1358. this.fireEvent("postLoad");
  1359. }.bind(this));
  1360. }.bind(this));
  1361. }
  1362. },
  1363. show: function(){
  1364. if (!this.propertyContent){
  1365. if (this.htmlString){
  1366. this.JsonTemplate = new MWF.widget.JsonTemplate({}, this.htmlString);
  1367. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyNode);
  1368. this.propertyContent.set("html", this.JsonTemplate.load());
  1369. this.setEditNodeEvent();
  1370. this.setEditNodeStyles(this.propertyContent);
  1371. this.loadPropertyTab();
  1372. this.loadMaplist();
  1373. this.loadScriptArea();
  1374. this.loadTreeData();
  1375. this.loadArrayList();
  1376. //this.loadEventsEditor();
  1377. //this.loadHTMLArea();
  1378. //this.loadJSONArea();
  1379. // this.loadScriptInput();
  1380. //MWF.process.widget.EventsEditor
  1381. }
  1382. }else{
  1383. this.propertyContent.setStyle("display", "block");
  1384. }
  1385. },
  1386. hide: function(){
  1387. if (this.propertyContent) this.propertyContent.destroy();
  1388. },
  1389. changeStyle: function(name){
  1390. this.modules.each(function(module){
  1391. module.setPropertiesOrStyles(name);
  1392. }.bind(this));
  1393. },
  1394. changeData: function(name, input, oldValue){
  1395. this.modules.each(function(module){
  1396. module._setEditStyle(name, input, oldValue);
  1397. }.bind(this));
  1398. },
  1399. changeJsonDate: function(key, value){
  1400. //alert(key+": "+value );
  1401. this.modules.each(function(module){
  1402. module.json[key] = value;
  1403. }.bind(this));
  1404. },
  1405. });