Property.js 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331
  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 queryStatementNodes = this.propertyContent.getElements(".MWFQueryStatementSelect");
  1173. var querystatNodes = this.propertyContent.getElements(".MWFQueryStatSelect");
  1174. var fileNodes = this.propertyContent.getElements(".MWFImageFileSelect");
  1175. var processFileNodes = this.propertyContent.getElements(".MWFProcessImageFileSelect");
  1176. var scriptNodes = this.propertyContent.getElements(".MWFScriptSelect");
  1177. var formStyleNodes = this.propertyContent.getElements(".MWFFormStyleSelect");
  1178. var dictionaryNodes = this.propertyContent.getElements(".MWFDictionarySelect");
  1179. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  1180. personIdentityNodes.each(function(node){
  1181. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1182. "type": "identity",
  1183. "names": this.data[node.get("name")],
  1184. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  1185. });
  1186. }.bind(this));
  1187. personUnitNodes.each(function(node){
  1188. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1189. "type": "unit",
  1190. "names": this.data[node.get("name")],
  1191. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  1192. });
  1193. }.bind(this));
  1194. dutyNodes.each(function(node){
  1195. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1196. "type": "duty",
  1197. "names": this.data[node.get("name")],
  1198. "onChange": function(ids){this.addDutyItem(node, ids);}.bind(this),
  1199. "onRemoveDuty": function(item){this.removeDutyItem(node, item);}.bind(this)
  1200. });
  1201. }.bind(this));
  1202. dutyNameNodes.each(function(node){
  1203. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1204. "type": "dutyName",
  1205. "names": this.data[node.get("name")],
  1206. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  1207. });
  1208. }.bind(this));
  1209. viewNodes.each(function(node){
  1210. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1211. "type": "View",
  1212. "count": 1,
  1213. "names": [this.data[node.get("name")]],
  1214. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  1215. });
  1216. }.bind(this));
  1217. cmsviewNodes.each(function(node){
  1218. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1219. "type": "CMSView",
  1220. "count": 1,
  1221. "names": [this.data[node.get("name")]],
  1222. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  1223. });
  1224. }.bind(this));
  1225. queryviewNodes.each(function(node){
  1226. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1227. "type": "QueryView",
  1228. "count": 1,
  1229. "names": [this.data[node.get("name")]],
  1230. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  1231. });
  1232. }.bind(this));
  1233. queryStatementNodes.each(function(node){
  1234. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1235. "type": "QueryStatement",
  1236. "count": 1,
  1237. "names": [this.data[node.get("name")]],
  1238. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  1239. });
  1240. }.bind(this));
  1241. querystatNodes.each(function(node){
  1242. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1243. "type": "QueryStat",
  1244. "count": 1,
  1245. "names": [this.data[node.get("name")]],
  1246. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  1247. });
  1248. }.bind(this));
  1249. scriptNodes.each(function(node){
  1250. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1251. "type": "Script",
  1252. "count": node.dataset["count"] || 1,
  1253. "names": (!node.dataset["count"] || node.dataset["count"].toInt()==1) ? [this.data[node.get("name")]] : this.data[node.get("name")],
  1254. "onChange": function(ids){
  1255. this.saveScriptSelectItem(node, ids);
  1256. }.bind(this)
  1257. });
  1258. }.bind(this));
  1259. var _self = this;
  1260. formStyleNodes.each(function(node){
  1261. debugger;
  1262. var data = this.data[node.get("name")];
  1263. if( typeOf( data ) === "string" ){
  1264. for( var key in this.module.form.stylesList ){
  1265. var s = this.module.form.stylesList[key];
  1266. if( ((!data && key=="default") || (data==key)) ){
  1267. data = {
  1268. name : s.name,
  1269. id : key
  1270. };
  1271. break;
  1272. }
  1273. }
  1274. }
  1275. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1276. "type": "FormStyle",
  1277. "count": 1,
  1278. "names": [data],
  1279. "selectorOptions" : {
  1280. "mode" : ( this.form.options.mode || "" ).toLowerCase() === "mobile" ? "mobile" : "pc"
  1281. },
  1282. "validFun" : function (ids) {
  1283. var flag = true;
  1284. if( ids.length === 0 ){
  1285. this.designer.notice(MWF.APPFD.LP.mustSelectFormStyle, "error");
  1286. flag = false;
  1287. }else if( ids[0].data.type === "script" ){
  1288. this.designer.actions.getScriptByName( ids[0].data.name, ids[0].data.application, function( json ) {
  1289. debugger;
  1290. try{
  1291. var f = eval("(function(){\n return "+json.data.text+"\n})");
  1292. var j = f();
  1293. if( typeOf(j) !== "object" ){
  1294. this.designer.notice( MWF.APPFD.LP.notValidJson, "error" );
  1295. flag = false;
  1296. }
  1297. }catch (e) {
  1298. this.designer.notice( MWF.APPFD.LP.notValidJson +":"+ e.message, "error" );
  1299. flag = false;
  1300. }
  1301. }.bind(this), function () {
  1302. flag = false;
  1303. }, false);
  1304. }
  1305. return flag;
  1306. }.bind(this),
  1307. "onChange": function(ids){
  1308. var d = ids[0].data;
  1309. var data;
  1310. if( d.type === "script" ){
  1311. data = {
  1312. "type" : "script",
  1313. "name": d.name,
  1314. "alias": d.alias,
  1315. "id": d.id,
  1316. "appName" : d.appName || d.applicationName,
  1317. "appId": d.appId,
  1318. "application": d.application
  1319. };
  1320. }else{
  1321. data = d.id;
  1322. }
  1323. var name = node.get("name");
  1324. var oldValue = this.data[name];
  1325. this.data[name] = data;
  1326. this.changeData(name, node, oldValue);
  1327. }.bind(this)
  1328. });
  1329. var next = node.getNext();
  1330. if( next && next.get("class") === "MWFScriptSelectRefresh" ){
  1331. var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(next);
  1332. refreshNode.addEvent("click", function(e){
  1333. _self.changeData(this.get("name"), this );
  1334. }.bind(node));
  1335. }
  1336. }.bind(this));
  1337. dictionaryNodes.each(function(node){
  1338. var data = this.data[node.get("name")];
  1339. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1340. "type": "Dictionary",
  1341. "count": 0,
  1342. "names": typeOf(data)==="array" ? data : [data],
  1343. "onChange": function(ids){
  1344. var data = [];
  1345. var name = node.get("name");
  1346. if( ids.length > 0 ){
  1347. // var d = ids[0].data;
  1348. ids.each( function (id) {
  1349. debugger;
  1350. var d = id.data;
  1351. data.push({
  1352. "type" : "dictionary",
  1353. "name": d.name,
  1354. "alias": d.alias,
  1355. "id": d.id,
  1356. "appName" : d.appName || d.applicationName,
  1357. "appAlias" : d.appAlias || d.applicationAlias,
  1358. "appId": d.appId,
  1359. "application": d.application,
  1360. "appType" : d.appType
  1361. })
  1362. });
  1363. }
  1364. var oldValue = this.data[name];
  1365. this.data[name] = data;
  1366. this.changeData(name, node, oldValue);
  1367. }.bind(this)
  1368. });
  1369. }.bind(this));
  1370. fileNodes.each(function(node){
  1371. var d = this.data[node.get("name")];
  1372. var data = d || {};
  1373. //this.form
  1374. if (d && typeOf(d)==="string"){
  1375. if (this.form.page){
  1376. data = {"id": d, "portal": this.form.application}
  1377. }else{
  1378. data = {"id": d, "application": this.form.application}
  1379. }
  1380. }
  1381. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1382. "type": "PortalFile",
  1383. "count": 1,
  1384. "isImage": true,
  1385. "values": (data.id) ? [data.id] : [],
  1386. "onChange": function(ids){this.saveFileItem(node, ids);}.bind(this)
  1387. });
  1388. }.bind(this));
  1389. processFileNodes.each(function(node){
  1390. var d = this.data[node.get("name")];
  1391. var data = d || {};
  1392. //this.form
  1393. if (d && typeOf(d)==="string"){
  1394. if (this.form.page){
  1395. data = {"id": d, "portal": this.form.application}
  1396. }else{
  1397. data = {"id": d, "application": this.form.application}
  1398. }
  1399. }
  1400. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1401. "type": "ProcessFile",
  1402. "count": 1,
  1403. "isImage": true,
  1404. "values": (data.id) ? [data.id] : [],
  1405. "onChange": function(ids){this.saveFileItem(node, ids);}.bind(this)
  1406. });
  1407. }.bind(this));
  1408. }.bind(this));
  1409. },
  1410. loadDictionaryIncluder : function(){
  1411. var nodes = this.propertyContent.getElements(".MWFDictionaryIncluder");
  1412. if (nodes.length){
  1413. nodes.each(function(node){
  1414. var name = node.get("name");
  1415. MWF.xDesktop.requireApp("process.FormDesigner", "widget.DictionaryIncluder", function(){
  1416. var dictionaryIncluder = new MWF.xApplication.process.FormDesigner.widget.DictionaryIncluder(node, this.designer, {
  1417. "onChange": function(){
  1418. var data = dictionaryIncluder.getData();
  1419. this.data[name] = data;
  1420. }.bind(this)
  1421. });
  1422. dictionaryIncluder.load(this.data[name])
  1423. }.bind(this));
  1424. }.bind(this));
  1425. }
  1426. },
  1427. loadScriptIncluder : function(){
  1428. var nodes = this.propertyContent.getElements(".MWFScriptIncluder");
  1429. if (nodes.length){
  1430. nodes.each(function(node){
  1431. var name = node.get("name");
  1432. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ScriptIncluder", function(){
  1433. var scriptIncluder = new MWF.xApplication.process.FormDesigner.widget.ScriptIncluder(node, this.designer, {
  1434. "onChange": function(){
  1435. var data = scriptIncluder.getData();
  1436. this.data[name] = data;
  1437. }.bind(this)
  1438. });
  1439. scriptIncluder.load(this.data[name])
  1440. }.bind(this));
  1441. }.bind(this));
  1442. }
  1443. },
  1444. saveFileItem: function(node, ids){
  1445. if (ids[0]){
  1446. var file = ids[0].data;
  1447. this.data[node.get("name")] = file;
  1448. }else{
  1449. this.data[node.get("name")] = null;
  1450. }
  1451. this.changeData(node.get("name"));
  1452. },
  1453. saveViewItem: function(node, ids){
  1454. if (ids[0]){
  1455. var view = ids[0].data;
  1456. var data = {
  1457. "name": view.name,
  1458. "alias": view.alias,
  1459. "id": view.id,
  1460. "appName" : view.appName || view.applicationName || view.query,
  1461. "appId": view.appId,
  1462. "application": view.application || view.query
  1463. };
  1464. this.data[node.get("name")] = data;
  1465. }else{
  1466. this.data[node.get("name")] = null;
  1467. }
  1468. if (this.module._checkView) this.module._checkView();
  1469. },
  1470. removeViewItem: function(node, item){
  1471. },
  1472. saveScriptSelectItem: function(node, ids){
  1473. var count = (node.dataset["count"] || 1).toInt();
  1474. if (count==1){
  1475. if (ids[0]){
  1476. var script = ids[0].data;
  1477. var data = {
  1478. "appType": script.appType,
  1479. "type" : "script",
  1480. "name": script.name,
  1481. "alias": script.alias,
  1482. "id": script.id,
  1483. "appName" : script.appName || script.applicationName,
  1484. "appId": script.appId,
  1485. "application": script.application
  1486. };
  1487. var name = node.get("name");
  1488. var oldValue = this.data[name];
  1489. this.data[name] = data;
  1490. // this.changeJsonDate(name, data );
  1491. this.changeData(name, node, oldValue);
  1492. }else{
  1493. // this.data[node.get("name")] = null;
  1494. }
  1495. }else{
  1496. var scriptValues = [];
  1497. ids.each(function(s){
  1498. var scriptValue = {
  1499. "appType": s.data.appType,
  1500. "type" : "script",
  1501. "name": s.data.name,
  1502. "alias": s.data.alias,
  1503. "id": s.data.id,
  1504. "appName" : s.data.appName || s.data.applicationName,
  1505. "appId": s.data.appId,
  1506. "application": s.data.application
  1507. }
  1508. scriptValues.push(scriptValue);
  1509. }.bind(this));
  1510. var name = node.get("name");
  1511. var oldValue = this.data[name];
  1512. this.data[name] = scriptValues;
  1513. this.changeData(name, node, oldValue);
  1514. }
  1515. },
  1516. removeDutyItem: function(node, item){
  1517. if (item.data.id){
  1518. var values = JSON.decode(this.data[node.get("name")] || []);
  1519. var value = values.filter(function(v){
  1520. return v.id == item.data.id;
  1521. });
  1522. value.each(function(v) {
  1523. values = values.erase(v);
  1524. });
  1525. this.data[node.get("name")] = JSON.encode(values);
  1526. }
  1527. item.node.destroy();
  1528. MWF.release(item);
  1529. delete item;
  1530. },
  1531. addDutyItem: function(node, ids){
  1532. var value = this.data[node.get("name")] || "";
  1533. if (!value) value = "[]";
  1534. var values = JSON.decode(value);
  1535. ids.each(function(id){
  1536. if (id.data.dutyId){
  1537. for (var i=0; i<values.length; i++){
  1538. if (values[i].dutyId===id.data.dutyId){
  1539. values[i].name = id.data.name;
  1540. values[i].code = id.data.code;
  1541. break;
  1542. }
  1543. }
  1544. }else{
  1545. id.data.dutyId = new MWF.widget.UUID().toString();
  1546. values.push({"name": id.data.name, "id": id.data.id, "dutyId": id.data.dutyId, "code": id.data.code});
  1547. }
  1548. }.bind(this));
  1549. this.data[node.get("name")] = JSON.encode(values);
  1550. },
  1551. loadFormFieldInput: function(){
  1552. var fieldNodes = this.propertyContent.getElements(".MWFFormFieldPerson");
  1553. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  1554. fieldNodes.each(function(node){
  1555. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.form.designer, {
  1556. "type": "formField",
  1557. "application": this.form.json.application,
  1558. "fieldType": "person",
  1559. "names": this.data[node.get("name")],
  1560. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  1561. });
  1562. }.bind(this));
  1563. }.bind(this));
  1564. },
  1565. savePersonItem: function(node, ids){
  1566. var values = [];
  1567. ids.each(function(id){
  1568. values.push(MWF.org.parseOrgData(id.data));
  1569. }.bind(this));
  1570. this.data[node.get("name")] = values;
  1571. },
  1572. loadScriptArea: function(){
  1573. var scriptAreas = this.propertyContent.getElements(".MWFScriptArea");
  1574. var formulaAreas = this.propertyContent.getElements(".MWFFormulaArea");
  1575. this.loadScriptEditor(scriptAreas);
  1576. this.loadScriptEditor(formulaAreas, "formula");
  1577. },
  1578. loadScriptEditor: function(scriptAreas, style){
  1579. scriptAreas.each(function(node){
  1580. var title = node.get("title");
  1581. var name = node.get("name");
  1582. if (!this.data[name]) this.data[name] = {"code": "", "html": ""};
  1583. var scriptContent = this.data[name];
  1584. MWF.require("MWF.widget.ScriptArea", function(){
  1585. var scriptArea = new MWF.widget.ScriptArea(node, {
  1586. "title": title,
  1587. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  1588. "maxObj": this.designer.formContentNode || this.designer.pageContentNode,
  1589. "onChange": function(){
  1590. //this.data[name] = scriptArea.toJson();
  1591. if (!this.data[name]){
  1592. this.data[name] = {"code": "", "html": ""};
  1593. if (this.module.form.scriptDesigner) this.module.form.scriptDesigner.addScriptItem(this.data[name], "code", this.data, name);
  1594. }
  1595. var json = scriptArea.toJson();
  1596. this.data[name].code = json.code;
  1597. //this.data[name].html = json.html;
  1598. }.bind(this),
  1599. "onSave": function(){
  1600. this.designer.saveForm();
  1601. }.bind(this),
  1602. "style": style || "default",
  1603. "runtime": "web"
  1604. });
  1605. scriptArea.load(scriptContent);
  1606. }.bind(this));
  1607. }.bind(this));
  1608. },
  1609. loadCssArea: function(style){
  1610. var cssAreas = this.propertyContent.getElements(".MWFCssArea");
  1611. cssAreas.each(function(node){
  1612. var title = node.get("title");
  1613. var name = node.get("name");
  1614. if (!this.data[name]) this.data[name] = {"code": "", "html": ""};
  1615. var cssContent = this.data[name];
  1616. o2.require("o2.widget.CssArea", function(){
  1617. var cssArea = new o2.widget.CssArea(node, {
  1618. "title": title,
  1619. "maxObj": this.designer.formContentNode || this.designer.pageContentNode,
  1620. "onChange": function(){
  1621. //this.data[name] = scriptArea.toJson();
  1622. if (!this.data[name]){
  1623. this.data[name] = {"code": "", "html": ""};
  1624. if (this.module.form.scriptDesigner) this.module.form.scriptDesigner.addScriptItem(this.data[name], "code", this.data, name);
  1625. }
  1626. var json = cssArea.toJson();
  1627. this.data[name].code = json.code;
  1628. cssArea.isChanged = true;
  1629. //this.data[name].html = json.html;
  1630. }.bind(this),
  1631. "onBlur": function(){
  1632. if (cssArea.isChanged){
  1633. this.changeData(name, node, "");
  1634. cssArea.isChanged = false;
  1635. }
  1636. }.bind(this),
  1637. "onSave": function(){
  1638. this.designer.saveForm();
  1639. }.bind(this),
  1640. "style": style || "default"
  1641. });
  1642. cssArea.load(cssContent);
  1643. }.bind(this));
  1644. }.bind(this));
  1645. },
  1646. loadActionStylesArea: function(){
  1647. var _self = this;
  1648. var actionAreas = this.propertyContent.getElements(".MWFActionStylesArea");
  1649. actionAreas.each(function(node){
  1650. var name = node.get("name");
  1651. var actionStyles = this.data[name];
  1652. MWF.require("MWF.widget.Maplist", function(){
  1653. var maps = [];
  1654. Object.each(actionStyles, function(v, k){
  1655. var mapNode = new Element("div").inject(node);
  1656. mapNode.empty();
  1657. var maplist = new MWF.widget.Maplist(mapNode, {
  1658. "title": k,
  1659. "collapse": true,
  1660. "onChange": function(){
  1661. var oldData = _self.data[name];
  1662. maps.each(function(o){
  1663. _self.data[name][o.key] = o.map.toJson();
  1664. }.bind(this));
  1665. _self.changeData(name, node, oldData);
  1666. }
  1667. });
  1668. maps.push({"key": k, "map": maplist});
  1669. maplist.load(v);
  1670. }.bind(this));
  1671. }.bind(this));
  1672. }.bind(this));
  1673. },
  1674. loadActionArea: function(){
  1675. var actionAreas = this.propertyContent.getElements(".MWFActionArea");
  1676. actionAreas.each(function(node){
  1677. var name = node.get("name");
  1678. var actionContent = this.data[name];
  1679. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ActionsEditor", function(){
  1680. // debugger;
  1681. // var actionEditor = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor(node, this.designer, {
  1682. // "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  1683. // "noCreate": true,
  1684. // "noDelete": true,
  1685. // "noCode": true,
  1686. // "onChange": function(){
  1687. // this.data[name] = actionEditor.data;
  1688. // }.bind(this)
  1689. // });
  1690. // actionEditor.load(this.module.defaultToolBarsData);
  1691. var actionEditor = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor(node, this.designer, this.data, {
  1692. "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  1693. "onChange": function(){
  1694. this.data[name] = actionEditor.data;
  1695. this.changeData(name);
  1696. }.bind(this)
  1697. });
  1698. actionEditor.load(actionContent);
  1699. }.bind(this));
  1700. }.bind(this));
  1701. var actionAreas = this.propertyContent.getElements(".MWFDefaultActionArea");
  1702. actionAreas.each(function(node){
  1703. var name = node.get("name");
  1704. var actionContent = this.data[name] || this.module.defaultToolBarsData;
  1705. MWF.xDesktop.requireApp("process.FormDesigner", "widget.ActionsEditor", function(){
  1706. var actionEditor = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor(node, this.designer, this.data, {
  1707. "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  1708. "isSystemTool" : true,
  1709. "noCreate": true,
  1710. "noDelete": false,
  1711. "noCode": true,
  1712. "noReadShow": true,
  1713. "target" : node.get("data-target"),
  1714. "noEditShow": true,
  1715. "onChange": function(){
  1716. this.data[name] = actionEditor.data;
  1717. this.changeData(name);
  1718. }.bind(this)
  1719. });
  1720. actionEditor.load(actionContent);
  1721. // var actionEditor = new MWF.xApplication.process.FormDesigner.widget.ActionsEditor(node, this.designer, {
  1722. // "maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  1723. // "onChange": function(){
  1724. // this.data[name] = actionEditor.data;
  1725. // }.bind(this)
  1726. // });
  1727. // actionEditor.load(actionContent);
  1728. }.bind(this));
  1729. }.bind(this));
  1730. },
  1731. loadMaplist: function(){
  1732. var maplists = this.propertyContent.getElements(".MWFMaplist");
  1733. debugger;
  1734. maplists.each(function(node){
  1735. var title = node.get("title");
  1736. var name = node.get("name");
  1737. var collapse = node.get("collapse");
  1738. var mapObj = this.data[name];
  1739. if (!mapObj) mapObj = {};
  1740. MWF.require("MWF.widget.Maplist", function(){
  1741. node.empty();
  1742. var maplist = new MWF.widget.Maplist(node, {
  1743. "title": title,
  1744. "collapse": (collapse) ? true : false,
  1745. "onChange": function(){
  1746. //this.data[name] = maplist.toJson();
  1747. //
  1748. var oldData = this.data[name];
  1749. this.changeJsonDate(name, maplist.toJson());
  1750. this.changeStyle(name, oldData);
  1751. this.changeData(name);
  1752. }.bind(this),
  1753. "onDelete": function(key){
  1754. debugger;
  1755. this.module.deletePropertiesOrStyles(name, key);
  1756. }.bind(this)
  1757. });
  1758. maplist.load(mapObj);
  1759. this.maplists[name] = maplist;
  1760. }.bind(this));
  1761. }.bind(this));
  1762. },
  1763. //loadPropertyTab: function(){
  1764. // var tabNodes = this.propertyContent.getElements(".MWFTab");
  1765. // if (tabNodes.length){
  1766. // var tmpNode = this.propertyContent.getFirst();
  1767. // var tabAreaNode = new Element("div", {
  1768. // "styles": this.form.css.propertyTabNode
  1769. // }).inject(tmpNode, "before");
  1770. //
  1771. // MWF.require("MWF.widget.Tab", function(){
  1772. // var tab = new MWF.widget.Tab(tabAreaNode, {"style": "formPropertyList"});
  1773. // tab.load();
  1774. // var tabPages = [];
  1775. // tabNodes.each(function(node){
  1776. // if (node.getStyle("display")!="none"){
  1777. // var page = tab.addTab(node, node.get("title"), false);
  1778. // tabPages.push(page);
  1779. // page.contentScrollNode = new Element("div", {"styles": {"height": "100%", "overflow": "hidden"}}).inject(page.contentNodeArea);
  1780. // node.inject(page.contentScrollNode);
  1781. // this.setScrollBar(page.contentScrollNode, "small", null, null);
  1782. // }
  1783. // }.bind(this));
  1784. // tabPages[0].showTab();
  1785. //
  1786. // this.propertyTab = tab;
  1787. //
  1788. // this.designer.resizeNode();
  1789. // }.bind(this), false);
  1790. // }
  1791. //},
  1792. loadPropertyTab: function(){
  1793. var tabNodes = this.propertyContent.getElements(".MWFTab");
  1794. var groupObject = {}; //data-group 属性可以表示不同的分组
  1795. if (tabNodes.length){
  1796. tabNodes.each( function(node){
  1797. var group = node.get("data-group") || "default";
  1798. groupObject[group] = groupObject[group] || [];
  1799. groupObject[group].push( node );
  1800. }.bind(this))
  1801. }
  1802. for( var group in groupObject ){
  1803. if( group === "default" ){
  1804. var tmpNode = this.propertyContent.getFirst();
  1805. var tabAreaNode = new Element("div", {
  1806. "styles": this.form.css.propertyTabNode
  1807. }).inject(tmpNode, "before");
  1808. MWF.require("MWF.widget.Tab", function(){
  1809. var tab = new MWF.widget.Tab(tabAreaNode, {"style": "formPropertyList"});
  1810. tab.load();
  1811. var tabPages = [];
  1812. groupObject["default"].each(function(node){
  1813. if (node.getStyle("display")!="none"){
  1814. var page = tab.addTab(node, node.get("title"), false);
  1815. tabPages.push(page);
  1816. page.contentScrollNode = new Element("div", {"styles": {"height": "100%", "overflow": "hidden"}}).inject(page.contentNodeArea);
  1817. node.inject(page.contentScrollNode);
  1818. this.setScrollBar(page.contentScrollNode, "small", null, null);
  1819. }
  1820. }.bind(this));
  1821. tabPages[0].showTab();
  1822. this.propertyTab = tab;
  1823. this.designer.resizeNode();
  1824. }.bind(this), false);
  1825. }else{
  1826. var tmpNode = groupObject[group][0];
  1827. var tabAreaNode = new Element("div", {
  1828. "styles": this.form.css.propertyTabNode
  1829. }).inject(tmpNode, "before");
  1830. MWF.require("MWF.widget.Tab", function(){
  1831. var tab = new MWF.widget.Tab(tabAreaNode, {"style": tmpNode.get("data-style") || "formPropertyList"});
  1832. tab.load();
  1833. var tabPages = [];
  1834. groupObject[group].each(function(node) {
  1835. var page = tab.addTab(node, node.get("title"), false);
  1836. tabPages.push(page);
  1837. node.store("tab", page);
  1838. if (node.getStyle("display") === "none"){
  1839. page.disableTab( true );
  1840. node.show();
  1841. }
  1842. }.bind(this));
  1843. for( var i=0; i<tabPages.length; i++ ){
  1844. if( !tabPages[i].disabled ){
  1845. tabPages[i].showTab();
  1846. break
  1847. }
  1848. }
  1849. }.bind(this), false);
  1850. }
  1851. }
  1852. },
  1853. setEditNodeEvent: function(){
  1854. var property = this;
  1855. // var inputs = this.process.propertyListNode.getElements(".editTableInput");
  1856. var inputs = this.propertyContent.getElements("input");
  1857. inputs.each(function(input){
  1858. var jsondata = input.get("name");
  1859. if (this.module){
  1860. var id = this.data.pid;
  1861. //var id = this.form.json.id;
  1862. // input.set("name", this.form.options.mode+id+jsondata);
  1863. input.set("name", id+jsondata);
  1864. }
  1865. if (jsondata){
  1866. var inputType = input.get("type").toLowerCase();
  1867. switch (inputType){
  1868. case "radio":
  1869. input.addEvent("change", function(e){
  1870. property.setRadioValue(jsondata, this);
  1871. });
  1872. input.addEvent("blur", function(e){
  1873. property.setRadioValue(jsondata, this);
  1874. });
  1875. input.addEvent("keydown", function(e){
  1876. e.stopPropagation();
  1877. });
  1878. property.setRadioValue(jsondata, input);
  1879. break;
  1880. case "checkbox":
  1881. input.addEvent("change", function(e){
  1882. property.setCheckboxValue(jsondata, this);
  1883. });
  1884. input.addEvent("click", function(e){
  1885. property.setCheckboxValue(jsondata, this);
  1886. });
  1887. input.addEvent("keydown", function(e){
  1888. e.stopPropagation();
  1889. });
  1890. break;
  1891. default:
  1892. input.addEvent("change", function(e){
  1893. property.setValue(jsondata, this.value, this);
  1894. });
  1895. input.addEvent("blur", function(e){
  1896. property.setValue(jsondata, this.value, this);
  1897. });
  1898. input.addEvent("keydown", function(e){
  1899. if (e.code==13){
  1900. property.setValue(jsondata, this.value, this);
  1901. }
  1902. e.stopPropagation();
  1903. });
  1904. }
  1905. }
  1906. }.bind(this));
  1907. var selects = this.propertyContent.getElements("select");
  1908. selects.each(function(select){
  1909. var jsondata = select.get("name");
  1910. if (jsondata){
  1911. select.addEvent("change", function(e){
  1912. property.setSelectValue(jsondata, this);
  1913. });
  1914. //property.setSelectValue(jsondata, select);
  1915. }
  1916. });
  1917. var textareas = this.propertyContent.getElements("textarea");
  1918. textareas.each(function(input){
  1919. var jsondata = input.get("name");
  1920. if (jsondata){
  1921. input.addEvent("change", function(e){
  1922. property.setValue(jsondata, this.value);
  1923. });
  1924. input.addEvent("blur", function(e){
  1925. property.setValue(jsondata, this.value);
  1926. });
  1927. input.addEvent("keydown", function(e){
  1928. e.stopPropagation();
  1929. });
  1930. }
  1931. }.bind(this));
  1932. },
  1933. changeStyle: function(name, oldData){
  1934. this.module.setPropertiesOrStyles(name, oldData);
  1935. },
  1936. changeData: function(name, input, oldValue){
  1937. this.module._setEditStyle(name, input, oldValue);
  1938. },
  1939. changeJsonDate: function(key, value){
  1940. if (typeOf(key)!=="array") key = [key];
  1941. var o = this.data;
  1942. var len = key.length-1;
  1943. key.each(function(n, i){
  1944. if (!o[n]) o[n] = {};
  1945. if (i<len) o = o[n];
  1946. }.bind(this));
  1947. o[key[len]] = value;
  1948. //this.data[key] = value;
  1949. },
  1950. setRadioValue: function(name, input){
  1951. if (input.checked){
  1952. var i = name.indexOf("*");
  1953. var names = (i==-1) ? name.split(".") : name.substr(i+1, name.length).split(".");
  1954. var value = input.value;
  1955. if (value=="false") value = false;
  1956. if (value=="true") value = true;
  1957. var oldValue = this.data;
  1958. for (var idx = 0; idx<names.length; idx++){
  1959. if (!oldValue[names[idx]]){
  1960. oldValue = null;
  1961. break;
  1962. }else{
  1963. oldValue = oldValue[names[idx]];
  1964. }
  1965. }
  1966. // var value = input.value;
  1967. // if (value==="false") value = false;
  1968. // if (value==="true") value = true;
  1969. //var oldValue = this.data[name];
  1970. this.changeJsonDate(names, value);
  1971. this.changeData(name, input, oldValue);
  1972. }
  1973. },
  1974. setCheckboxValue: function(name, input){
  1975. //var id = this.module.json.id;
  1976. //var id = this.form.json.id;
  1977. var id = this.data.pid;
  1978. // var checkboxList = $$("input[name='"+this.form.options.mode+id+name+"']");
  1979. var checkboxList = $$("input[name='"+id+name+"']");
  1980. var values = [];
  1981. checkboxList.each(function(checkbox){
  1982. if (checkbox.get("checked")){
  1983. values.push(checkbox.value);
  1984. }
  1985. });
  1986. var oldValue = this.data[name];
  1987. //this.data[name] = values;
  1988. this.changeJsonDate(name, values);
  1989. this.changeData(name, input, oldValue);
  1990. },
  1991. setSelectValue: function(name, select){
  1992. var idx = select.selectedIndex;
  1993. var options = select.getElements("option");
  1994. var value = "";
  1995. if (options[idx]){
  1996. value = options[idx].get("value");
  1997. }
  1998. var oldValue = this.data[name];
  1999. //this.data[name] = value;
  2000. this.changeJsonDate(name, value);
  2001. this.changeData(name, select, oldValue);
  2002. },
  2003. setValue: function(name, value, obj){
  2004. if (name==="id"){
  2005. if (value!==this.module.json.id) {
  2006. if (!value) {
  2007. this.designer.notice(MWF.APPFD.LP.notNullId, "error", this.module.form.designer.propertyContentArea, {
  2008. x: "right",
  2009. y: "bottom"
  2010. });
  2011. obj.focus();
  2012. return false;
  2013. } else {
  2014. var check = this.module.form.checkModuleId(value, this.module.json.type);
  2015. if (check.elementConflict) {
  2016. this.designer.notice(MWF.APPFD.LP.repetitionsId, "error", this.module.form.designer.propertyContentArea, {
  2017. x: "right",
  2018. y: "bottom"
  2019. });
  2020. obj.focus();
  2021. return false;
  2022. } else {
  2023. var json = this.module.form.json.moduleList[this.module.json.id];
  2024. this.module.form.json.moduleList[value] = json;
  2025. delete this.module.form.json.moduleList[this.module.json.id];
  2026. }
  2027. }
  2028. // if (this.module.form.json.moduleList[value]){
  2029. // this.designer.notice(MWF.APPFD.LP.repetitionsId, "error", this.module.form.designer.propertyContentArea, {x:"right", y:"bottom"});
  2030. // obj.focus();
  2031. // return false;
  2032. // }else{
  2033. // var flag = false;
  2034. // if (this.module.form.subformList){
  2035. // Object.each(this.module.form.subformList, function(o, k){
  2036. // if (o.subformData.moduleList[value] && o.subformData.moduleList[value] ) flag = true;
  2037. // });
  2038. // }
  2039. // if (flag){
  2040. // this.designer.notice(MWF.APPFD.LP.repetitionsId, "error", this.module.form.designer.propertyContentArea, {x:"right", y:"bottom"});
  2041. // obj.focus();
  2042. // return false;
  2043. // }else{
  2044. // var json = this.module.form.json.moduleList[this.module.json.id];
  2045. // this.module.form.json.moduleList[value]=json;
  2046. // delete this.module.form.json.moduleList[this.module.json.id];
  2047. // }
  2048. // }
  2049. }
  2050. }
  2051. //var oldValue = this.data[name];
  2052. var names = name.split(".");
  2053. var oldValue = this.data;
  2054. for (var idx = 0; idx<names.length; idx++){
  2055. if (!oldValue[names[idx]]){
  2056. oldValue = null;
  2057. break;
  2058. }else{
  2059. oldValue = oldValue[names[idx]];
  2060. }
  2061. }
  2062. //this.data[name] = value;
  2063. this.changeJsonDate(names, value);
  2064. this.changeData(name, obj, oldValue);
  2065. },
  2066. setEditNodeStyles: function(node){
  2067. var nodes = node.getChildren();
  2068. if (nodes.length){
  2069. nodes.each(function(el){
  2070. var cName = el.get("class");
  2071. if (cName){
  2072. if (this.form.css[cName]) el.setStyles(this.form.css[cName]);
  2073. }
  2074. this.setEditNodeStyles(el);
  2075. }.bind(this));
  2076. }
  2077. },
  2078. loadScriptInput: function(){
  2079. var scriptNodes = this.propertyContent.getElements(".MWFScript");
  2080. scriptNodes.each(function(node){
  2081. MWF.require("MWF.widget.ScriptEditor", function(){
  2082. var script = new MWF.widget.ScriptEditor(node, {
  2083. "onPostSave": function(script){
  2084. this.saveScriptItem(node, script);
  2085. }.bind(this),
  2086. "onQueryDelete": function(script){
  2087. this.deleteScriptItem(node, script);
  2088. }.bind(this)
  2089. });
  2090. this.setScriptItems(script, node);
  2091. }.bind(this));
  2092. }.bind(this));
  2093. },
  2094. deleteScriptItem: function(node, script){
  2095. var jsondata = node.get("name");
  2096. this.data[jsondata].erase(script.data.id);
  2097. this.process.scripts[script.data.id] = null;
  2098. delete this.process.scripts[script.data.id];
  2099. this.process.process.scriptList.erase(script.data);
  2100. },
  2101. saveScriptItem: function(node, script){
  2102. var jsondata = node.get("name");
  2103. var scriptList = this.data[jsondata];
  2104. var data = script.data;
  2105. var scriptData = this.process.scripts[script.data.id];
  2106. if (!scriptData){
  2107. this.process.process.scriptList.push(data);
  2108. this.process.scripts[script.data.id] = data;
  2109. }
  2110. if (scriptList.indexOf(data.id) == -1){
  2111. this.data[jsondata].push(data.id);
  2112. }
  2113. },
  2114. setScriptItems: function(script, node){
  2115. var jsondata = node.get("name");
  2116. var scriptList = this.data[jsondata];
  2117. scriptList.each(function(id){
  2118. if (id){
  2119. var data = this.process.scripts[id];
  2120. if (data) script.setScriptItem(data);
  2121. }
  2122. }.bind(this));
  2123. }
  2124. });
  2125. MWF.xApplication.process.FormDesigner.PropertyMulti = new Class({
  2126. Extends: MWF.xApplication.process.FormDesigner.Property,
  2127. Implements: [Options, Events],
  2128. initialize: function(form, modules, propertyNode, designer, options){
  2129. this.setOptions(options);
  2130. this.modules = modules;
  2131. this.form = form;
  2132. // this.data = module.json;
  2133. this.data = {};
  2134. this.htmlPath = this.options.path;
  2135. this.designer = designer;
  2136. this.maplists = {};
  2137. this.propertyNode = propertyNode;
  2138. },
  2139. load: function(){
  2140. if (this.fireEvent("queryLoad")){
  2141. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  2142. this.htmlString = responseText;
  2143. MWF.require("MWF.widget.JsonTemplate", function(){
  2144. this.fireEvent("postLoad");
  2145. }.bind(this));
  2146. }.bind(this));
  2147. }
  2148. },
  2149. show: function(){
  2150. if (!this.propertyContent){
  2151. if (this.htmlString){
  2152. this.JsonTemplate = new MWF.widget.JsonTemplate({}, this.htmlString);
  2153. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyNode);
  2154. this.propertyContent.set("html", this.JsonTemplate.load());
  2155. this.setEditNodeEvent();
  2156. this.setEditNodeStyles(this.propertyContent);
  2157. this.loadPropertyTab();
  2158. this.loadMaplist();
  2159. this.loadScriptArea();
  2160. this.loadTreeData();
  2161. this.loadArrayList();
  2162. //this.loadEventsEditor();
  2163. //this.loadHTMLArea();
  2164. //this.loadJSONArea();
  2165. // this.loadScriptInput();
  2166. //MWF.process.widget.EventsEditor
  2167. }
  2168. }else{
  2169. this.propertyContent.setStyle("display", "block");
  2170. }
  2171. },
  2172. hide: function(){
  2173. if (this.propertyContent) this.propertyContent.destroy();
  2174. },
  2175. changeStyle: function(name){
  2176. this.modules.each(function(module){
  2177. module.setPropertiesOrStyles(name);
  2178. }.bind(this));
  2179. },
  2180. changeData: function(name, input, oldValue){
  2181. this.modules.each(function(module){
  2182. module._setEditStyle(name, input, oldValue);
  2183. }.bind(this));
  2184. },
  2185. changeJsonDate: function(key, value){
  2186. //alert(key+": "+value );
  2187. this.modules.each(function(module){
  2188. module.json[key] = value;
  2189. }.bind(this));
  2190. },
  2191. });