Property.js 97 KB

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