Property.js 98 KB

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