Property.js 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347
  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.options.mode+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.loadActionStylesArea();
  65. this.loadHTMLArea();
  66. this.loadJSONArea();
  67. this.loadFormSelect();
  68. this.loadSubformSelect();
  69. //this.loadPageSelect();
  70. this.loadWidgetSelect();
  71. this.loadANNModelSelect();
  72. //this.loadViewSelect();
  73. this.loadValidation();
  74. this.loadIconSelect();
  75. this.loadLabelFlagSelect();
  76. this.loadImageClipper();
  77. this.loadImageFileSelect();
  78. this.loadParameterEditor();
  79. this.loadContextRoot();
  80. this.loadUnitTypeSelector();
  81. this.loadSourceTestRestful();
  82. this.loadSidebarPosition();
  83. this.loadViewFilter();
  84. this.loadDocumentTempleteSelect();
  85. // this.loadScriptIncluder();
  86. // this.loadDictionaryIncluder();
  87. //this.testRestful();
  88. // this.loadScriptInput();
  89. //MWF.process.widget.EventsEditor
  90. }
  91. }.bind(this));
  92. }else{
  93. this.propertyContent.setStyle("display", "block");
  94. }
  95. (new Fx.Scroll(layout.desktop.node)).toTop();
  96. },
  97. hide: function(){
  98. //this.JsonTemplate = null;
  99. //this.propertyNode.set("html", "");
  100. if (this.propertyContent) this.propertyContent.setStyle("display", "none");
  101. },
  102. destroy: function(){
  103. if (this.propertyContent){
  104. this.propertyContent.destroy();
  105. }
  106. MWF.release(this);
  107. },
  108. loadTreeData: function(){
  109. var arrays = this.propertyContent.getElements(".MWFTreeData");
  110. arrays.each(function(node){
  111. var title = node.get("title");
  112. var name = node.get("name");
  113. var json = this.data[name];
  114. if (!json) json = [];
  115. MWF.require("MWF.widget.TreeEditor", function(){
  116. var treeEditor = new MWF.widget.TreeEditor(node, {
  117. "title": title,
  118. "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  119. "onChange": function(){
  120. this.data[name] = treeEditor.toJson();
  121. this.module.json[name] = this.data[name];
  122. this.module._refreshTree();
  123. }.bind(this)
  124. });
  125. treeEditor.load(json);
  126. }.bind(this));
  127. node.addEvent("keydown", function(e){e.stopPropagation();});
  128. }.bind(this));
  129. },
  130. loadJSONArea: function(){
  131. var jsonNode = this.propertyContent.getElement(".MWFJSONArea");
  132. if (jsonNode){
  133. this.propertyTab.pages.each(function(page){
  134. if (page.contentNode === jsonNode.parentElement){
  135. page.setOptions({
  136. "onShow": function(){
  137. jsonNode.empty();
  138. MWF.require("MWF.widget.JsonParse", function(){
  139. this.json = new MWF.widget.JsonParse(this.module.json, jsonNode, null);
  140. this.json.load();
  141. }.bind(this));
  142. }.bind(this)
  143. });
  144. }
  145. }.bind(this));
  146. }
  147. },
  148. loadHTMLArea: function(){
  149. var htmlNode = this.propertyContent.getElement(".MWFHTMLArea");
  150. if (htmlNode){
  151. var copy = this.module.node.clone(true, true);
  152. copy.clearStyles(true);
  153. htmlNode.set("text", copy.outerHTML);
  154. copy.destroy();
  155. this.propertyTab.pages.each(function(page){
  156. if (page.contentNode == htmlNode.parentElement){
  157. page.setOptions({
  158. "onShow": function(){
  159. var copy = this.module.node.clone(true, true);
  160. copy.clearStyles(true);
  161. //MWF.require("MWF.widget.HtmlEditor", function(){
  162. // debugger;
  163. // var editor = new MWF.widget.HtmlEditor(htmlNode);
  164. // editor.load(function(){
  165. // editor.editor.setValue(copy.outerHTML)
  166. // }.bind(this));
  167. //}.bind(this));
  168. o2.load("JSBeautifier_html", function(){
  169. htmlNode.set("text", html_beautify(copy.outerHTML, {"indent_size":1}));
  170. }.bind(this));
  171. o2.require("o2.widget.ace", function(){
  172. MWF.widget.ace.load(function(){
  173. COMMON.AjaxModule.loadDom("../o2_lib/ace/src-min-noconflict/ext-static_highlight.js", function(){
  174. var highlight = ace.require("ace/ext/static_highlight");
  175. highlight(htmlNode, {mode: "ace/mode/html", theme: "ace/theme/eclipse", "fontSize": 16});
  176. }.bind(this));
  177. }.bind(this));
  178. }.bind(this));
  179. copy.destroy();
  180. }.bind(this)
  181. });
  182. }
  183. }.bind(this));
  184. }
  185. },
  186. loadSidebarPosition: function(){
  187. var nodes = this.propertyContent.getElements(".MWFSidebarReposition");
  188. if (nodes.length){
  189. nodes.each(function(node){
  190. node.addEvent("click", function(){
  191. this.module.json.styles.top = "";
  192. this.module.loadPosition();
  193. }.bind(this));
  194. }.bind(this));
  195. }
  196. },
  197. loadANNModelSelect: function(){
  198. var nodes = this.propertyContent.getElements(".MWFANNModelSelect");
  199. if (nodes.length){
  200. this.getModelList(function(){
  201. nodes.each(function(node){
  202. var select = new Element("select").inject(node);
  203. select.addEvent("change", function(e){
  204. this.setValue(e.target.getParent("div").get("name"), e.target.options[e.target.selectedIndex].value, select);
  205. }.bind(this));
  206. this.setModelSelectOptions(node, select);
  207. var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  208. refreshNode.addEvent("click", function(e){
  209. this.getModelList(function(){
  210. this.setModelSelectOptions(node, select);
  211. }.bind(this), true);
  212. }.bind(this));
  213. }.bind(this));
  214. }.bind(this));
  215. }
  216. },
  217. getModelList: function(callback, refresh){
  218. if (!this.models || refresh){
  219. var action = o2.Actions.get("x_query_assemble_designer");
  220. if (action.listModel) action.listModel(function(json){
  221. this.models = json.data;
  222. if (callback) callback();
  223. }.bind(this));
  224. }else{
  225. if (callback) callback();
  226. }
  227. },
  228. setModelSelectOptions: function(node, select){
  229. var name = node.get("name");
  230. select.empty();
  231. var option = new Element("option", {"text": "none"}).inject(select);
  232. this.models.each(function(model){
  233. var option = new Element("option", {
  234. "text": model.name,
  235. "value": model.id,
  236. "selected": (this.data[name]==model.id)
  237. }).inject(select);
  238. }.bind(this));
  239. },
  240. loadFormSelect: function(){
  241. var formNodes = this.propertyContent.getElements(".MWFFormSelect");
  242. if (formNodes.length){
  243. this.getFormList(function(){
  244. formNodes.each(function(node){
  245. var select = new Element("select").inject(node);
  246. select.addEvent("change", function(e){
  247. var value = e.target.options[e.target.selectedIndex].value;
  248. this.setValue(e.target.getParent("div").get("name"), value, select);
  249. }.bind(this));
  250. this.setFormSelectOptions(node, select);
  251. var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  252. refreshNode.addEvent("click", function(e){
  253. this.getFormList(function(){
  254. this.setFormSelectOptions(node, select);
  255. }.bind(this), true);
  256. }.bind(this));
  257. //select.addEvent("click", function(e){
  258. // this.setFormSelectOptions(node, select);
  259. //}.bind(this));
  260. }.bind(this));
  261. }.bind(this));
  262. }
  263. },
  264. setFormSelectOptions: function(node, select){
  265. var name = node.get("name");
  266. select.empty();
  267. var option = new Element("option", {"text": "none"}).inject(select);
  268. this.forms.each(function(form){
  269. if( this.form.json.id !== form.id ){
  270. var option = new Element("option", {
  271. "text": form.name,
  272. "value": form.id,
  273. "selected": (this.data[name]==form.id)
  274. }).inject(select);
  275. }
  276. }.bind(this));
  277. },
  278. getFormList: function(callback, refresh){
  279. if (!this.forms || refresh){
  280. this.form.designer.actions.listForm(this.form.designer.application.id, function(json){
  281. this.forms = json.data;
  282. if (callback) callback();
  283. }.bind(this));
  284. }else{
  285. if (callback) callback();
  286. }
  287. },
  288. loadSubformSelect: function(){
  289. var subformContainers = this.propertyContent.getElements(".MWFSubFormSelectContainer");
  290. if (subformContainers.length){
  291. subformContainers.each( function( container ){
  292. var appSelectNode = container.getElement(".MWFSubformAppSelect");
  293. var formSelectNode = container.getElement(".MWFSubformSelect");
  294. var formSelect;
  295. var appNodeName = appSelectNode.get("name");
  296. var formNodeName = formSelectNode.get("name");
  297. this.loadProcessApplictionSelect( appSelectNode, appNodeName, function( apps ){
  298. var oldValue = this.data[appNodeName] || "";
  299. this.data[appNodeName] = !apps.length ? "" : apps[0].data.id;
  300. if( oldValue !== this.data[appNodeName] ){
  301. this.getSubFormList(function(){
  302. this.setSubformSelectOptions(formSelectNode, formSelect);
  303. formSelect.fireEvent("change");
  304. }.bind(this), true, appNodeName);
  305. }
  306. }.bind(this));
  307. formSelect = this._loadSubformSelect( formSelectNode, formNodeName, appNodeName ) ;
  308. }.bind(this))
  309. }
  310. },
  311. loadProcessApplictionSelect : function( node, appNodeName, callback ){
  312. var application = appNodeName ? this.data[appNodeName] : "";
  313. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function() {
  314. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  315. "title" : this.form.designer.lp.selectApplication,
  316. "type": "application",
  317. "count" : 1,
  318. "names": application ? [ {id : application} ] : [],
  319. "onChange": function (apps) {
  320. callback(apps)
  321. }.bind(this)
  322. });
  323. }.bind(this))
  324. },
  325. _loadSubformSelect : function( node, formNodeName, appNodeName ){
  326. var select;
  327. this.getSubFormList(function(){
  328. select = new Element("select").inject(node);
  329. select.addEvent("change", function(e){
  330. var value = select.options[select.selectedIndex].value;
  331. this.setValue(formNodeName, value, select);
  332. }.bind(this));
  333. this.setSubformSelectOptions(node, select);
  334. var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  335. refreshNode.addEvent("click", function(e){
  336. this.getSubFormList(function(){
  337. this.setSubformSelectOptions(node, select);
  338. }.bind(this), true, appNodeName);
  339. }.bind(this));
  340. }.bind(this), false, appNodeName );
  341. return select;
  342. },
  343. setSubformSelectOptions: function(node, select){
  344. var name = node.get("name");
  345. select.empty();
  346. var option = new Element("option", {"text": "none"}).inject(select);
  347. this.subforms.each(function(subforms){
  348. if( this.form.json.id !== subforms.id ){
  349. var option = new Element("option", {
  350. "text": subforms.name,
  351. "value": subforms.id,
  352. "selected": (this.data[name]==subforms.id)
  353. }).inject(select);
  354. }
  355. }.bind(this));
  356. },
  357. getSubFormList: function(callback, refresh, appNodeName){
  358. var application = appNodeName ? this.data[appNodeName] : "";
  359. if (!this.subforms || refresh){
  360. this.form.designer.actions.listForm( application || this.form.designer.application.id, function(json){
  361. this.subforms = json.data;
  362. if (callback) callback();
  363. }.bind(this), null, false);
  364. }else{
  365. if (callback) callback();
  366. }
  367. },
  368. loadPageSelect: function(){
  369. var pageNodes = this.propertyContent.getElements(".MWFPageSelect");
  370. if (pageNodes.length){
  371. this.getPageList(function(){
  372. pageNodes.each(function(node){
  373. var select = new Element("select").inject(node);
  374. select.addEvent("change", function(e){
  375. var value = e.target.options[e.target.selectedIndex].value;
  376. this.setValue(e.target.getParent("div").get("name"), value, select);
  377. }.bind(this));
  378. this.setPageSelectOptions(node, select);
  379. var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  380. refreshNode.addEvent("click", function(e){
  381. this.getPageList(function(){
  382. this.setPageSelectOptions(node, select);
  383. }.bind(this), true);
  384. }.bind(this));
  385. }.bind(this));
  386. }.bind(this));
  387. }
  388. },
  389. setPageSelectOptions: function(node, select){
  390. var name = node.get("name");
  391. select.empty();
  392. var option = new Element("option", {"text": "none"}).inject(select);
  393. this.pages.each(function(page){
  394. if( this.form.json.id !== page.id ){
  395. var option = new Element("option", {
  396. "text": page.name,
  397. "value": page.id,
  398. "selected": (this.data[name]==page.id)
  399. }).inject(select);
  400. }
  401. }.bind(this));
  402. },
  403. getPageList: function(callback, refresh){
  404. if (!this.pages || refresh){
  405. this.form.designer.actions.listPage(this.form.designer.application.id, function(json){
  406. this.pages = json.data;
  407. if (callback) callback();
  408. }.bind(this));
  409. }else{
  410. if (callback) callback();
  411. }
  412. },
  413. loadWidgetSelect: function(){
  414. var widgetNodes = this.propertyContent.getElements(".MWFWidgetSelect");
  415. if (widgetNodes.length){
  416. this.getWidgetList(function(){
  417. widgetNodes.each(function(node){
  418. var select = new Element("select").inject(node);
  419. select.addEvent("change", function(e){
  420. var value = e.target.options[e.target.selectedIndex].value;
  421. this.setValue(e.target.getParent("div").get("name"), value, select);
  422. }.bind(this));
  423. this.setWidgetSelectOptions(node, select);
  424. var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  425. refreshNode.addEvent("click", function(e){
  426. this.getWidgetList(function(){
  427. this.setWidgetSelectOptions(node, select);
  428. }.bind(this), true);
  429. }.bind(this));
  430. }.bind(this));
  431. }.bind(this));
  432. }
  433. },
  434. setWidgetSelectOptions: function(node, select){
  435. var name = node.get("name");
  436. select.empty();
  437. var option = new Element("option", {"text": "none"}).inject(select);
  438. this.widgets.each(function(widget){
  439. if( this.form.json.id !== widget.id ){
  440. var option = new Element("option", {
  441. "text": widget.name,
  442. "value": widget.id,
  443. "selected": (this.data[name]==widget.id)
  444. }).inject(select);
  445. }
  446. }.bind(this));
  447. },
  448. getWidgetList: function(callback, refresh){
  449. if (!this.widgets || refresh){
  450. this.form.designer.actions.listWidget(this.form.designer.application.id, function(json){
  451. this.widgets = json.data;
  452. if (callback) callback();
  453. }.bind(this));
  454. }else{
  455. if (callback) callback();
  456. }
  457. },
  458. // clearStyles: function(node){
  459. // node.removeProperty("style");
  460. // var subNode = node.getFirst();
  461. // while (subNode){
  462. // this.clearStyles(subNode);
  463. // subNode = subNode.getNext();
  464. // }
  465. // },
  466. loadDocumentTempleteSelect: function(){
  467. var nodes = this.propertyContent.getElements(".MWFDocumentTempleteSelect");
  468. if (nodes.length){
  469. o2.getJSON("../x_component_process_FormDesigner/Module/Documenteditor/templete/templete.json", function(json){
  470. nodes.each(function(node){
  471. var name = node.get("name");
  472. Object.each(json, function(o, k){
  473. new Element("option", {
  474. "text": o.name,
  475. "value": k,
  476. "selected": (this.data[name]==k)
  477. }).inject(node);
  478. }.bind(this));
  479. node.addEvent("change", function(e){
  480. var oldValue = this.data[name];
  481. var value = e.target.options[e.target.selectedIndex].value;
  482. var name = e.target.options[e.target.selectedIndex].get("text");
  483. this.changeJsonDate([name], value);
  484. this.changeData(name, node, oldValue);
  485. }.bind(this));
  486. }.bind(this));
  487. }.bind(this));
  488. }
  489. },
  490. loadStatementFilter: function(){
  491. var nodes = this.propertyContent.getElements(".MWFStatementFilter");
  492. var filtrData = this.data.filterList;
  493. nodes.each(function(node){
  494. MWF.xDesktop.requireApp("query.StatementDesigner", "widget.ViewFilter", function(){
  495. var _slef = this;
  496. new MWF.xApplication.query.StatementDesigner.widget.ViewFilter(node, this.form.designer, {"filtrData": filtrData, "customData": null}, {
  497. "onChange": function(ids){
  498. var data = this.getData();
  499. _slef.changeJsonDate(["filterList"], data.data);
  500. //_slef.changeJsonDate(["data", "customFilterEntryList"], data.customData);
  501. }
  502. });
  503. }.bind(this));
  504. }.bind(this));
  505. },
  506. loadViewFilter: function(){
  507. var nodes = this.propertyContent.getElements(".MWFViewFilter");
  508. var filtrData = this.data.filterList;
  509. nodes.each(function(node){
  510. MWF.xDesktop.requireApp("query.ViewDesigner", "widget.ViewFilter", function(){
  511. var _slef = this;
  512. new MWF.xApplication.query.ViewDesigner.widget.ViewFilter(node, this.form.designer, {"filtrData": filtrData, "customData": null}, {
  513. "onChange": function(ids){
  514. var data = this.getData();
  515. _slef.changeJsonDate(["filterList"], data.data);
  516. //_slef.changeJsonDate(["data", "customFilterEntryList"], data.customData);
  517. }
  518. });
  519. }.bind(this));
  520. }.bind(this));
  521. },
  522. loadViewSelect: function(){
  523. var viewNodes = this.propertyContent.getElements(".MWFViewSelect");
  524. if (viewNodes.length){
  525. this.getViewList(function(){
  526. viewNodes.each(function(node){
  527. var select = new Element("select").inject(node);
  528. select.addEvent("change", function(e){
  529. var viewId = e.target.options[e.target.selectedIndex].value;
  530. var viewName = e.target.options[e.target.selectedIndex].get("text");
  531. this.setValue(e.target.getParent("div").get("name"), viewId);
  532. this.setValue(e.target.getParent("div").get("name")+"Name", viewName);
  533. }.bind(this));
  534. this.setViewSelectOptions(node, select);
  535. var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  536. refreshNode.addEvent("click", function(e){
  537. this.getViewList(function(){
  538. this.setViewSelectOptions(node, select);
  539. }.bind(this), true);
  540. }.bind(this));
  541. //select.addEvent("click", function(e){
  542. // this.setFormSelectOptions(node, select);
  543. //}.bind(this));
  544. }.bind(this));
  545. }.bind(this));
  546. }
  547. },
  548. setViewSelectOptions: function(node, select){
  549. var name = node.get("name");
  550. select.empty();
  551. var option = new Element("option", {"text": "none"}).inject(select);
  552. this.views.each(function(view){
  553. var option = new Element("option", {
  554. "text": view.name,
  555. "value": view.id,
  556. "selected": (this.data[name]==view.id)
  557. }).inject(select);
  558. }.bind(this));
  559. },
  560. getViewList: function(callback, refresh){
  561. if (!this.views || refresh){
  562. this.form.designer.actions.listView(this.form.designer.application.id, function(json){
  563. this.views = json.data;
  564. if (callback) callback();
  565. }.bind(this));
  566. }else{
  567. if (callback) callback();
  568. }
  569. },
  570. loadValidation: function(){
  571. var nodes = this.propertyContent.getElements(".MWFValidation");
  572. if (nodes.length){
  573. nodes.each(function(node){
  574. var name = node.get("name");
  575. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ValidationEditor", function(){
  576. var validationEditor = new MWF.xApplication.process.FormDesigner.widget.ValidationEditor(node, this.designer, {
  577. "onChange": function(){
  578. var data = validationEditor.getValidationData();
  579. this.data[name] = data;
  580. }.bind(this)
  581. });
  582. validationEditor.load(this.data[name])
  583. }.bind(this));
  584. //new MWF.xApplication.process.FormDesigner.widget.ValidationEditor(node, this.designer);
  585. }.bind(this));
  586. }
  587. },
  588. loadIconSelect: function(){
  589. var nodes = this.propertyContent.getElements(".MWFIcon");
  590. if (nodes.length){
  591. nodes.each(function(node){
  592. var id = node.get("name");
  593. var icon = this.data[id];
  594. var iconNode = new Element("div", {"styles": this.form.css.processIconNode}).inject(node);
  595. if (icon) iconNode.setStyles({"background": "url("+icon+") center center no-repeat"});
  596. var selectNode = new Element("div", {"styles": this.form.css.processIconSelectNode, "text": this.form.designer.lp.selectIcon}).inject(node);
  597. selectNode.addEvent("click", function(){
  598. this.selectIcon(node);
  599. }.bind(this));
  600. }.bind(this));
  601. }
  602. },
  603. selectIcon: function(node){
  604. if (!node.iconMenu){
  605. var iconSelectMenu = new MWF.widget.Menu(node, {"event": "click", "style": "processIcon"});
  606. iconSelectMenu.load();
  607. node.iconMenu = iconSelectMenu;
  608. var _self = this;
  609. for (var i=0; i<=48; i++){
  610. var icon = "../x_component_process_ProcessManager/$Explorer/default/processIcon/process_icon_"+i+".png";
  611. var item = iconSelectMenu.addMenuItem("", "click", function(){
  612. var id = node.get("name");
  613. var src = this.item.getElement("img").get("src");
  614. _self.data[id] = src;
  615. node.getFirst("div").setStyle("background-image", "url("+src+")");
  616. }, icon);
  617. item.iconName = icon;
  618. }
  619. }
  620. },
  621. loadLabelFlagSelect: function(){
  622. var nodes = this.propertyContent.getElements(".MWFLabelFlag");
  623. if (nodes.length){
  624. nodes.each(function(node){
  625. var id = node.get("name");
  626. var icon = this.data[id];
  627. var iconNode = new Element("div", {"styles": this.form.css.labelFlagNode}).inject(node);
  628. if (icon) iconNode.setStyles({"background": "url("+icon+") center center no-repeat"});
  629. var selectNode = new Element("div", {"styles": this.form.css.processIconSelectNode, "text": this.form.designer.lp.empty}).inject(node);
  630. selectNode.addEvent("click", function(e){
  631. var id = node.get("name");
  632. this.data[id] = "";
  633. node.getFirst("div").setStyle("background-image", "");
  634. this.changeData(id);
  635. e.stopPropagation();
  636. }.bind(this));
  637. var selectNode = new Element("div", {"styles": this.form.css.processIconSelectNode, "text": this.form.designer.lp.select}).inject(node);
  638. selectNode.addEvent("click", function(){
  639. this.selectLabelFlag(node);
  640. }.bind(this));
  641. }.bind(this));
  642. }
  643. },
  644. selectLabelFlag: function(node){
  645. if (!node.iconMenu){
  646. var iconSelectMenu = new MWF.widget.Menu(node, {"event": "click", "style": "labelFlag"});
  647. iconSelectMenu.load();
  648. node.iconMenu = iconSelectMenu;
  649. var _self = this;
  650. for (var i=1; i<=21; i++){
  651. var icon = "../x_component_process_FormDesigner/Module/Label/default/icon/flag/"+i+".png";
  652. var item = iconSelectMenu.addMenuItem("", "click", function(){
  653. var id = node.get("name");
  654. var src = this.item.getElement("img").get("src");
  655. _self.data[id] = src;
  656. node.getFirst("div").setStyle("background-image", "url("+src+")");
  657. _self.changeData(id);
  658. }, icon);
  659. item.iconName = icon;
  660. }
  661. }
  662. },
  663. loadImageFileSelect: function(){
  664. // var nodes = this.propertyContent.getElements(".MWFImageFileSelect");
  665. // if (nodes.length){
  666. //
  667. //
  668. //
  669. //
  670. // this.getFileList(function(){
  671. // nodes.each(function(node){
  672. // var select = new Element("select").inject(node);
  673. // select.addEvent("change", function(e){
  674. // this.setValue(e.target.getParent("div").get("name"), e.target.options[e.target.selectedIndex].value, select);
  675. //
  676. // }.bind(this));
  677. // this.setFileSelectOptions(node, select);
  678. //
  679. // var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  680. // refreshNode.addEvent("click", function(e){
  681. // this.getFileList(function(){
  682. // this.setFileSelectOptions(node, select);
  683. // }.bind(this), true);
  684. // }.bind(this));
  685. // }.bind(this));
  686. // }.bind(this));
  687. // }
  688. },
  689. setFileSelectOptions: function(node, select){
  690. var name = node.get("name");
  691. select.empty();
  692. var option = new Element("option", {"text": "none"}).inject(select);
  693. this.files.each(function(file){
  694. var option = new Element("option", {
  695. "text": file.name,
  696. "value": file.id,
  697. "selected": (this.data[name]==file.id)
  698. }).inject(select);
  699. }.bind(this));
  700. },
  701. getFileList: function(callback, refresh){
  702. if (!this.files || refresh){
  703. this.form.designer.actions.listFile(this.form.designer.application.id, function(json){
  704. this.files = json.data;
  705. if (callback) callback();
  706. }.bind(this));
  707. }else{
  708. if (callback) callback();
  709. }
  710. },
  711. loadImageClipper: function(){
  712. var nodes = this.propertyContent.getElements(".MWFImageClipper");
  713. if (nodes.length){
  714. nodes.each(function(node){
  715. var id = node.get("name");
  716. var selectNode = new Element("div", {"styles": this.form.css.processIconSelectNode, "text": this.form.designer.lp.selectImage}).inject(node);
  717. selectNode.addEvent("click", function(){
  718. this.selectImage(node, id);
  719. }.bind(this));
  720. }.bind(this));
  721. }
  722. },
  723. createUploadFileAreaNode: function(node, name){
  724. this.uploadFileAreaNode = new Element("div");
  725. var html = "<input name=\"file\" multiple type=\"file\" accept=\"images/*\" />";
  726. this.uploadFileAreaNode.set("html", html);
  727. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  728. this.fileUploadNode.addEvent("change", function(){
  729. //var fileId = attachment.data.id;
  730. var files = this.fileUploadNode.files;
  731. if (files.length){
  732. var count = files.length;
  733. for (var i = 0; i < files.length; i++) {
  734. var file = files.item(i);
  735. var formData = new FormData();
  736. formData.append('file', file);
  737. MWF.xDesktop.uploadImage(
  738. this.form.json.id,
  739. (this.module.form.moduleType=="page") ? "portalPage" : "processPlatformForm",
  740. formData,
  741. file,
  742. function(json){
  743. var id = json.id;
  744. var src = MWF.xDesktop.getImageSrc(id);
  745. var data = {"imageSrc": src, "imageId": id};
  746. this.changeJsonDate(name, data);
  747. this.changeData(name, node, null);
  748. }.bind(this)
  749. );
  750. }
  751. }
  752. }.bind(this));
  753. },
  754. selectImage: function(node, name){
  755. if (!this.uploadFileAreaNode){
  756. this.createUploadFileAreaNode(node, name);
  757. }
  758. //this.fileUploadNode.set("accept", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
  759. this.fileUploadNode.set("multiple", false);
  760. var fileNode = this.uploadFileAreaNode.getFirst();
  761. fileNode.set("accept", ".png,.jpg,.bmp,.gif,.jpeg,.jpe");
  762. fileNode.click();
  763. //MWF.xDesktop.requireApp("process.FormDesigner", "widget.ImageClipper", function(){
  764. // var size = this.module.node.getSize();
  765. // var image = new MWF.xApplication.process.FormDesigner.widget.ImageClipper(this.designer, {
  766. // "title": this.form.designer.lp.selectImage,
  767. // "width": (this.data.styles.width) ? size.x : 0,
  768. // "height": (this.data.styles.height) ? size.y : 0,
  769. // "imageUrl" : this.data.imageSrc,
  770. // "reference" : this.form.json.id,
  771. // "referenceType": (this.module.form.moduleType=="page") ? "portalPage" : "processPlatformForm",
  772. // "onChange": function(){
  773. // var data = {"imageSrc": image.imageSrc, "imageId": image.imageId};
  774. // this.changeJsonDate(name, data);
  775. // this.changeData(name, node, null);
  776. // }.bind(this)
  777. // });
  778. // image.load(this.data[name])
  779. //}.bind(this));
  780. },
  781. loadEventsEditor: function(){
  782. var events = this.propertyContent.getElement(".MWFEventsArea");
  783. if (events){
  784. var name = events.get("name");
  785. var eventsObj = this.data[name];
  786. MWF.xDesktop.requireApp("process.FormDesigner", "widget.EventsEditor", function(){
  787. var eventsEditor = new MWF.xApplication.process.FormDesigner.widget.EventsEditor(events, this.designer, {
  788. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  789. "maxObj": this.designer.formContentNode || this.designer.pageContentNode
  790. });
  791. eventsEditor.load(eventsObj, this.data, name);
  792. }.bind(this));
  793. }
  794. },
  795. testRestful: function(){
  796. var node = this.propertyContent.getElements(".MWFTestRestful");
  797. if (node){
  798. var resultNode = node.getLast();
  799. node.getFirst().addEvent("click", function(){
  800. }.bind(this));
  801. }
  802. },
  803. loadContextRoot: function(){
  804. var nodes = this.propertyContent.getElements(".MWFContextRoot");
  805. if (nodes){
  806. nodes.each(function(node){
  807. var name = node.get("name");
  808. var selects = node.getElements("select");
  809. var rootSelect = selects[0];
  810. var actionSelect = selects[1];
  811. var methodSelect = selects[2];
  812. var pathInput = node.getElement("input");
  813. //var select = new Element("select").inject(node);
  814. //var methodSelect = new Element("select").inject(node);
  815. debugger;
  816. var getValue = function(){
  817. var v;
  818. try {
  819. v = JSON.parse(this.data[name]);
  820. }catch(e){
  821. v = {"root": this.data[name], "action":"", "method": "", "uri": ""};
  822. }
  823. return v
  824. }.bind(this);
  825. var value = getValue();
  826. var resetRootSelects = function(){
  827. var root = rootSelect.options[rootSelect.selectedIndex].value;
  828. var action = o2.Actions.load(root);
  829. actionSelect.empty();
  830. methodSelect.empty();
  831. pathInput.set("value", "");
  832. var value = getValue();
  833. Object.each(action, function(o, key){
  834. var option = new Element("option", {"value": key, "text": key, "selected": (value.action==key)}).inject(actionSelect);
  835. });
  836. return JSON.stringify({"root": root, "action":"", "method": "", "uri": ""});
  837. };
  838. var resetActionSelects = function(){
  839. var root = rootSelect.options[rootSelect.selectedIndex].value;
  840. var actionName = actionSelect.options[actionSelect.selectedIndex].value;
  841. var action = o2.Actions.load(root);
  842. methodSelect.empty();
  843. pathInput.set("value", "");
  844. var value = getValue();
  845. Object.each(action[actionName].action.actions, function(o, key){
  846. var option = new Element("option", {"value": key, "text": key, "selected": (value.method==key)}).inject(methodSelect);
  847. });
  848. return JSON.stringify({"root": root, "action":actionName, "method": "", "uri": ""});
  849. };
  850. var resetMethodSelects = function(){
  851. var root = rootSelect.options[rootSelect.selectedIndex].value;
  852. var actionName = actionSelect.options[actionSelect.selectedIndex].value;
  853. var methodName = methodSelect.options[methodSelect.selectedIndex].value;
  854. var action = o2.Actions.load(root);
  855. var uri = action[actionName].action.actions[methodName].uri;
  856. pathInput.set("value", uri);
  857. return JSON.stringify({"root": root, "action":actionName, "method": methodName, "uri": uri});
  858. };
  859. Object.each(layout.serviceAddressList, function(v, key){
  860. var option = new Element("option", {"value": key, "text": v.name, "selected": (value.root==key)}).inject(rootSelect);
  861. }.bind(this));
  862. resetRootSelects()
  863. resetActionSelects();
  864. resetMethodSelects();
  865. rootSelect.addEvent("change", function(){
  866. resetRootSelects();
  867. resetActionSelects();
  868. var data = resetMethodSelects();
  869. this.changeJsonDate(name, data);
  870. this.changeData(name, node, value);
  871. }.bind(this));
  872. actionSelect.addEvent("change", function(){
  873. resetActionSelects();
  874. var data = resetMethodSelects();
  875. this.changeJsonDate(name, data);
  876. this.changeData(name, node, value);
  877. }.bind(this));
  878. methodSelect.addEvent("change", function(){
  879. var data = resetMethodSelects();
  880. this.changeJsonDate(name, data);
  881. this.changeData(name, node, value);
  882. }.bind(this));
  883. }.bind(this));
  884. }
  885. },
  886. loadSourceTestRestful: function(){
  887. var nodes = this.propertyContent.getElements(".MWFSourceTestRestful");
  888. if (nodes.length){
  889. nodes.each(function(node){
  890. var button = node.getFirst();
  891. var content = node.getLast();
  892. //var button = new Element("input", {"type": "button", "value": "Test"}).inject(node);
  893. button.addEvent("click", function(e){
  894. this.testSourceRestful(content);
  895. }.bind(this));
  896. }.bind(this));
  897. }
  898. },
  899. testSourceRestful: function(content){
  900. var service;
  901. try {
  902. service = JSON.parse(this.module.json.contextRoot);
  903. }catch(e){
  904. service = {"root": this.module.json.contextRoot, "action":"", "method": "", "url": ""};
  905. }
  906. var address = this._getO2Address(service.root);
  907. var uri = this._getO2Uri(this.module, address);
  908. this._invoke(this.module, uri, function(json){
  909. content.empty();
  910. MWF.require("MWF.widget.JsonParse", function(){
  911. var jsonParse = new MWF.widget.JsonParse(json, content, null);
  912. jsonParse.load();
  913. }.bind(this));
  914. }.bind(this));
  915. },
  916. _getO2Address: function(contextRoot){
  917. var addressObj = layout.serviceAddressList[contextRoot];
  918. var address = "";
  919. if (addressObj){
  920. address = layout.config.app_protocol+"//"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+addressObj.context;
  921. }else{
  922. var host = layout.desktop.centerServer.host || window.location.hostname;
  923. var port = layout.desktop.centerServer.port;
  924. address = layout.config.app_protocol+"//"+host+(port=="80" ? "" : ":"+port)+"/x_program_center";
  925. }
  926. return address;
  927. },
  928. _getO2Uri: function(module, address){
  929. //var uri = module.json.path || module.json.selectPath;
  930. var uri = module.json.path;
  931. var pars = {};
  932. MWF.require("MWF.xScript.Macro", null, false);
  933. var macro = new MWF.Macro["PageContext"]({"businessData": {}, "json": {}, "options": {}});
  934. if (module.json.parameters){
  935. Object.each(module.json.parameters, function(v, key){
  936. if (uri.indexOf("{"+key+"}")!==-1){
  937. var reg = new RegExp("{"+key+"}", "g");
  938. uri = uri.replace(reg, encodeURIComponent((v && v.code) ? (macro.exec(v.code, this) || "") : v));
  939. }else{
  940. pars[key] = v;
  941. }
  942. }.bind(this));
  943. }
  944. var data = null;
  945. if (module.json.requestBody){
  946. if (module.json.requestBody.code){
  947. data = macro.exec(module.json.requestBody.code, this)
  948. }
  949. }
  950. if (module.json.httpMethod==="GET" || module.json.httpMethod==="OPTIONS" || module.json.httpMethod==="HEAD" || module.json.httpMethod==="DELETE"){
  951. var tag = "?";
  952. if (uri.indexOf("?")!==-1) tag = "&";
  953. Object.each(pars, function(v, k){
  954. var value = (v && v.code) ? (macro.exec(v.code, this) || "") : v;
  955. uri = uri+tag+k+"="+value;
  956. }.bind(this));
  957. }else{
  958. Object.each(pars, function(v, k){
  959. if (!data) data = {};
  960. var value = (v && v.code) ? (macro.exec(v.code, this) || "") : v;
  961. data[k] = value;
  962. }.bind(this));
  963. }
  964. this.body = data;
  965. return {"uri": address+uri, "body": data};
  966. },
  967. _invoke: function(module, uri, callback){
  968. MWF.restful(module.json.httpMethod, uri.uri, JSON.encode(uri.body), function(json){
  969. //this.data = json;
  970. if (callback) callback(json);
  971. }.bind(this), true, true);
  972. },
  973. loadUnitTypeSelector: function(){
  974. var nodes = this.propertyContent.getElements(".MWFFormUnitTypeSelector");
  975. if (nodes.length){
  976. this.getUnitTypeList(function(){
  977. nodes.each(function(node){
  978. var select = new Element("select").inject(node);
  979. select.addEvent("change", function(e){
  980. this.setValue(e.target.getParent("div").get("name"), e.target.options[e.target.selectedIndex].value);
  981. }.bind(this));
  982. this.setUnitTypeSelectOptions(node, select);
  983. this.setValue(select.getParent("div").get("name"), select.options[select.selectedIndex].value);
  984. // var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  985. // refreshNode.addEvent("click", function(e){
  986. // this.getUnitTypeList(function(){
  987. // this.setUnitTypeSelectOptions(node, select);
  988. // }.bind(this), true);
  989. // }.bind(this));
  990. }.bind(this));
  991. }.bind(this));
  992. }
  993. },
  994. setUnitTypeSelectOptions: function(node, select){
  995. var name = node.get("name");
  996. select.empty();
  997. var option = new Element("option", {"value":"all", "text": this.form.designer.lp.all, "selected": (!this.data[name] || this.data[name]==="all")}).inject(select);
  998. this.unitTypeList.each(function(unitType){
  999. var option = new Element("option", {
  1000. "text": unitType,
  1001. "value": unitType,
  1002. "selected": (this.data[name]===unitType)
  1003. }).inject(select);
  1004. }.bind(this));
  1005. },
  1006. getUnitTypeList: function(callback, refresh){
  1007. if (!this.unitTypeList || refresh){
  1008. //MWF.xDesktop.requireApp("Org", "Actions.RestActions", function(){
  1009. // var action = new MWF.xApplication.Org.Actions.RestActions();
  1010. var action = MWF.Actions.get("x_organization_assemble_control");
  1011. action.listUnitType(function(json){
  1012. this.unitTypeList = json.data.valueList;
  1013. if (callback) callback();
  1014. }.bind(this));
  1015. //}.bind(this));
  1016. }else{
  1017. if (callback) callback();
  1018. }
  1019. },
  1020. loadParameterEditor: function(){
  1021. var pars = this.propertyContent.getElements(".MWFParameterArea");
  1022. if (pars){
  1023. pars.each(function(par){
  1024. var name = par.get("name");
  1025. if (!this.data[name]) this.data[name] = {};
  1026. var parObj = this.data[name];
  1027. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ParameterEditor", function(){
  1028. var parameterEditor = new MWF.xApplication.process.FormDesigner.widget.ParameterEditor(par, this.designer, {
  1029. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  1030. "maxObj": this.designer.formContentNode
  1031. });
  1032. parameterEditor.load(parObj, this.data, name);
  1033. }.bind(this));
  1034. }.bind(this));
  1035. }
  1036. },
  1037. loadArrayList: function(){
  1038. var arrays = this.propertyContent.getElements(".MWFArraylist");
  1039. arrays.each(function(node){
  1040. var title = node.get("title");
  1041. var name = node.get("name");
  1042. var arr = this.data[name];
  1043. if (!arr) arr = [];
  1044. MWF.require("MWF.widget.Arraylist", function(){
  1045. var arraylist = new MWF.widget.Arraylist(node, {
  1046. "title": title,
  1047. "onChange": function(){
  1048. this.data[name] = arraylist.toArray();
  1049. }.bind(this)
  1050. });
  1051. arraylist.load(arr);
  1052. }.bind(this));
  1053. node.addEvent("keydown", function(e){e.stopPropagation();});
  1054. }.bind(this));
  1055. },
  1056. loadHtmlEditorArea: function(){
  1057. var htmlAreas = this.propertyContent.getElements(".MWFHtmlEditorArea");
  1058. htmlAreas.each(function(node){
  1059. var title = node.get("title");
  1060. var name = node.get("name");
  1061. var scriptContent = this.data[name];
  1062. MWF.require("MWF.widget.HtmlEditorArea", function(){
  1063. var htmlArea = new MWF.widget.HtmlEditorArea(node, {
  1064. "title": title,
  1065. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  1066. "maxObj": this.designer.formContentNode,
  1067. "onChange": function(){
  1068. this.data[name] = htmlArea.getValue();
  1069. this.changeData(name);
  1070. htmlArea.isChanged = true;
  1071. }.bind(this),
  1072. // "onBlur": function(){
  1073. // if (htmlArea.isChanged){
  1074. // this.changeData(name, node, "");
  1075. // htmlArea.isChanged = false;
  1076. // }
  1077. // }.bind(this),
  1078. "onSave": function(){
  1079. this.designer.saveForm();
  1080. }.bind(this)
  1081. });
  1082. htmlArea.load({"code": scriptContent});
  1083. }.bind(this));
  1084. }.bind(this));
  1085. },
  1086. loadStylesList: function(){
  1087. var _self = this;
  1088. var styleSelNodes = this.propertyContent.getElements(".MWFFormStyle");
  1089. styleSelNodes.each(function(node){
  1090. if (this.module.form.stylesList){
  1091. if (!this.data.formStyleType) this.data.formStyleType = "default";
  1092. var mode = ( this.form.options.mode || "" ).toLowerCase() === "mobile" ? "mobile" : "pc";
  1093. Object.each(this.module.form.stylesList, function(s, key){
  1094. if( s.mode.contains( mode ) ){
  1095. new Element("option", {
  1096. "text": s.name,
  1097. "value": key,
  1098. "selected": ((!this.data.formStyleType && key=="default") || (this.data.formStyleType==key))
  1099. }).inject(node)
  1100. }
  1101. }.bind(this));
  1102. }else{
  1103. node.getParent("tr").setStyle("display", "none");
  1104. }
  1105. var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node, "after");
  1106. refreshNode.addEvent("click", function(e){
  1107. _self.changeData(this.get("name"), this );
  1108. }.bind(node));
  1109. }.bind(this));
  1110. },
  1111. // loadStylesList: function(){
  1112. // var _self = this;
  1113. // var styleSelNodes = this.propertyContent.getElements(".MWFFormStyle");
  1114. // styleSelNodes.each(function(node){
  1115. // if (this.module.form.stylesList){
  1116. // if (!this.data.formStyleType) this.data.formStyleType = "default";
  1117. // var mode = ( this.form.options.mode || "" ).toLowerCase() === "mobile" ? "mobile" : "pc";
  1118. // Object.each(this.module.form.stylesList, function(s, key){
  1119. // if( s.mode.contains( mode ) ){
  1120. // new Element("option", {
  1121. // "text": s.name,
  1122. // "value": key,
  1123. // "selected": ((!this.data.formStyleType && key=="default") || (this.data.formStyleType==key))
  1124. // }).inject(node)
  1125. // }
  1126. // }.bind(this));
  1127. // }else{
  1128. // node.getParent("tr").setStyle("display", "none");
  1129. // }
  1130. //
  1131. // var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node, "after");
  1132. // refreshNode.addEvent("click", function(e){
  1133. // _self.changeData(this.get("name"), this );
  1134. // }.bind(node));
  1135. // }.bind(this));
  1136. // },
  1137. loadDivTemplateType: function(){
  1138. var nodes = this.propertyContent.getElements(".MWFDivTemplate");
  1139. if (nodes.length){
  1140. var keys = [];
  1141. //if (this.module.form.stylesList) {
  1142. // if (this.module.form.stylesList[this.module.form.json.formStyleType]){
  1143. // var styles = this.module.form.stylesList[this.module.form.json.formStyleType][this.module.moduleName];
  1144. // if (styles) {
  1145. // Object.each(styles, function (v, k) {
  1146. // keys.push(k);
  1147. // }.bind(this));
  1148. // }
  1149. // }
  1150. //}
  1151. if (this.module.form.templateStyles && this.module.form.templateStyles[this.module.moduleName]) {
  1152. var styles = this.module.form.templateStyles[this.module.moduleName];
  1153. if (styles) {
  1154. Object.each(styles, function (v, k) {
  1155. keys.push(k);
  1156. }.bind(this));
  1157. }
  1158. }
  1159. nodes.each(function(node){
  1160. node.empty();
  1161. new Element("option", {
  1162. "text": "default",
  1163. "value": "default",
  1164. "selected": (!this.data.templateType || this.data.templateType=="default")
  1165. }).inject(node);
  1166. if (keys.length){
  1167. keys.each(function(k){
  1168. new Element("option", {
  1169. "text": styles[k].name,
  1170. "value": k,
  1171. "selected": (this.data.templateType==k)
  1172. }).inject(node)
  1173. }.bind(this));
  1174. }else{
  1175. node.getParent("tr").setStyle("display", "none");
  1176. }
  1177. }.bind(this));
  1178. }
  1179. },
  1180. loadPersonInput: function(){
  1181. var personIdentityNodes = this.propertyContent.getElements(".MWFPersonIdentity");
  1182. var personUnitNodes = this.propertyContent.getElements(".MWFPersonUnit");
  1183. var dutyNodes = this.propertyContent.getElements(".MWFDutySelector");
  1184. var dutyNameNodes = this.propertyContent.getElements(".MWFPersonDuty");
  1185. var viewNodes = this.propertyContent.getElements(".MWFViewSelect");
  1186. var cmsviewNodes = this.propertyContent.getElements(".MWFCMSViewSelect");
  1187. var queryviewNodes = this.propertyContent.getElements(".MWFQueryViewSelect");
  1188. var queryStatementNodes = this.propertyContent.getElements(".MWFQueryStatementSelect");
  1189. var querystatNodes = this.propertyContent.getElements(".MWFQueryStatSelect");
  1190. var fileNodes = this.propertyContent.getElements(".MWFImageFileSelect");
  1191. var processFileNodes = this.propertyContent.getElements(".MWFProcessImageFileSelect");
  1192. var scriptNodes = this.propertyContent.getElements(".MWFScriptSelect");
  1193. var formStyleNodes = this.propertyContent.getElements(".MWFFormStyleSelect");
  1194. var dictionaryNodes = this.propertyContent.getElements(".MWFDictionarySelect");
  1195. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  1196. personIdentityNodes.each(function(node){
  1197. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1198. "type": "identity",
  1199. "names": this.data[node.get("name")],
  1200. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  1201. });
  1202. }.bind(this));
  1203. personUnitNodes.each(function(node){
  1204. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1205. "type": "unit",
  1206. "names": this.data[node.get("name")],
  1207. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  1208. });
  1209. }.bind(this));
  1210. dutyNodes.each(function(node){
  1211. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1212. "type": "duty",
  1213. "names": this.data[node.get("name")],
  1214. "onChange": function(ids){this.addDutyItem(node, ids);}.bind(this),
  1215. "onRemoveDuty": function(item){this.removeDutyItem(node, item);}.bind(this)
  1216. });
  1217. }.bind(this));
  1218. dutyNameNodes.each(function(node){
  1219. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1220. "type": "dutyName",
  1221. "names": this.data[node.get("name")],
  1222. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  1223. });
  1224. }.bind(this));
  1225. viewNodes.each(function(node){
  1226. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1227. "type": "View",
  1228. "count": 1,
  1229. "names": [this.data[node.get("name")]],
  1230. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  1231. });
  1232. }.bind(this));
  1233. cmsviewNodes.each(function(node){
  1234. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1235. "type": "CMSView",
  1236. "count": 1,
  1237. "names": [this.data[node.get("name")]],
  1238. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  1239. });
  1240. }.bind(this));
  1241. queryviewNodes.each(function(node){
  1242. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1243. "type": "QueryView",
  1244. "count": 1,
  1245. "names": [this.data[node.get("name")]],
  1246. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  1247. });
  1248. }.bind(this));
  1249. queryStatementNodes.each(function(node){
  1250. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1251. "type": "QueryStatement",
  1252. "count": 1,
  1253. "names": [this.data[node.get("name")]],
  1254. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  1255. });
  1256. }.bind(this));
  1257. querystatNodes.each(function(node){
  1258. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1259. "type": "QueryStat",
  1260. "count": 1,
  1261. "names": [this.data[node.get("name")]],
  1262. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  1263. });
  1264. }.bind(this));
  1265. scriptNodes.each(function(node){
  1266. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1267. "type": "Script",
  1268. "count": node.dataset["count"] || 1,
  1269. "names": (!node.dataset["count"] || node.dataset["count"].toInt()==1) ? [this.data[node.get("name")]] : this.data[node.get("name")],
  1270. "onChange": function(ids){
  1271. this.saveScriptSelectItem(node, ids);
  1272. }.bind(this)
  1273. });
  1274. }.bind(this));
  1275. var _self = this;
  1276. formStyleNodes.each(function(node){
  1277. debugger;
  1278. var data = this.data[node.get("name")];
  1279. if( typeOf( data ) === "string" ){
  1280. for( var key in this.module.form.stylesList ){
  1281. var s = this.module.form.stylesList[key];
  1282. if( ((!data && key=="default") || (data==key)) ){
  1283. data = {
  1284. name : s.name,
  1285. id : key
  1286. };
  1287. break;
  1288. }
  1289. }
  1290. }
  1291. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1292. "type": "FormStyle",
  1293. "count": 1,
  1294. "names": [data],
  1295. "selectorOptions" : {
  1296. "mode" : ( this.form.options.mode || "" ).toLowerCase() === "mobile" ? "mobile" : "pc"
  1297. },
  1298. "validFun" : function (ids) {
  1299. var flag = true;
  1300. if( ids.length === 0 ){
  1301. this.designer.notice(MWF.APPFD.LP.mustSelectFormStyle, "error");
  1302. flag = false;
  1303. }else if( ids[0].data.type === "script" ){
  1304. this.designer.actions.getScriptByName( ids[0].data.name, ids[0].data.application, function( json ) {
  1305. debugger;
  1306. try{
  1307. var f = eval("(function(){\n return "+json.data.text+"\n})");
  1308. var j = f();
  1309. if( typeOf(j) !== "object" ){
  1310. this.designer.notice( MWF.APPFD.LP.notValidJson, "error" );
  1311. flag = false;
  1312. }
  1313. }catch (e) {
  1314. this.designer.notice( MWF.APPFD.LP.notValidJson +":"+ e.message, "error" );
  1315. flag = false;
  1316. }
  1317. }.bind(this), function () {
  1318. flag = false;
  1319. }, false);
  1320. }
  1321. return flag;
  1322. }.bind(this),
  1323. "onChange": function(ids){
  1324. var d = ids[0].data;
  1325. var data;
  1326. if( d.type === "script" ){
  1327. data = {
  1328. "type" : "script",
  1329. "name": d.name,
  1330. "alias": d.alias,
  1331. "id": d.id,
  1332. "appName" : d.appName || d.applicationName,
  1333. "appId": d.appId,
  1334. "application": d.application
  1335. };
  1336. }else{
  1337. data = d.id;
  1338. }
  1339. var name = node.get("name");
  1340. var oldValue = this.data[name];
  1341. this.data[name] = data;
  1342. this.changeData(name, node, oldValue);
  1343. }.bind(this)
  1344. });
  1345. var next = node.getNext();
  1346. if( next && next.get("class") === "MWFScriptSelectRefresh" ){
  1347. var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(next);
  1348. refreshNode.addEvent("click", function(e){
  1349. _self.changeData(this.get("name"), this );
  1350. }.bind(node));
  1351. }
  1352. }.bind(this));
  1353. dictionaryNodes.each(function(node){
  1354. var data = this.data[node.get("name")];
  1355. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1356. "type": "Dictionary",
  1357. "count": 0,
  1358. "names": typeOf(data)==="array" ? data : [data],
  1359. "onChange": function(ids){
  1360. var data = [];
  1361. var name = node.get("name");
  1362. if( ids.length > 0 ){
  1363. // var d = ids[0].data;
  1364. ids.each( function (id) {
  1365. debugger;
  1366. var d = id.data;
  1367. data.push({
  1368. "type" : "dictionary",
  1369. "name": d.name,
  1370. "alias": d.alias,
  1371. "id": d.id,
  1372. "appName" : d.appName || d.applicationName,
  1373. "appAlias" : d.appAlias || d.applicationAlias,
  1374. "appId": d.appId,
  1375. "application": d.application,
  1376. "appType" : d.appType
  1377. })
  1378. });
  1379. }
  1380. var oldValue = this.data[name];
  1381. this.data[name] = data;
  1382. this.changeData(name, node, oldValue);
  1383. }.bind(this)
  1384. });
  1385. }.bind(this));
  1386. fileNodes.each(function(node){
  1387. var d = this.data[node.get("name")];
  1388. var data = d || {};
  1389. //this.form
  1390. if (d && typeOf(d)==="string"){
  1391. if (this.form.page){
  1392. data = {"id": d, "portal": this.form.application}
  1393. }else{
  1394. data = {"id": d, "application": this.form.application}
  1395. }
  1396. }
  1397. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1398. "type": "PortalFile",
  1399. "count": 1,
  1400. "isImage": true,
  1401. "values": (data.id) ? [data.id] : [],
  1402. "onChange": function(ids){this.saveFileItem(node, ids);}.bind(this)
  1403. });
  1404. }.bind(this));
  1405. processFileNodes.each(function(node){
  1406. var d = this.data[node.get("name")];
  1407. var data = d || {};
  1408. //this.form
  1409. if (d && typeOf(d)==="string"){
  1410. if (this.form.page){
  1411. data = {"id": d, "portal": this.form.application}
  1412. }else{
  1413. data = {"id": d, "application": this.form.application}
  1414. }
  1415. }
  1416. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1417. "type": "ProcessFile",
  1418. "count": 1,
  1419. "isImage": true,
  1420. "values": (data.id) ? [data.id] : [],
  1421. "onChange": function(ids){this.saveFileItem(node, ids);}.bind(this)
  1422. });
  1423. }.bind(this));
  1424. }.bind(this));
  1425. },
  1426. loadDictionaryIncluder : function(){
  1427. var nodes = this.propertyContent.getElements(".MWFDictionaryIncluder");
  1428. if (nodes.length){
  1429. nodes.each(function(node){
  1430. var name = node.get("name");
  1431. MWF.xDesktop.requireApp("process.FormDesigner", "widget.DictionaryIncluder", function(){
  1432. var dictionaryIncluder = new MWF.xApplication.process.FormDesigner.widget.DictionaryIncluder(node, this.designer, {
  1433. "onChange": function(){
  1434. var data = dictionaryIncluder.getData();
  1435. this.data[name] = data;
  1436. }.bind(this)
  1437. });
  1438. dictionaryIncluder.load(this.data[name])
  1439. }.bind(this));
  1440. }.bind(this));
  1441. }
  1442. },
  1443. loadScriptIncluder : function(){
  1444. var nodes = this.propertyContent.getElements(".MWFScriptIncluder");
  1445. if (nodes.length){
  1446. nodes.each(function(node){
  1447. var name = node.get("name");
  1448. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ScriptIncluder", function(){
  1449. var scriptIncluder = new MWF.xApplication.process.FormDesigner.widget.ScriptIncluder(node, this.designer, {
  1450. "onChange": function(){
  1451. var data = scriptIncluder.getData();
  1452. this.data[name] = data;
  1453. }.bind(this)
  1454. });
  1455. scriptIncluder.load(this.data[name])
  1456. }.bind(this));
  1457. }.bind(this));
  1458. }
  1459. },
  1460. saveFileItem: function(node, ids){
  1461. if (ids[0]){
  1462. var file = ids[0].data;
  1463. this.data[node.get("name")] = file;
  1464. }else{
  1465. this.data[node.get("name")] = null;
  1466. }
  1467. this.changeData(node.get("name"));
  1468. },
  1469. saveViewItem: function(node, ids){
  1470. if (ids[0]){
  1471. var view = ids[0].data;
  1472. var data = {
  1473. "name": view.name,
  1474. "alias": view.alias,
  1475. "id": view.id,
  1476. "appName" : view.appName || view.applicationName || view.query,
  1477. "appId": view.appId,
  1478. "application": view.application || view.query
  1479. };
  1480. this.data[node.get("name")] = data;
  1481. }else{
  1482. this.data[node.get("name")] = null;
  1483. }
  1484. if (this.module._checkView) this.module._checkView();
  1485. },
  1486. removeViewItem: function(node, item){
  1487. },
  1488. saveScriptSelectItem: function(node, ids){
  1489. var count = (node.dataset["count"] || 1).toInt();
  1490. if (count==1){
  1491. if (ids[0]){
  1492. var script = ids[0].data;
  1493. var data = {
  1494. "appType": script.appType,
  1495. "type" : "script",
  1496. "name": script.name,
  1497. "alias": script.alias,
  1498. "id": script.id,
  1499. "appName" : script.appName || script.applicationName,
  1500. "appId": script.appId,
  1501. "application": script.application
  1502. };
  1503. var name = node.get("name");
  1504. var oldValue = this.data[name];
  1505. this.data[name] = data;
  1506. // this.changeJsonDate(name, data );
  1507. this.changeData(name, node, oldValue);
  1508. }else{
  1509. // this.data[node.get("name")] = null;
  1510. }
  1511. }else{
  1512. var scriptValues = [];
  1513. ids.each(function(s){
  1514. var scriptValue = {
  1515. "appType": s.data.appType,
  1516. "type" : "script",
  1517. "name": s.data.name,
  1518. "alias": s.data.alias,
  1519. "id": s.data.id,
  1520. "appName" : s.data.appName || s.data.applicationName,
  1521. "appId": s.data.appId,
  1522. "application": s.data.application
  1523. }
  1524. scriptValues.push(scriptValue);
  1525. }.bind(this));
  1526. var name = node.get("name");
  1527. var oldValue = this.data[name];
  1528. this.data[name] = scriptValues;
  1529. this.changeData(name, node, oldValue);
  1530. }
  1531. },
  1532. removeDutyItem: function(node, item){
  1533. if (item.data.id){
  1534. var values = JSON.decode(this.data[node.get("name")] || []);
  1535. var value = values.filter(function(v){
  1536. return v.id == item.data.id;
  1537. });
  1538. value.each(function(v) {
  1539. values = values.erase(v);
  1540. });
  1541. this.data[node.get("name")] = JSON.encode(values);
  1542. }
  1543. item.node.destroy();
  1544. MWF.release(item);
  1545. delete item;
  1546. },
  1547. addDutyItem: function(node, ids){
  1548. var value = this.data[node.get("name")] || "";
  1549. if (!value) value = "[]";
  1550. var values = JSON.decode(value);
  1551. ids.each(function(id){
  1552. if (id.data.dutyId){
  1553. for (var i=0; i<values.length; i++){
  1554. if (values[i].dutyId===id.data.dutyId){
  1555. values[i].name = id.data.name;
  1556. values[i].code = id.data.code;
  1557. break;
  1558. }
  1559. }
  1560. }else{
  1561. id.data.dutyId = new MWF.widget.UUID().toString();
  1562. values.push({"name": id.data.name, "id": id.data.id, "dutyId": id.data.dutyId, "code": id.data.code});
  1563. }
  1564. }.bind(this));
  1565. this.data[node.get("name")] = JSON.encode(values);
  1566. },
  1567. loadFormFieldInput: function(){
  1568. var fieldNodes = this.propertyContent.getElements(".MWFFormFieldPerson");
  1569. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  1570. fieldNodes.each(function(node){
  1571. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1572. "type": "formField",
  1573. "application": this.form.json.application,
  1574. "fieldType": "person",
  1575. "names": this.data[node.get("name")],
  1576. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  1577. });
  1578. }.bind(this));
  1579. }.bind(this));
  1580. },
  1581. savePersonItem: function(node, ids){
  1582. var values = [];
  1583. ids.each(function(id){
  1584. values.push(MWF.org.parseOrgData(id.data));
  1585. }.bind(this));
  1586. this.data[node.get("name")] = values;
  1587. },
  1588. loadScriptArea: function(){
  1589. var scriptAreas = this.propertyContent.getElements(".MWFScriptArea");
  1590. var formulaAreas = this.propertyContent.getElements(".MWFFormulaArea");
  1591. this.loadScriptEditor(scriptAreas);
  1592. this.loadScriptEditor(formulaAreas, "formula");
  1593. },
  1594. loadScriptEditor: function(scriptAreas, style){
  1595. scriptAreas.each(function(node){
  1596. var title = node.get("title");
  1597. var name = node.get("name");
  1598. if (!this.data[name]) this.data[name] = {"code": "", "html": ""};
  1599. var scriptContent = this.data[name];
  1600. MWF.require("MWF.widget.ScriptArea", function(){
  1601. var scriptArea = new MWF.widget.ScriptArea(node, {
  1602. "title": title,
  1603. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  1604. "maxObj": this.designer.formContentNode || this.designer.pageContentNode,
  1605. "onChange": function(){
  1606. //this.data[name] = scriptArea.toJson();
  1607. if (!this.data[name]){
  1608. this.data[name] = {"code": "", "html": ""};
  1609. if (this.module.form.scriptDesigner) this.module.form.scriptDesigner.addScriptItem(this.data[name], "code", this.data, name);
  1610. }
  1611. var json = scriptArea.toJson();
  1612. this.data[name].code = json.code;
  1613. //this.data[name].html = json.html;
  1614. }.bind(this),
  1615. "onSave": function(){
  1616. this.designer.saveForm();
  1617. }.bind(this),
  1618. "style": style || "default",
  1619. "runtime": "web"
  1620. });
  1621. scriptArea.load(scriptContent);
  1622. }.bind(this));
  1623. }.bind(this));
  1624. },
  1625. loadCssArea: function(style){
  1626. var cssAreas = this.propertyContent.getElements(".MWFCssArea");
  1627. cssAreas.each(function(node){
  1628. var title = node.get("title");
  1629. var name = node.get("name");
  1630. if (!this.data[name]) this.data[name] = {"code": "", "html": ""};
  1631. var cssContent = this.data[name];
  1632. o2.require("o2.widget.CssArea", function(){
  1633. var cssArea = new o2.widget.CssArea(node, {
  1634. "title": title,
  1635. "maxObj": this.designer.formContentNode || this.designer.pageContentNode,
  1636. "onChange": function(){
  1637. //this.data[name] = scriptArea.toJson();
  1638. if (!this.data[name]){
  1639. this.data[name] = {"code": "", "html": ""};
  1640. if (this.module.form.scriptDesigner) this.module.form.scriptDesigner.addScriptItem(this.data[name], "code", this.data, name);
  1641. }
  1642. var json = cssArea.toJson();
  1643. this.data[name].code = json.code;
  1644. cssArea.isChanged = true;
  1645. //this.data[name].html = json.html;
  1646. }.bind(this),
  1647. "onBlur": function(){
  1648. if (cssArea.isChanged){
  1649. this.changeData(name, node, "");
  1650. cssArea.isChanged = false;
  1651. }
  1652. }.bind(this),
  1653. "onSave": function(){
  1654. this.designer.saveForm();
  1655. }.bind(this),
  1656. "style": style || "default"
  1657. });
  1658. cssArea.load(cssContent);
  1659. }.bind(this));
  1660. }.bind(this));
  1661. },
  1662. loadActionStylesArea: function(){
  1663. var _self = this;
  1664. var actionAreas = this.propertyContent.getElements(".MWFActionStylesArea");
  1665. actionAreas.each(function(node){
  1666. var name = node.get("name");
  1667. var actionStyles = this.data[name];
  1668. MWF.require("MWF.widget.Maplist", function(){
  1669. var maps = [];
  1670. Object.each(actionStyles, function(v, k){
  1671. var mapNode = new Element("div").inject(node);
  1672. mapNode.empty();
  1673. var maplist = new MWF.widget.Maplist(mapNode, {
  1674. "title": k,
  1675. "collapse": true,
  1676. "onChange": function(){
  1677. var oldData = _self.data[name];
  1678. maps.each(function(o){
  1679. _self.data[name][o.key] = o.map.toJson();
  1680. }.bind(this));
  1681. _self.changeData(name, node, oldData);
  1682. }
  1683. });
  1684. maps.push({"key": k, "map": maplist});
  1685. maplist.load(v);
  1686. }.bind(this));
  1687. }.bind(this));
  1688. }.bind(this));
  1689. },
  1690. loadActionArea: function(){
  1691. var actionAreas = this.propertyContent.getElements(".MWFActionArea");
  1692. actionAreas.each(function(node){
  1693. var name = node.get("name");
  1694. var actionContent = this.data[name];
  1695. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ActionsEditor", function(){
  1696. // debugger;
  1697. // var actionEditor = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor(node, this.designer, {
  1698. // "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  1699. // "noCreate": true,
  1700. // "noDelete": true,
  1701. // "noCode": true,
  1702. // "onChange": function(){
  1703. // this.data[name] = actionEditor.data;
  1704. // }.bind(this)
  1705. // });
  1706. // actionEditor.load(this.module.defaultToolBarsData);
  1707. var actionEditor = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor(node, this.designer, this.data, {
  1708. "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  1709. "onChange": function(){
  1710. this.data[name] = actionEditor.data;
  1711. this.changeData(name);
  1712. }.bind(this)
  1713. });
  1714. actionEditor.load(actionContent);
  1715. }.bind(this));
  1716. }.bind(this));
  1717. var actionAreas = this.propertyContent.getElements(".MWFDefaultActionArea");
  1718. actionAreas.each(function(node){
  1719. var name = node.get("name");
  1720. var actionContent = this.data[name] || this.module.defaultToolBarsData;
  1721. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ActionsEditor", function(){
  1722. var actionEditor = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor(node, this.designer, this.data, {
  1723. "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  1724. "isSystemTool" : true,
  1725. "noCreate": true,
  1726. "noDelete": false,
  1727. "noCode": true,
  1728. "noReadShow": true,
  1729. "target" : node.get("data-target"),
  1730. "noEditShow": true,
  1731. "onChange": function(){
  1732. this.data[name] = actionEditor.data;
  1733. this.changeData(name);
  1734. }.bind(this)
  1735. });
  1736. actionEditor.load(actionContent);
  1737. // var actionEditor = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor(node, this.designer, {
  1738. // "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  1739. // "onChange": function(){
  1740. // this.data[name] = actionEditor.data;
  1741. // }.bind(this)
  1742. // });
  1743. // actionEditor.load(actionContent);
  1744. }.bind(this));
  1745. }.bind(this));
  1746. },
  1747. loadMaplist: function(){
  1748. var maplists = this.propertyContent.getElements(".MWFMaplist");
  1749. debugger;
  1750. maplists.each(function(node){
  1751. var title = node.get("title");
  1752. var name = node.get("name");
  1753. var collapse = node.get("collapse");
  1754. var mapObj = this.data[name];
  1755. if (!mapObj) mapObj = {};
  1756. MWF.require("MWF.widget.Maplist", function(){
  1757. node.empty();
  1758. var maplist = new MWF.widget.Maplist(node, {
  1759. "title": title,
  1760. "collapse": (collapse) ? true : false,
  1761. "onChange": function(){
  1762. //this.data[name] = maplist.toJson();
  1763. //
  1764. var oldData = this.data[name];
  1765. this.changeJsonDate(name, maplist.toJson());
  1766. this.changeStyle(name, oldData);
  1767. this.changeData(name);
  1768. }.bind(this),
  1769. "onDelete": function(key){
  1770. debugger;
  1771. this.module.deletePropertiesOrStyles(name, key);
  1772. }.bind(this)
  1773. });
  1774. maplist.load(mapObj);
  1775. this.maplists[name] = maplist;
  1776. }.bind(this));
  1777. }.bind(this));
  1778. },
  1779. //loadPropertyTab: function(){
  1780. // var tabNodes = this.propertyContent.getElements(".MWFTab");
  1781. // if (tabNodes.length){
  1782. // var tmpNode = this.propertyContent.getFirst();
  1783. // var tabAreaNode = new Element("div", {
  1784. // "styles": this.form.css.propertyTabNode
  1785. // }).inject(tmpNode, "before");
  1786. //
  1787. // MWF.require("MWF.widget.Tab", function(){
  1788. // var tab = new MWF.widget.Tab(tabAreaNode, {"style": "formPropertyList"});
  1789. // tab.load();
  1790. // var tabPages = [];
  1791. // tabNodes.each(function(node){
  1792. // if (node.getStyle("display")!="none"){
  1793. // var page = tab.addTab(node, node.get("title"), false);
  1794. // tabPages.push(page);
  1795. // page.contentScrollNode = new Element("div", {"styles": {"height": "100%", "overflow": "hidden"}}).inject(page.contentNodeArea);
  1796. // node.inject(page.contentScrollNode);
  1797. // this.setScrollBar(page.contentScrollNode, "small", null, null);
  1798. // }
  1799. // }.bind(this));
  1800. // tabPages[0].showTab();
  1801. //
  1802. // this.propertyTab = tab;
  1803. //
  1804. // this.designer.resizeNode();
  1805. // }.bind(this), false);
  1806. // }
  1807. //},
  1808. loadPropertyTab: function(){
  1809. var tabNodes = this.propertyContent.getElements(".MWFTab");
  1810. var groupObject = {}; //data-group 属性可以表示不同的分组
  1811. if (tabNodes.length){
  1812. tabNodes.each( function(node){
  1813. var group = node.get("data-group") || "default";
  1814. groupObject[group] = groupObject[group] || [];
  1815. groupObject[group].push( node );
  1816. }.bind(this))
  1817. }
  1818. for( var group in groupObject ){
  1819. if( group === "default" ){
  1820. var tmpNode = this.propertyContent.getFirst();
  1821. var tabAreaNode = new Element("div", {
  1822. "styles": this.form.css.propertyTabNode
  1823. }).inject(tmpNode, "before");
  1824. MWF.require("MWF.widget.Tab", function(){
  1825. var tab = new MWF.widget.Tab(tabAreaNode, {"style": "formPropertyList"});
  1826. tab.load();
  1827. var tabPages = [];
  1828. groupObject["default"].each(function(node){
  1829. if (node.getStyle("display")!="none"){
  1830. var page = tab.addTab(node, node.get("title"), false);
  1831. tabPages.push(page);
  1832. page.contentScrollNode = new Element("div", {"styles": {"height": "100%", "overflow": "hidden"}}).inject(page.contentNodeArea);
  1833. node.inject(page.contentScrollNode);
  1834. this.setScrollBar(page.contentScrollNode, "small", null, null);
  1835. }
  1836. }.bind(this));
  1837. tabPages[0].showTab();
  1838. this.propertyTab = tab;
  1839. this.designer.resizeNode();
  1840. }.bind(this), false);
  1841. }else{
  1842. var tmpNode = groupObject[group][0];
  1843. var tabAreaNode = new Element("div", {
  1844. "styles": this.form.css.propertyTabNode
  1845. }).inject(tmpNode, "before");
  1846. MWF.require("MWF.widget.Tab", function(){
  1847. var tab = new MWF.widget.Tab(tabAreaNode, {"style": tmpNode.get("data-style") || "formPropertyList"});
  1848. tab.load();
  1849. var tabPages = [];
  1850. groupObject[group].each(function(node) {
  1851. var page = tab.addTab(node, node.get("title"), false);
  1852. tabPages.push(page);
  1853. node.store("tab", page);
  1854. if (node.getStyle("display") === "none"){
  1855. page.disableTab( true );
  1856. node.show();
  1857. }
  1858. }.bind(this));
  1859. for( var i=0; i<tabPages.length; i++ ){
  1860. if( !tabPages[i].disabled ){
  1861. tabPages[i].showTab();
  1862. break
  1863. }
  1864. }
  1865. }.bind(this), false);
  1866. }
  1867. }
  1868. },
  1869. setEditNodeEvent: function(){
  1870. var property = this;
  1871. // var inputs = this.process.propertyListNode.getElements(".editTableInput");
  1872. var inputs = this.propertyContent.getElements("input");
  1873. inputs.each(function(input){
  1874. var jsondata = input.get("name");
  1875. if (this.module){
  1876. var id = this.data.pid;
  1877. //var id = this.form.json.id;
  1878. // input.set("name", this.form.options.mode+id+jsondata);
  1879. input.set("name", id+jsondata);
  1880. }
  1881. if (jsondata){
  1882. var inputType = input.get("type").toLowerCase();
  1883. switch (inputType){
  1884. case "radio":
  1885. input.addEvent("change", function(e){
  1886. property.setRadioValue(jsondata, this);
  1887. });
  1888. input.addEvent("blur", function(e){
  1889. property.setRadioValue(jsondata, this);
  1890. });
  1891. input.addEvent("keydown", function(e){
  1892. e.stopPropagation();
  1893. });
  1894. property.setRadioValue(jsondata, input);
  1895. break;
  1896. case "checkbox":
  1897. input.addEvent("change", function(e){
  1898. property.setCheckboxValue(jsondata, this);
  1899. });
  1900. input.addEvent("click", function(e){
  1901. property.setCheckboxValue(jsondata, this);
  1902. });
  1903. input.addEvent("keydown", function(e){
  1904. e.stopPropagation();
  1905. });
  1906. break;
  1907. default:
  1908. input.addEvent("change", function(e){
  1909. property.setValue(jsondata, this.value, this);
  1910. });
  1911. input.addEvent("blur", function(e){
  1912. property.setValue(jsondata, this.value, this);
  1913. });
  1914. input.addEvent("keydown", function(e){
  1915. if (e.code==13){
  1916. property.setValue(jsondata, this.value, this);
  1917. }
  1918. e.stopPropagation();
  1919. });
  1920. }
  1921. }
  1922. }.bind(this));
  1923. var selects = this.propertyContent.getElements("select");
  1924. selects.each(function(select){
  1925. var jsondata = select.get("name");
  1926. if (jsondata){
  1927. select.addEvent("change", function(e){
  1928. property.setSelectValue(jsondata, this);
  1929. });
  1930. //property.setSelectValue(jsondata, select);
  1931. }
  1932. });
  1933. var textareas = this.propertyContent.getElements("textarea");
  1934. textareas.each(function(input){
  1935. var jsondata = input.get("name");
  1936. if (jsondata){
  1937. input.addEvent("change", function(e){
  1938. property.setValue(jsondata, this.value);
  1939. });
  1940. input.addEvent("blur", function(e){
  1941. property.setValue(jsondata, this.value);
  1942. });
  1943. input.addEvent("keydown", function(e){
  1944. e.stopPropagation();
  1945. });
  1946. }
  1947. }.bind(this));
  1948. },
  1949. changeStyle: function(name, oldData){
  1950. this.module.setPropertiesOrStyles(name, oldData);
  1951. },
  1952. changeData: function(name, input, oldValue){
  1953. this.module._setEditStyle(name, input, oldValue);
  1954. },
  1955. changeJsonDate: function(key, value){
  1956. if (typeOf(key)!=="array") key = [key];
  1957. var o = this.data;
  1958. var len = key.length-1;
  1959. key.each(function(n, i){
  1960. if (!o[n]) o[n] = {};
  1961. if (i<len) o = o[n];
  1962. }.bind(this));
  1963. o[key[len]] = value;
  1964. //this.data[key] = value;
  1965. },
  1966. setRadioValue: function(name, input){
  1967. if (input.checked){
  1968. var i = name.indexOf("*");
  1969. var names = (i==-1) ? name.split(".") : name.substr(i+1, name.length).split(".");
  1970. var value = input.value;
  1971. if (value=="false") value = false;
  1972. if (value=="true") value = true;
  1973. var oldValue = this.data;
  1974. for (var idx = 0; idx<names.length; idx++){
  1975. if (!oldValue[names[idx]]){
  1976. oldValue = null;
  1977. break;
  1978. }else{
  1979. oldValue = oldValue[names[idx]];
  1980. }
  1981. }
  1982. // var value = input.value;
  1983. // if (value==="false") value = false;
  1984. // if (value==="true") value = true;
  1985. //var oldValue = this.data[name];
  1986. this.changeJsonDate(names, value);
  1987. this.changeData(name, input, oldValue);
  1988. }
  1989. },
  1990. setCheckboxValue: function(name, input){
  1991. //var id = this.module.json.id;
  1992. //var id = this.form.json.id;
  1993. var id = this.data.pid;
  1994. // var checkboxList = $$("input[name='"+this.form.options.mode+id+name+"']");
  1995. var checkboxList = $$("input[name='"+id+name+"']");
  1996. var values = [];
  1997. checkboxList.each(function(checkbox){
  1998. if (checkbox.get("checked")){
  1999. values.push(checkbox.value);
  2000. }
  2001. });
  2002. var oldValue = this.data[name];
  2003. //this.data[name] = values;
  2004. this.changeJsonDate(name, values);
  2005. this.changeData(name, input, oldValue);
  2006. },
  2007. setSelectValue: function(name, select){
  2008. var idx = select.selectedIndex;
  2009. var options = select.getElements("option");
  2010. var value = "";
  2011. if (options[idx]){
  2012. value = options[idx].get("value");
  2013. }
  2014. var oldValue = this.data[name];
  2015. //this.data[name] = value;
  2016. this.changeJsonDate(name, value);
  2017. this.changeData(name, select, oldValue);
  2018. },
  2019. setValue: function(name, value, obj){
  2020. if (name==="id"){
  2021. if (value!==this.module.json.id) {
  2022. if (!value) {
  2023. this.designer.notice(MWF.APPFD.LP.notNullId, "error", this.module.form.designer.propertyContentArea, {
  2024. x: "right",
  2025. y: "bottom"
  2026. });
  2027. obj.focus();
  2028. return false;
  2029. } else {
  2030. var check = this.module.form.checkModuleId(value, this.module.json.type);
  2031. if (check.elementConflict) {
  2032. this.designer.notice(MWF.APPFD.LP.repetitionsId, "error", this.module.form.designer.propertyContentArea, {
  2033. x: "right",
  2034. y: "bottom"
  2035. });
  2036. obj.focus();
  2037. return false;
  2038. } else {
  2039. var json = this.module.form.json.moduleList[this.module.json.id];
  2040. this.module.form.json.moduleList[value] = json;
  2041. delete this.module.form.json.moduleList[this.module.json.id];
  2042. }
  2043. }
  2044. // if (this.module.form.json.moduleList[value]){
  2045. // this.designer.notice(MWF.APPFD.LP.repetitionsId, "error", this.module.form.designer.propertyContentArea, {x:"right", y:"bottom"});
  2046. // obj.focus();
  2047. // return false;
  2048. // }else{
  2049. // var flag = false;
  2050. // if (this.module.form.subformList){
  2051. // Object.each(this.module.form.subformList, function(o, k){
  2052. // if (o.subformData.moduleList[value] && o.subformData.moduleList[value] ) flag = true;
  2053. // });
  2054. // }
  2055. // if (flag){
  2056. // this.designer.notice(MWF.APPFD.LP.repetitionsId, "error", this.module.form.designer.propertyContentArea, {x:"right", y:"bottom"});
  2057. // obj.focus();
  2058. // return false;
  2059. // }else{
  2060. // var json = this.module.form.json.moduleList[this.module.json.id];
  2061. // this.module.form.json.moduleList[value]=json;
  2062. // delete this.module.form.json.moduleList[this.module.json.id];
  2063. // }
  2064. // }
  2065. }
  2066. }
  2067. //var oldValue = this.data[name];
  2068. var names = name.split(".");
  2069. var oldValue = this.data;
  2070. for (var idx = 0; idx<names.length; idx++){
  2071. if (!oldValue[names[idx]]){
  2072. oldValue = null;
  2073. break;
  2074. }else{
  2075. oldValue = oldValue[names[idx]];
  2076. }
  2077. }
  2078. //this.data[name] = value;
  2079. this.changeJsonDate(names, value);
  2080. this.changeData(name, obj, oldValue);
  2081. },
  2082. setEditNodeStyles: function(node){
  2083. var nodes = node.getChildren();
  2084. if (nodes.length){
  2085. nodes.each(function(el){
  2086. var cName = el.get("class");
  2087. if (cName){
  2088. if (this.form.css[cName]) el.setStyles(this.form.css[cName]);
  2089. }
  2090. this.setEditNodeStyles(el);
  2091. }.bind(this));
  2092. }
  2093. },
  2094. loadScriptInput: function(){
  2095. var scriptNodes = this.propertyContent.getElements(".MWFScript");
  2096. scriptNodes.each(function(node){
  2097. MWF.require("MWF.widget.ScriptEditor", function(){
  2098. var script = new MWF.widget.ScriptEditor(node, {
  2099. "onPostSave": function(script){
  2100. this.saveScriptItem(node, script);
  2101. }.bind(this),
  2102. "onQueryDelete": function(script){
  2103. this.deleteScriptItem(node, script);
  2104. }.bind(this)
  2105. });
  2106. this.setScriptItems(script, node);
  2107. }.bind(this));
  2108. }.bind(this));
  2109. },
  2110. deleteScriptItem: function(node, script){
  2111. var jsondata = node.get("name");
  2112. this.data[jsondata].erase(script.data.id);
  2113. this.process.scripts[script.data.id] = null;
  2114. delete this.process.scripts[script.data.id];
  2115. this.process.process.scriptList.erase(script.data);
  2116. },
  2117. saveScriptItem: function(node, script){
  2118. var jsondata = node.get("name");
  2119. var scriptList = this.data[jsondata];
  2120. var data = script.data;
  2121. var scriptData = this.process.scripts[script.data.id];
  2122. if (!scriptData){
  2123. this.process.process.scriptList.push(data);
  2124. this.process.scripts[script.data.id] = data;
  2125. }
  2126. if (scriptList.indexOf(data.id) == -1){
  2127. this.data[jsondata].push(data.id);
  2128. }
  2129. },
  2130. setScriptItems: function(script, node){
  2131. var jsondata = node.get("name");
  2132. var scriptList = this.data[jsondata];
  2133. scriptList.each(function(id){
  2134. if (id){
  2135. var data = this.process.scripts[id];
  2136. if (data) script.setScriptItem(data);
  2137. }
  2138. }.bind(this));
  2139. }
  2140. });
  2141. MWF.xApplication.process.FormDesigner.PropertyMulti = new Class({
  2142. Extends: MWF.xApplication.process.FormDesigner.Property,
  2143. Implements: [Options, Events],
  2144. initialize: function(form, modules, propertyNode, designer, options){
  2145. this.setOptions(options);
  2146. this.modules = modules;
  2147. this.form = form;
  2148. // this.data = module.json;
  2149. this.data = {};
  2150. this.htmlPath = this.options.path;
  2151. this.designer = designer;
  2152. this.maplists = {};
  2153. this.propertyNode = propertyNode;
  2154. },
  2155. load: function(){
  2156. if (this.fireEvent("queryLoad")){
  2157. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  2158. this.htmlString = responseText;
  2159. MWF.require("MWF.widget.JsonTemplate", function(){
  2160. this.fireEvent("postLoad");
  2161. }.bind(this));
  2162. }.bind(this));
  2163. }
  2164. },
  2165. show: function(){
  2166. if (!this.propertyContent){
  2167. if (this.htmlString){
  2168. this.JsonTemplate = new MWF.widget.JsonTemplate({}, this.htmlString);
  2169. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyNode);
  2170. this.propertyContent.set("html", this.JsonTemplate.load());
  2171. this.setEditNodeEvent();
  2172. this.setEditNodeStyles(this.propertyContent);
  2173. this.loadPropertyTab();
  2174. this.loadMaplist();
  2175. this.loadScriptArea();
  2176. this.loadTreeData();
  2177. this.loadArrayList();
  2178. //this.loadEventsEditor();
  2179. //this.loadHTMLArea();
  2180. //this.loadJSONArea();
  2181. // this.loadScriptInput();
  2182. //MWF.process.widget.EventsEditor
  2183. }
  2184. }else{
  2185. this.propertyContent.setStyle("display", "block");
  2186. }
  2187. },
  2188. hide: function(){
  2189. if (this.propertyContent) this.propertyContent.destroy();
  2190. },
  2191. changeStyle: function(name){
  2192. this.modules.each(function(module){
  2193. module.setPropertiesOrStyles(name);
  2194. }.bind(this));
  2195. },
  2196. changeData: function(name, input, oldValue){
  2197. this.modules.each(function(module){
  2198. module._setEditStyle(name, input, oldValue);
  2199. }.bind(this));
  2200. },
  2201. changeJsonDate: function(key, value){
  2202. //alert(key+": "+value );
  2203. this.modules.each(function(module){
  2204. module.json[key] = value;
  2205. }.bind(this));
  2206. },
  2207. });