Main.js 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105
  1. MWF.xApplication.process = MWF.xApplication.process || {};
  2. MWF.APPFD = MWF.xApplication.process.FormDesigner = MWF.xApplication.process.FormDesigner || {};
  3. MWF.xApplication.cms.FormDesigner = MWF.xApplication.cms.FormDesigner || {};
  4. MWF.CMSFD = MWF.xApplication.cms.FormDesigner;
  5. MWF.CMSFD.options = {
  6. "multitask": true,
  7. "executable": false
  8. };
  9. //MWF.xDesktop.requireApp("cms.ColumnManager", "Actions.RestActions", null, false);
  10. MWF.xDesktop.requireApp("cms.FormDesigner", "Module.Package", null, false);
  11. MWF.xApplication.cms.FormDesigner.Main = new Class({
  12. Extends: MWF.xApplication.Common.Main,
  13. Implements: [Options, Events],
  14. options: {
  15. "style": "default",
  16. "template": "form.json",
  17. "templateId": "",
  18. "name": "cms.FormDesigner",
  19. "icon": "icon.png",
  20. "title": MWF.CMSFD.LP.title,
  21. "appTitle": MWF.CMSFD.LP.title,
  22. "id": "",
  23. "actions": null,
  24. "category": null,
  25. "processData": null,
  26. "mvcStyle": "style.css"
  27. },
  28. onQueryLoad: function(){
  29. this._loadCss();
  30. this.shortcut = true;
  31. if (this.status){
  32. this.options.id = this.status.id;
  33. }
  34. if (!this.options.id){
  35. this.options.desktopReload = false;
  36. this.options.title = this.options.title + "-"+MWF.CMSFD.LP.newForm;
  37. }
  38. this.actions = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.ColumnManager.Actions.RestActions();
  39. this.lp = MWF.xApplication.cms.FormDesigner.LP;
  40. if( this.options.application ){
  41. if( !this.application )this.application = this.options.application;
  42. if( !this.column )this.column = this.options.application;
  43. }
  44. // this.processData = this.options.processData;
  45. },
  46. loadApplication: function(callback){
  47. this.createNode();
  48. if (!this.options.isRefresh){
  49. this.maxSize(function(){
  50. this.openForm();
  51. }.bind(this));
  52. }else{
  53. this.openForm();
  54. }
  55. this.addKeyboardEvents();
  56. if (callback) callback();
  57. },
  58. addKeyboardEvents: function(){
  59. this.addEvent("copy", function(){
  60. this.copyModule();
  61. }.bind(this));
  62. this.addEvent("paste", function(e){
  63. if( e.target && e.target.tagName && e.target.tagName.toLowerCase() === "textarea" )return;
  64. this.pasteModule();
  65. e.preventDefault();
  66. }.bind(this));
  67. this.addEvent("cut", function(){
  68. this.cutModule();
  69. }.bind(this));
  70. this.addEvent("keySave", function(e){
  71. this.keySave(e);
  72. }.bind(this));
  73. this.addEvent("keyDelete", function(e){
  74. this.keyDelete(e);
  75. }.bind(this));
  76. },
  77. keySave: function(e){
  78. if (this.shortcut) {
  79. if (this.form) this.saveForm();
  80. e.preventDefault();
  81. }
  82. },
  83. keyDelete: function(e){
  84. if (this.form){
  85. if (this.shortcut){
  86. if (this.form.currentSelectedModule){
  87. var module = this.form.currentSelectedModule;
  88. if (module.moduleType!="form" && module.moduleName.indexOf("$")==-1){
  89. module["delete"](module.node);
  90. }
  91. }
  92. }
  93. }
  94. },
  95. copyModule: function(){
  96. if (this.shortcut) {
  97. if (this.form) {
  98. if (this.form.currentSelectedModule) {
  99. var module = this.form.currentSelectedModule;
  100. if (module.moduleType != "form" && module.moduleName.indexOf("$") == -1) {
  101. this.form.fireEvent("queryGetFormData", [module.node]);
  102. var html = module.getHtml();
  103. var json = module.getJson();
  104. this.form.fireEvent("postGetFormData", [module.node]);
  105. MWF.clipboard.data = {
  106. "type": "form",
  107. "data": {
  108. "html": html,
  109. "json": json
  110. }
  111. };
  112. } else {
  113. MWF.clipboard.data = null;
  114. }
  115. }
  116. // }
  117. }
  118. }
  119. },
  120. cutModule: function(){
  121. if (this.shortcut) {
  122. if (this.form) {
  123. // if (this.form.isFocus){
  124. if (this.form.currentSelectedModule) {
  125. var module = this.form.currentSelectedModule;
  126. if (module.moduleType != "form" && module.moduleName.indexOf("$") == -1) {
  127. this.copyModule();
  128. var _form = module.form;
  129. if( _form.history ){
  130. module.addHistoryLog("cut");
  131. }
  132. module.destroy();
  133. _form.currentSelectedModule = null;
  134. _form.selected();
  135. _form = null;
  136. }
  137. }
  138. // }
  139. }
  140. }
  141. },
  142. pasteModule: function(){
  143. if (this.shortcut) {
  144. if (this.form) {
  145. if (MWF.clipboard.data) {
  146. if (MWF.clipboard.data.type == "form") {
  147. var datatemplateJsons = [];
  148. var idMap = {};
  149. var html = MWF.clipboard.data.data.html;
  150. var json = Object.clone(MWF.clipboard.data.data.json);
  151. var tmpNode = Element("div", {
  152. "styles": {"display": "none"},
  153. "html": html
  154. }).inject(this.content);
  155. var originalIds = {};
  156. Object.each(json, function (moduleJson){
  157. originalIds[moduleJson.id] = true;
  158. });
  159. Object.each(json, function (moduleJson) {
  160. var oid = moduleJson.id;
  161. var id = moduleJson.id;
  162. var idx = 1;
  163. while (this.form.json.moduleList[id] || ( originalIds[id] && idx > 1 )) {
  164. id = oid + "_" + idx;
  165. idx++;
  166. }
  167. if (oid != id) {
  168. idMap[oid] = id;
  169. moduleJson.id = id;
  170. var moduleNode = tmpNode.getElementById(oid);
  171. if (moduleNode) moduleNode.set("id", id);
  172. }
  173. if( moduleJson.type === "Datatemplate" )datatemplateJsons.push(moduleJson);
  174. this.form.json.moduleList[moduleJson.id] = moduleJson;
  175. }.bind(this));
  176. json = null;
  177. datatemplateJsons.each(function (json) {
  178. this.checkDatatemplateRelativeId(json, idMap);
  179. }.bind(this));
  180. var injectNode = this.form.node;
  181. var where = "bottom";
  182. var parent = this.form;
  183. if (this.form.currentSelectedModule) {
  184. var toModule = this.form.currentSelectedModule;
  185. injectNode = toModule.node;
  186. parent = toModule;
  187. if (toModule.moduleType != "container" && toModule.moduleType != "form") {
  188. where = "after";
  189. parent = toModule.parentContainer;
  190. }
  191. }
  192. var moduleList = [];
  193. var copyModuleNode = tmpNode.getFirst();
  194. while (copyModuleNode) {
  195. copyModuleNode.inject(injectNode, where);
  196. var copyModuleJson = this.form.getDomjson(copyModuleNode);
  197. var module = this.form.loadModule(copyModuleJson, copyModuleNode, parent);
  198. module._setEditStyle_custom("id");
  199. module.selected();
  200. moduleList.push( module );
  201. copyModuleNode = tmpNode.getFirst();
  202. }
  203. tmpNode.destroy();
  204. tmpNode = null;
  205. if( this.form.history && moduleList.length){
  206. moduleList[0].addHistoryLog("paste", moduleList);
  207. }
  208. }
  209. }
  210. }
  211. }
  212. },
  213. createNode: function(){
  214. this.content.setStyle("overflow", "hidden");
  215. this.node = new Element("div", {
  216. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  217. }).inject(this.content);
  218. },
  219. openForm: function(){
  220. this.initOptions();
  221. this.loadNodes();
  222. this.loadToolbar();
  223. this.loadFormNode();
  224. this.loadProperty();
  225. this.loadTools(function(){
  226. this.resizeNode();
  227. this.addEvent("resize", this.resizeNode.bind(this));
  228. }.bind(this));
  229. this.loadForm();
  230. MWF.require("MWF.widget.ScrollBar", function(){
  231. new MWF.widget.ScrollBar(this.propertyDomScrollArea, {
  232. "style":"default", "where": "before", "distance": 30, "friction": 4, "indent": false, "axis": {"x": false, "y": true}
  233. });
  234. }.bind(this));
  235. MWF.require("MWF.widget.ScrollBar", function(){
  236. new MWF.widget.ScrollBar(this.historyScrollArea, {
  237. "style":"default", "where": "before", "distance": 30, "friction": 4, "indent": false, "axis": {"x": false, "y": true}
  238. });
  239. }.bind(this));
  240. // if (this.toolbarContentNode){
  241. // this.setScrollBar(this.toolbarContentNode, null, {
  242. // "V": {"x": 0, "y": 0},
  243. // "H": {"x": 0, "y": 0}
  244. // });
  245. // //this.setScrollBar(this.propertyDomScrollArea, "form_property", {
  246. // // "V": {"x": 0, "y": 0},
  247. // // "H": {"x": 0, "y": 0}
  248. // //});
  249. // MWF.require("MWF.widget.ScrollBar", function(){
  250. // new MWF.widget.ScrollBar(this.propertyDomScrollArea, {
  251. // "style":"default", "where": "before", "distance": 30, "friction": 4, "indent": false, "axis": {"x": false, "y": true}
  252. // });
  253. // }.bind(this));
  254. // }
  255. },
  256. initOptions: function(){
  257. this.toolsData = null;
  258. this.toolbarMode = "all";
  259. this.tools = [];
  260. this.toolGroups = [];
  261. this.toolbarDecrease = 0;
  262. this.designNode = null;
  263. this.form = null;
  264. },
  265. loadNodes: function(){
  266. this.toolbarNode = new Element("div", {
  267. "styles": this.css.toolbarNode,
  268. "events": {"selectstart": function(e){e.preventDefault();}}
  269. }).inject(this.node);
  270. this.propertyNode = new Element("div", {
  271. "styles": this.css.propertyNode
  272. }).inject(this.node);
  273. this.formNode = new Element("div", {
  274. "styles": this.css.formNode
  275. }).inject(this.node);
  276. if (this.options.style=="bottom") this.propertyNode.inject(this.formNode, "after");
  277. },
  278. //loadToolbar----------------------
  279. loadToolbar: function(){
  280. this.toolbarTitleNode = new Element("div", {
  281. "styles": this.css.toolbarTitleNode,
  282. "text": MWF.APPFD.LP.tools
  283. }).inject(this.toolbarNode);
  284. this.toolbarTitleActionNode = new Element("div", {
  285. "styles": this.css.toolbarTitleActionNode,
  286. "events": {
  287. "click": function(e){
  288. this.switchToolbarMode();
  289. }.bind(this)
  290. }
  291. }).inject(this.toolbarNode);
  292. this.toolbarTitleCategoryActionNode = new Element("div", {
  293. "styles": this.css.toolbarTitleCategoryActionNode
  294. }).inject(this.toolbarNode);
  295. this.categoryActionMenu = new o2.xDesktop.Menu(this.toolbarTitleCategoryActionNode, {
  296. "event": "click", "style": "flatUser", "offsetX": 0, "offsetY": 0, "container": this.node,
  297. "onQueryShow": this.showCategoryMenu.bind(this)
  298. });
  299. this.categoryActionMenu.load();
  300. this.toolbarGroupContentNode = new Element("div", {"styles": this.css.toolbarGroupContentNode}).inject(this.toolbarNode);
  301. this.toolbarGroupContentNode.addEvent("selectstart", function(e){
  302. e.preventDefault();
  303. e.stopPropagation();
  304. });
  305. },
  306. showCategoryMenu: function(){
  307. this.categoryActionMenu.items.each(function(item){
  308. if (this.currentToolGroup && this.currentToolGroup.data.text==item.options.text){
  309. item.setDisable(true);
  310. var imgDiv = item.item.getFirst();
  311. var img = imgDiv.getElement("img");
  312. if (!img) img = new Element("img", {"styles": item.menu.css.menuItemImg}).inject(imgDiv);
  313. img.set("src", this.path+this.options.style+"/check.png");
  314. }else{
  315. item.setDisable(false);
  316. var imgDiv = item.item.getFirst();
  317. var img = imgDiv.getElement("img");
  318. if (img) img.destroy();
  319. }
  320. }.bind(this));
  321. },
  322. switchToolbarMode: function(){
  323. if (this.toolbarMode=="all"){
  324. var size = this.toolbarNode.getSize();
  325. this.toolbarDecrease = (size.x.toFloat())-60;
  326. this.tools.each(function(node){
  327. node.getLast().setStyle("display", "none");
  328. });
  329. this.toolbarTitleNode.set("text", "");
  330. this.toolbarNode.setStyle("width", "60px");
  331. var formMargin = this.formNode.getStyle("margin-left").toFloat();
  332. formMargin = formMargin - this.toolbarDecrease;
  333. this.formNode.setStyle("margin-left", ""+formMargin+"px");
  334. this.toolbarTitleActionNode.setStyles(this.css.toolbarTitleActionNodeRight);
  335. this.toolbarGroupContentNode.getElements(".o2formModuleTools").hide();
  336. this.toolbarMode="simple";
  337. }else{
  338. sizeX = 60 + this.toolbarDecrease;
  339. var formMargin = this.formNode.getStyle("margin-left").toFloat();
  340. formMargin = formMargin + this.toolbarDecrease;
  341. this.toolbarNode.setStyle("width", ""+sizeX+"px");
  342. this.formNode.setStyle("margin-left", ""+formMargin+"px");
  343. this.tools.each(function(node){
  344. node.getLast().setStyle("display", "block");
  345. });
  346. this.toolbarTitleNode.set("text", MWF.APPFD.LP.tools);
  347. this.toolbarTitleActionNode.setStyles(this.css.toolbarTitleActionNode);
  348. this.toolbarGroupContentNode.getElements(".o2formModuleTools").show();
  349. this.toolbarMode="all";
  350. }
  351. },
  352. //loadFormNode------------------------------
  353. loadFormNode: function(){
  354. this.formToolbarNode = new Element("div", {
  355. "styles": this.css.formToolbarNode
  356. }).inject(this.formNode);
  357. this.loadFormToolbar();
  358. this.formContentNode = new Element("div", {
  359. "styles": this.css.formContentNode
  360. }).inject(this.formNode);
  361. this.loadFormContent(function(){
  362. if (this.designDcoument) this.designDcoument.body.setStyles(this.css.designBody);
  363. if (this.designNode) this.designNode.setStyles(this.css.designNode);
  364. }.bind(this));
  365. },
  366. loaddesignerActionNode: function(){
  367. this.pcDesignerActionNode = this.formToolbarNode.getElement("#MWFFormPCDesignerAction");
  368. this.mobileDesignerActionNode = this.formToolbarNode.getElement("#MWFFormMobileDesignerAction");
  369. this.currentDesignerMode = "PC";
  370. this.pcDesignerActionNode.setStyles(this.css.designerActionNode_current);
  371. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode);
  372. var iconNode = new Element("div", {"styles": this.css.designerActionPcIconNode}).inject(this.pcDesignerActionNode);
  373. iconNode = new Element("div", {"styles": this.css.designerActionMobileIconNode}).inject(this.mobileDesignerActionNode);
  374. var textNode = new Element("div", {"styles": this.css.designerActiontextNode, "text": "PC"}).inject(this.pcDesignerActionNode);
  375. textNode = new Element("div", {"styles": this.css.designerActiontextNode, "text": "Mobile"}).inject(this.mobileDesignerActionNode);
  376. this.pcDesignerActionNode.addEvent("click", function(){
  377. if (this.currentDesignerMode!="PC"){
  378. this.changeDesignerModeToPC();
  379. }
  380. }.bind(this));
  381. this.mobileDesignerActionNode.addEvent("click", function(){
  382. if (this.currentDesignerMode=="PC"){
  383. this.changeDesignerModeToMobile();
  384. }
  385. }.bind(this));
  386. },
  387. changeDesignerModeToPC: function(){
  388. this.pcDesignerActionNode.setStyles(this.css.designerActionNode_current);
  389. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode);
  390. this.designMobileNode.setStyle("display", "none");
  391. this.designNode.setStyle("display", "block");
  392. if (this.form.currentSelectedModule){
  393. if (this.form.currentSelectedModule==this){
  394. return true;
  395. }else{
  396. this.mobilePreSelectedModule = this.form.currentSelectedModule;
  397. this.form.currentSelectedModule.unSelected();
  398. }
  399. }
  400. if (this.form.propertyMultiTd){
  401. this.form.propertyMultiTd.hide();
  402. this.form.propertyMultiTd = null;
  403. }
  404. this.form.unSelectedMulti();
  405. if( this.mobileForm )this.mobileForm.hideDomTree();
  406. if (this.form.designTabPageScriptAreaNode) this.form.designTabPageScriptAreaNode.hide();
  407. this.form = this.pcForm;
  408. this.pcForm.showDomTree();
  409. ( this.pcPreSelectedModule || this.pcForm ).selected();
  410. if ((this.scriptPage && this.scriptPage.isShow) || this.scriptPanel){
  411. this.loadAllScript();
  412. }
  413. this.currentDesignerMode = "PC";
  414. this.historyArea.show();
  415. this.historyAreaMobile.hide();
  416. this.currentHistoryNode = this.historyArea;
  417. },
  418. changeDesignerModeToMobile: function(){
  419. this.pcDesignerActionNode.setStyles(this.css.designerActionNode);
  420. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode_current);
  421. this.designMobileNode.setStyle("display", "block");
  422. this.designNode.setStyle("display", "none");
  423. if (this.form.currentSelectedModule){
  424. if (this.form.currentSelectedModule==this){
  425. return true;
  426. }else{
  427. this.pcPreSelectedModule = this.form.currentSelectedModule;
  428. this.form.currentSelectedModule.unSelected();
  429. }
  430. }
  431. if (this.form.propertyMultiTd){
  432. this.form.propertyMultiTd.hide();
  433. this.form.propertyMultiTd = null;
  434. }
  435. this.form.unSelectedMulti();
  436. if( this.pcForm )this.pcForm.hideDomTree();
  437. if (!this.mobileForm){
  438. this.mobileForm = new MWF.CMSFCForm(this, this.designMobileNode, {"mode": "Mobile"});
  439. if (!Object.keys(this.formMobileData.json.moduleList).length){
  440. this.formMobileData = Object.clone(this.formData);
  441. }
  442. this.mobileForm.load(this.formMobileData);
  443. }else{
  444. this.mobileForm.showDomTree();
  445. ( this.mobilePreSelectedModule || this.mobileForm ).selected();
  446. }
  447. if (this.form.designTabPageScriptAreaNode) this.form.designTabPageScriptAreaNode.hide();
  448. this.form = this.mobileForm;
  449. if ((this.scriptPage && this.scriptPage.isShow) || this.scriptPanel){
  450. this.loadAllScript();
  451. }
  452. this.currentDesignerMode = "Mobile";
  453. this.historyArea.hide();
  454. this.historyAreaMobile.show();
  455. this.currentHistoryNode = this.historyAreaMobile;
  456. },
  457. loadFormToolbar: function(callback){
  458. this.getFormToolbarHTML(function(toolbarNode){
  459. var spans = toolbarNode.getElements("span");
  460. spans.each(function(item, idx){
  461. var img = item.get("MWFButtonImage");
  462. if (img){
  463. item.set("MWFButtonImage", this.path+""+this.options.style+"/formtoolbar/"+img);
  464. }
  465. }.bind(this));
  466. $(toolbarNode).inject(this.formToolbarNode);
  467. MWF.require("MWF.widget.Toolbar", function(){
  468. this.formToolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "ProcessCategory"}, this);
  469. this.formToolbar.load();
  470. this.loaddesignerActionNode();
  471. if (callback) callback();
  472. }.bind(this));
  473. }.bind(this));
  474. },
  475. getFormToolbarHTML: function(callback){
  476. var toolbarUrl = this.path+this.options.style+"/formToolbars.html";
  477. MWF.getRequestText(toolbarUrl, function(responseText, responseXML){
  478. var htmlString = responseText;
  479. htmlString = o2.bindJson(htmlString, {"lp": this.lp.formToolbar});
  480. var temp = new Element('div').set('html', htmlString);
  481. if (callback) callback( temp.childNodes[0] );
  482. }.bind(this));
  483. },
  484. loadFormContent: function(callback){
  485. //var iframe = new Element("iframe#iframeaa", {
  486. // "styles": {
  487. // "width": "100%",
  488. // "height": "100%"
  489. // },
  490. // //"src": "../x_component_process_FormDesigner/$Main/blank.html",
  491. // "border": "0"
  492. //}).inject(this.formContentNode);
  493. // window.setTimeout(function(){
  494. // iframe.contentDocument.designMode = "on";
  495. //
  496. //
  497. // var x = document.id("iframeaa");
  498. // this.designNode = document.id(iframe.contentDocument.body, false, iframe.contentDocument);
  499. // this.designNode.setStyle("margin", "0px");
  500. // this.designNode.setStyles(this.css.designNode);
  501. MWF.require("MWF.widget.Tab", null, false);
  502. this.designTabNode = new Element("div").inject(this.formContentNode);
  503. this.designTab = new MWF.widget.Tab(this.designTabNode, {"style": "design"});
  504. this.designTab.load();
  505. this.designTabPageAreaNode = Element("div");
  506. this.designNode = new Element("div", {
  507. "styles": this.css.designNode
  508. }).inject(this.designTabPageAreaNode);
  509. //this.designContentNode = new Element("div", {
  510. // "styles": {"overflow": "visible"}
  511. //}).inject(this.designNode);
  512. //MWF.require("MWF.widget.ScrollBar", function(){
  513. // new MWF.widget.ScrollBar(this.designNode, {"distance": 100});
  514. //}.bind(this));
  515. this.designMobileNode = new Element("div", {
  516. "styles": this.css.designMobileNode
  517. }).inject(this.designTabPageAreaNode);
  518. //MWF.require("MWF.widget.ScrollBar", function(){
  519. // new MWF.widget.ScrollBar(this.designMobileNode, {"distance": 50, "style": "xApp_mobileForm"});
  520. //}.bind(this));
  521. // }.bind(this), 2000);
  522. this.designTabScriptAreaNode = Element("div", {"styles": this.css.designTabScriptAreaNode});
  523. this.designPage = this.designTab.addTab(this.designTabPageAreaNode, this.lp.design);
  524. this.scriptPage = this.designTab.addTab(this.designTabScriptAreaNode, this.lp.script);
  525. this.setScriptPageEvent();
  526. this.designPage.showTabIm();
  527. this.scriptPage.addEvent("postShow", function(){
  528. this.checkLoadAllScript();
  529. this.fireEvent("resize");
  530. }.bind(this));
  531. this.designPage.addEvent("postShow", function(){
  532. this.fireEvent("resize");
  533. }.bind(this));
  534. },
  535. createScriptPanel: function(p, s){
  536. MWF.require("MWF.widget.Panel", function(){
  537. this.scriptPanel = new MWF.widget.Panel(this.designTabScriptAreaNode, {
  538. "title": this.lp.script,
  539. "minLeft": "500",
  540. "minTop": "1",
  541. "style": "page",
  542. "target": this.content,
  543. "limitMove": false,
  544. "isClose": false,
  545. "width": s.x,
  546. "height": s.y,
  547. "top": p.y,
  548. "left": p.x,
  549. "onPostLoad": function(){
  550. this.loadAllScript();
  551. this.fireEvent("resize");
  552. }.bind(this),
  553. "onResize": function(){
  554. this.fireEvent("resize");
  555. }.bind(this),
  556. "onDrag": function(el, e){
  557. if (el.getStyle("top").toInt()<0) el.setStyle("top", "0px");
  558. if (!this.scriptPage.tab.tabNodeContainer.isOutside(e)){
  559. this.scriptPage.tabNode.show();
  560. this.scriptPanel.container.setStyle("opacity", "0.5");
  561. }else{
  562. this.scriptPage.tabNode.hide();
  563. this.scriptPanel.container.setStyle("opacity", "1");
  564. }
  565. }.bind(this),
  566. "onCompleteMove": function(el, e){
  567. if (!this.scriptPage.tab.tabNodeContainer.isOutside(e)){
  568. this.scriptPage.tabNode.show();
  569. this.designTabScriptAreaNode.inject(this.designTab.contentNodeContainer.getLast());
  570. this.fireEvent("resize");
  571. this.scriptPage.showTabIm();
  572. this.scriptPanel.closePanel();
  573. this.scriptPanel = null;
  574. }
  575. }.bind(this)
  576. });
  577. this.scriptPanel.load();
  578. }.bind(this));
  579. },
  580. createScriptPageDragNode: function(e){
  581. var size = this.scriptPage.tab.contentNodeContainer.getSize();
  582. var position = this.scriptPage.tab.contentNodeContainer.getPosition(this.content);
  583. if (!this.scriptPageContentDrag){
  584. var dragNode = new Element("div", {"styles": this.css.scriptPageDragNode}).inject(this.content);
  585. this.scriptPageContentDrag = new Drag.Move(dragNode, {
  586. "droppables": [this.scriptPage.tab.tabNodeContainer],
  587. "onEnter": function(el, drop){
  588. this.scriptPage.tabNode.show();
  589. this.designTabScriptAreaNode.show();
  590. // this.scriptPageContentDrag.stop();
  591. // this.scriptPageContentDrag.detach();
  592. this.scriptPageContentDrag = null;
  593. dragNode.destroy();
  594. this.scriptPageDrag.start(e);
  595. }.bind(this),
  596. "onComplete": function(el, e){
  597. if (this.scriptPage.tab.tabNodeContainer.isOutside(e)){
  598. this.createScriptPanel(dragNode.getPosition(this.content), dragNode.getSize());
  599. this.designPage.showTabIm();
  600. }
  601. this.scriptPageContentDrag = null;
  602. if (dragNode) dragNode.destroy();
  603. this.designTabScriptAreaNode.show();
  604. }.bind(this)
  605. });
  606. }
  607. var tabPosition = this.scriptPage.tabNode.getPosition();
  608. var dx = e.page.x-tabPosition.x;
  609. var dy = e.page.y-tabPosition.y;
  610. this.scriptPage.tabNode.hide();
  611. this.designTabScriptAreaNode.hide();
  612. var w = size.x*0.7;
  613. var h = size.y*0.7;
  614. var x = position.x+dx;
  615. var y = position.y+dy-20;
  616. dragNode.setStyles({
  617. "width": ""+w+"px",
  618. "height": ""+h+"px",
  619. "top": ""+y+"px",
  620. "left": ""+x+"px"
  621. });
  622. this.scriptPageContentDrag.start(e);
  623. },
  624. setScriptPageEvent: function(){
  625. this.scriptPageDrag = new Drag(this.scriptPage.tabNode, {
  626. "snap": 20,
  627. "onStart": function(el,e){
  628. el.setStyle("position", "static");
  629. },
  630. "onDrag": function(el,e){
  631. if (this.scriptPage.tab.tabNodeContainer.isOutside(e)){
  632. this.scriptPageDrag.stop();
  633. el.setStyle("left", "auto");
  634. this.createScriptPageDragNode(e);
  635. }
  636. }.bind(this),
  637. "onComplete": function(el){
  638. el.setStyle("left", "auto");
  639. //el.setStyle("position", "relative");
  640. }.bind(this)
  641. });
  642. },
  643. checkLoadAllScript: function(){
  644. if (this.form){
  645. this.loadAllScript();
  646. }else{
  647. this.designPage.showTabIm();
  648. }
  649. },
  650. loadAllScript: function(){
  651. if (!this.form.designTabPageScriptAreaNode) this.form.designTabPageScriptAreaNode = Element("div", {"styles": this.css.designTabScriptPcAreaNode}).inject(this.designTabScriptAreaNode);
  652. this.form.designTabPageScriptAreaNode.show();
  653. if (!this.form.scriptDesigner){
  654. MWF.xDesktop.requireApp("cms.FormDesigner", "Script", function(){
  655. this.form.scriptDesigner = new MWF.xApplication.cms.FormDesigner.Script(this, this.form.designTabPageScriptAreaNode, this.form.json);
  656. // var moduleJson = this.pageData.json;
  657. // if (moduleJson.jsheader){
  658. // if (moduleJson.jsheader.code){
  659. //
  660. // }
  661. // }
  662. }.bind(this));
  663. }
  664. },
  665. reloadPropertyStyles: function(){
  666. //MWF.release(this.css);
  667. this.css = null;
  668. this.cssPath = "../x_component_"+this.options.name.replace(/\./g, "_")+"/$Main/"+this.options.style+"/css.wcss";
  669. this._loadCss();
  670. if (this.options.style=="bottom"){
  671. this.propertyNode.inject(this.formNode, "after");
  672. this.propertyTitleNode.setStyle("cursor", "row-resize");
  673. this.loadPropertyResizeBottom();
  674. }else{
  675. this.propertyNode.inject(this.formNode, "before");
  676. this.propertyTitleNode.setStyle("cursor", "default");
  677. if (this.propertyResizeBottom) this.propertyResizeBottom.detach();
  678. }
  679. this.formNode.clearStyles(false);
  680. this.formNode.setStyles(this.css.formNode);
  681. this.propertyNode.clearStyles(false);
  682. this.propertyNode.setStyles(this.css.propertyNode);
  683. this.propertyTitleNode.clearStyles(false);
  684. this.propertyTitleNode.setStyles(this.css.propertyTitleNode);
  685. this.propertyResizeBar.clearStyles(false);
  686. this.propertyResizeBar.setStyles(this.css.propertyResizeBar);
  687. this.propertyContentNode.clearStyles(false);
  688. this.propertyContentNode.setStyles(this.css.propertyContentNode);
  689. this.propertyDomContentArea.clearStyles(false);
  690. this.propertyDomContentArea.setStyles(this.css.propertyDomContentArea);
  691. this.propertyDomScrollArea.clearStyles(false);
  692. this.propertyDomScrollArea.setStyles(this.css.propertyDomScrollArea);
  693. this.propertyDomArea.clearStyles(false);
  694. this.propertyDomArea.setStyles(this.css.propertyDomArea);
  695. this.propertyContentArea.clearStyles(false);
  696. this.propertyContentArea.setStyles(this.css.propertyContentArea);
  697. this.propertyContentResizeNode.clearStyles(false);
  698. this.propertyContentResizeNode.setStyles(this.css.propertyContentResizeNode);
  699. this.propertyTitleActionNode.clearStyles(false);
  700. this.propertyTitleActionNode.setStyles(this.css.propertyTitleActionNode);
  701. this.resizeNode();
  702. },
  703. //loadProperty------------------------
  704. loadProperty: function(){
  705. this.propertyTitleActionNode = new Element("div", {
  706. "styles": this.css.propertyTitleActionNode
  707. }).inject(this.propertyNode);
  708. this.propertyTitleActionNode.addEvent("click", function(){
  709. this.options.style = (this.options.style=="default") ? "bottom" : "default";
  710. MWF.UD.putData("formDesignerStyle", {"style": this.options.style});
  711. this.reloadPropertyStyles();
  712. }.bind(this));
  713. this.propertyTitleNode = new Element("div", {
  714. "styles": this.css.propertyTitleNode,
  715. "text": MWF.APPFD.LP.property
  716. }).inject(this.propertyNode);
  717. if (this.options.style=="bottom"){
  718. this.propertyTitleNode.setStyle("cursor", "row-resize");
  719. this.loadPropertyResizeBottom();
  720. }
  721. this.propertyResizeBar = new Element("div", {
  722. "styles": this.css.propertyResizeBar
  723. }).inject(this.propertyNode);
  724. this.loadPropertyResize();
  725. this.propertyContentNode = new Element("div", {
  726. "styles": this.css.propertyContentNode
  727. }).inject(this.propertyNode);
  728. this.propertyDomContentArea = new Element("div", {
  729. "styles": this.css.propertyDomContentArea
  730. }).inject(this.propertyContentNode);
  731. this.propertyDomTabArea = new Element("div").inject(this.propertyDomContentArea);
  732. //this.propertyDomScrollArea = new Element("div", {
  733. // "styles": this.css.propertyDomScrollArea
  734. //}).inject(this.propertyDomContentArea);
  735. //this.propertyDomArea = new Element("div", {
  736. // "styles": this.css.propertyDomArea
  737. //}).inject(this.propertyDomScrollArea);
  738. this.loadPropertyTab();
  739. this.propertyDomPercent = 0.3;
  740. this.propertyContentResizeNode = new Element("div", {
  741. "styles": this.css.propertyContentResizeNode
  742. }).inject(this.propertyContentNode);
  743. this.propertyContentArea = new Element("div", {
  744. "styles": this.css.propertyContentArea
  745. }).inject(this.propertyContentNode);
  746. this.loadPropertyContentResize();
  747. },
  748. loadPropertyTab: function (callback) {
  749. var _self = this;
  750. MWF.require("MWF.widget.Tab", null, false);
  751. this.propertyDomTab = new MWF.widget.Tab(this.propertyDomTabArea, {"style": "formPropertyList"});
  752. this.propertyDomTab.load();
  753. this.tabDomNode = Element("div");
  754. this.propertyDomScrollArea = new Element("div", {
  755. "styles": this.css.propertyDomScrollArea
  756. }).inject(this.tabDomNode);
  757. this.propertyDomArea = new Element("div", {
  758. "styles": this.css.propertyDomArea
  759. }).inject(this.propertyDomScrollArea);
  760. this.tabHistoryNode = Element("div");
  761. this.historyScrollArea = new Element("div", {
  762. "styles": this.css.propertyDomScrollArea
  763. }).inject(this.tabHistoryNode);
  764. this.historyArea = new Element("div", {
  765. "styles": this.css.propertyDomArea
  766. }).inject(this.historyScrollArea);
  767. this.historyAreaMobile = new Element("div", {
  768. "styles": this.css.propertyDomArea
  769. }).inject(this.historyScrollArea);
  770. this.historyAreaMobile.hide();
  771. this.currentHistoryNode = this.historyArea;
  772. this.domPage = this.propertyDomTab.addTab(this.tabDomNode, this.lp.componentTree);
  773. this.historyPage = this.propertyDomTab.addTab(this.tabHistoryNode, this.lp.history);
  774. this.domPage.showTabIm();
  775. this.domPage.addEvent("postShow", function () {
  776. var module = this.form.currentSelectedModule;
  777. if (module && module.treeNode){
  778. (new Fx.Scroll(this.propertyDomScrollArea)).toElement(module.treeNode.node);
  779. }
  780. }.bind(this));
  781. // this.runPage.addEvent("postShow", function () {
  782. // this.selected();
  783. // }.bind(this));
  784. },
  785. loadPropertyResizeBottom: function(){
  786. if (!this.propertyResizeBottom){
  787. this.propertyResizeBottom = new Drag(this.propertyTitleNode,{
  788. "snap": 1,
  789. "onStart": function(el, e){
  790. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  791. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  792. el.store("position", {"x": x, "y": y});
  793. var size = this.propertyNode.getSize();
  794. el.store("initialWidth", size.x);
  795. el.store("initialHeight", size.y);
  796. }.bind(this),
  797. "onDrag": function(el, e){
  798. // var x = e.event.x;
  799. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  800. var bodySize = this.content.getSize();
  801. var position = el.retrieve("position");
  802. var initialHeight = el.retrieve("initialHeight").toFloat();
  803. var dy = position.y.toFloat()-y.toFloat();
  804. var height = initialHeight+dy;
  805. if (height> bodySize.y/1.5) height = bodySize.y/1.5;
  806. if (height<40) height = 40;
  807. var percent = 1-(height/bodySize.y);
  808. this.resizeNode(percent);
  809. //var formNodeHeight = bodySize.y-height;
  810. //this.formNode.setStyle("height", ""+formNodeHeight+"px");
  811. //this.propertyNode.setStyle("height", ""+height+"px");
  812. }.bind(this)
  813. });
  814. }else{
  815. this.propertyResizeBottom.attach();
  816. }
  817. },
  818. loadPropertyResize: function(){
  819. // var size = this.propertyNode.getSize();
  820. // var position = this.propertyResizeBar.getPosition();
  821. this.propertyResize = new Drag(this.propertyResizeBar,{
  822. "snap": 1,
  823. "onStart": function(el, e){
  824. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  825. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  826. el.store("position", {"x": x, "y": y});
  827. var size = this.propertyNode.getSize();
  828. el.store("initialWidth", size.x);
  829. }.bind(this),
  830. "onDrag": function(el, e){
  831. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  832. // var y = e.event.y;
  833. var bodySize = this.content.getSize();
  834. var position = el.retrieve("position");
  835. var initialWidth = el.retrieve("initialWidth").toFloat();
  836. var dx = position.x.toFloat()-x.toFloat();
  837. var width = initialWidth+dx;
  838. if (width> bodySize.x/2) width = bodySize.x/2;
  839. if (width<40) width = 40;
  840. this.formNode.setStyle("margin-right", width+1);
  841. this.propertyNode.setStyle("width", width);
  842. }.bind(this)
  843. });
  844. },
  845. propertyResizeDragTopBottom: function(el, e){
  846. var size = this.propertyContentNode.getSize();
  847. // var x = e.event.x;
  848. var y = e.event.y;
  849. var position = el.retrieve("position");
  850. var dy = y.toFloat()-position.y.toFloat();
  851. var initialHeight = el.retrieve("initialHeight").toFloat();
  852. var height = initialHeight+dy;
  853. if (height<40) height = 40;
  854. if (height> size.y-40) height = size.y-40;
  855. this.propertyDomPercent = height/size.y;
  856. this.setPropertyContentResize();
  857. },
  858. propertyResizeDragLeftRight: function(el, e){
  859. var size = this.propertyContentNode.getSize();
  860. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  861. //var y = e.event.y;
  862. var position = el.retrieve("position");
  863. var dx = x.toFloat()-position.x.toFloat();
  864. var initialWidth = el.retrieve("initialWidth").toFloat();
  865. var width = initialWidth+dx;
  866. if (width<40) width = 40;
  867. if (width> size.x-40) width = size.x-40;
  868. this.propertyDomPercent = width/size.x;
  869. this.setPropertyContentResizeBottom();
  870. },
  871. loadPropertyContentResize: function(){
  872. this.propertyContentResize = new Drag(this.propertyContentResizeNode, {
  873. "snap": 1,
  874. "onStart": function(el, e){
  875. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  876. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  877. el.store("position", {"x": x, "y": y});
  878. var size = this.propertyDomContentArea.getSize();
  879. el.store("initialHeight", size.y);
  880. el.store("initialWidth", size.x);
  881. }.bind(this),
  882. "onDrag": function(el, e){
  883. if (this.options.style=="bottom"){
  884. this.propertyResizeDragLeftRight(el, e);
  885. }else{
  886. this.propertyResizeDragTopBottom(el, e);
  887. }
  888. }.bind(this)
  889. });
  890. },
  891. setPropertyContentResizeBottom: function(){
  892. var size = this.propertyContentNode.getSize();
  893. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  894. var width = size.x-resizeNodeSize.x-6;
  895. var domWidth = this.propertyDomPercent*width;
  896. var contentMargin = domWidth+resizeNodeSize.x+6;
  897. this.propertyDomContentArea.setStyle("width", ""+domWidth+"px");
  898. this.propertyContentArea.setStyle("margin-left", ""+contentMargin+"px");
  899. },
  900. setPropertyContentResize: function(){
  901. var size = this.propertyContentNode.getSize();
  902. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  903. var height = size.y-resizeNodeSize.y;
  904. var domHeight = this.propertyDomPercent*height;
  905. var contentHeight = height-domHeight;
  906. this.propertyDomContentArea.setStyle("height", ""+domHeight+"px");
  907. this.propertyDomScrollArea.setStyle("height", ""+(domHeight-28)+"px");
  908. this.historyScrollArea.setStyle("height", ""+(domHeight-28)+"px");
  909. this.propertyContentArea.setStyle("height", ""+contentHeight+"px");
  910. if (this.form){
  911. if (this.form.currentSelectedModule){
  912. if (this.form.currentSelectedModule.property){
  913. var tab = this.form.currentSelectedModule.property.propertyTab;
  914. if (tab){
  915. var tabTitleSize = tab.tabNodeContainer.getSize();
  916. tab.pages.each(function(page){
  917. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  918. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  919. var tabContentNodeAreaHeight = contentHeight - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  920. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  921. }.bind(this));
  922. }
  923. }
  924. }
  925. }
  926. },
  927. //loadTools------------------------------
  928. loadTools: function(callback){
  929. o2.loadCss("../o2_lib/vue/element/index.css");
  930. this.getToolResource(function(){
  931. this.toolsGroupData.forEach(function(o){
  932. //var o = this.toolsGroupData[key];
  933. this.toolGroups.push(new MWF.xApplication.cms.FormDesigner.ToolsGroup(o, this, o.name === this.currentUserDefaultTool));
  934. }, this);
  935. if (callback) callback();
  936. }.bind(this));
  937. },
  938. getToolResource: function(callback){
  939. var check = function () {
  940. var list = this.toolsGroupData.filter(function(o){
  941. return o.name === this.currentUserDefaultTool
  942. }.bind(this));
  943. if( list.length < 1 )this.currentUserDefaultTool = "default";
  944. callback();
  945. }.bind(this);
  946. this.getGroups(function(){
  947. if(this.toolsGroupData && this.currentUserDefaultTool )check();
  948. }.bind(this));
  949. this.getDefaultTool(function(){
  950. if(this.toolsGroupData && this.currentUserDefaultTool )check();
  951. }.bind(this));
  952. },
  953. getGroups: function(callback){
  954. if (this.toolsGroupData){
  955. if (callback) callback();
  956. }else{
  957. var toolsGroupDataUrl = this.path+this.options.style+"/toolsGroup.json";
  958. o2.JSON.get(toolsGroupDataUrl, function(responseJSON){
  959. this.toolsGroupData = responseJSON;
  960. if (callback) callback();
  961. }.bind(this));
  962. }
  963. },
  964. getDefaultTool: function(callback){
  965. if( typeOf(this.currentUserDefaultTool) === "string" ){
  966. if (callback) callback();
  967. }else{
  968. o2.UD.getDataJson("cmsTools", function (json) {
  969. this.currentUserDefaultTool = (json && json.defaultTool) || "default";
  970. if (callback) callback();
  971. }.bind(this));
  972. }
  973. },
  974. setDefaultTool: function(defaultTools, callback){
  975. o2.UD.getDataJson("cmsTools", function (json) {
  976. if(!json)json = {};
  977. json.defaultTool = defaultTools;
  978. o2.UD.putData("cmsTools", json, function () {
  979. if (callback) callback();
  980. }.bind(this));
  981. }.bind(this));
  982. },
  983. //resizeNode------------------------------------------------
  984. resizeNodeLeftRight: function(){
  985. var nodeSize = this.node.getSize();
  986. this.toolbarNode.setStyle("height", ""+nodeSize.y+"px");
  987. this.formNode.setStyle("height", ""+nodeSize.y+"px");
  988. this.propertyNode.setStyle("height", ""+nodeSize.y+"px");
  989. //nodeSize = {"x": nodeSize.x, "y": nodeSize.y*0.6};
  990. var formToolbarMarginTop = this.formToolbarNode.getStyle("margin-top").toFloat();
  991. var formToolbarMarginBottom = this.formToolbarNode.getStyle("margin-bottom").toFloat();
  992. var allFormToolberSize = this.formToolbarNode.getComputedSize();
  993. var y = nodeSize.y - allFormToolberSize.totalHeight - formToolbarMarginTop - formToolbarMarginBottom;
  994. this.formContentNode.setStyle("height", ""+y+"px");
  995. var tabSize = this.designTab.tabNodeContainer.getComputedSize();
  996. var tabMarginTop = this.designTab.tabNodeContainer.getStyle("margin-top").toFloat();
  997. var tabMarginBottom = this.designTab.tabNodeContainer.getStyle("margin-bottom").toFloat();
  998. y = y-tabSize.totalHeight-tabMarginTop-tabMarginBottom;
  999. this.designTab.contentNodeContainer.setStyle("height", ""+y+"px");
  1000. if (this.designNode){
  1001. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  1002. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  1003. //y = nodeSize.y - allFormToolberSize.totalHeight - formToolbarMarginTop - formToolbarMarginBottom - designMarginTop - designMarginBottom;
  1004. y = y - designMarginTop - designMarginBottom;
  1005. this.designNode.setStyle("height", ""+y+"px");
  1006. }
  1007. var titleSize = this.toolbarTitleNode.getSize();
  1008. var titleMarginTop = this.toolbarTitleNode.getStyle("margin-top").toFloat();
  1009. var titleMarginBottom = this.toolbarTitleNode.getStyle("margin-bottom").toFloat();
  1010. var titlePaddingTop = this.toolbarTitleNode.getStyle("padding-top").toFloat();
  1011. var titlePaddingBottom = this.toolbarTitleNode.getStyle("padding-bottom").toFloat();
  1012. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  1013. y = nodeSize.y-y;
  1014. //this.toolbarContentNode.setStyle("height", ""+y+"px");
  1015. this.toolbarGroupContentNode.setStyle("height", ""+y+"px");
  1016. var groupHeight = 0;
  1017. // this.toolGroups.each(function(g){
  1018. // groupHeight += g.toolbarGroupTitleNode.getSize().y;
  1019. // });
  1020. var contentHeight = y-groupHeight-5;
  1021. this.toolGroups.each(function(g){
  1022. g.setContentHeight(contentHeight);
  1023. //g.toolbarContentNode.setStyle("height", ""+contentHeight+"px");
  1024. });
  1025. titleSize = this.propertyTitleNode.getSize();
  1026. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  1027. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  1028. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  1029. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  1030. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  1031. y = nodeSize.y-y;
  1032. this.propertyContentNode.setStyle("height", ""+y+"px");
  1033. this.propertyResizeBar.setStyle("height", ""+y+"px");
  1034. },
  1035. resizeNodeTopBottom: function(percent){
  1036. var nodeSize = this.node.getSize();
  1037. this.toolbarNode.setStyle("height", ""+nodeSize.y+"px");
  1038. var percentNumber = percent || 0.6;
  1039. var designerHeight = nodeSize.y*percentNumber;
  1040. var propertyHeight = nodeSize.y - designerHeight;
  1041. this.formNode.setStyle("height", ""+designerHeight+"px");
  1042. this.propertyNode.setStyle("height", ""+propertyHeight+"px");
  1043. var formToolbarMarginTop = this.formToolbarNode.getStyle("margin-top").toFloat();
  1044. var formToolbarMarginBottom = this.formToolbarNode.getStyle("margin-bottom").toFloat();
  1045. var allFormToolberSize = this.formToolbarNode.getComputedSize();
  1046. var y = designerHeight - allFormToolberSize.totalHeight - formToolbarMarginTop - formToolbarMarginBottom;
  1047. // this.formContentNode.setStyle("height", ""+designerHeight+"px");
  1048. var tabSize = this.designTab.tabNodeContainer.getComputedSize();
  1049. var tabMarginTop = this.designTab.tabNodeContainer.getStyle("margin-top").toFloat();
  1050. var tabMarginBottom = this.designTab.tabNodeContainer.getStyle("margin-bottom").toFloat();
  1051. y = y-tabSize.totalHeight-tabMarginTop-tabMarginBottom;
  1052. this.designTab.contentNodeContainer.setStyle("height", ""+y+"px");
  1053. if (this.designNode){
  1054. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  1055. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  1056. //y = designerHeight - allFormToolberSize.totalHeight - formToolbarMarginTop - formToolbarMarginBottom - designMarginTop - designMarginBottom;
  1057. y = y - designMarginTop - designMarginBottom;
  1058. this.designNode.setStyle("height", ""+y+"px");
  1059. }
  1060. var titleSize = this.toolbarTitleNode.getSize();
  1061. var titleMarginTop = this.toolbarTitleNode.getStyle("margin-top").toFloat();
  1062. var titleMarginBottom = this.toolbarTitleNode.getStyle("margin-bottom").toFloat();
  1063. var titlePaddingTop = this.toolbarTitleNode.getStyle("padding-top").toFloat();
  1064. var titlePaddingBottom = this.toolbarTitleNode.getStyle("padding-bottom").toFloat();
  1065. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  1066. y = nodeSize.y-y;
  1067. //this.toolbarContentNode.setStyle("height", ""+y+"px");
  1068. this.toolbarGroupContentNode.setStyle("height", ""+y+"px");
  1069. var groupHeight = 0;
  1070. // this.toolGroups.each(function(g){
  1071. // groupHeight += g.toolbarGroupTitleNode.getSize().y;
  1072. // });
  1073. var contentHeight = y-groupHeight-5;
  1074. this.toolGroups.each(function(g){
  1075. g.setContentHeight(contentHeight);
  1076. });
  1077. titleSize = this.propertyTitleNode.getSize();
  1078. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  1079. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  1080. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  1081. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  1082. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  1083. y = propertyHeight-y;
  1084. this.propertyContentNode.setStyle("height", ""+y+"px");
  1085. this.propertyResizeBar.setStyle("height", ""+y+"px");
  1086. this.propertyDomContentArea.setStyle("height", ""+y+"px");
  1087. this.propertyDomScrollArea.setStyle("height", ""+(y-28)+"px");
  1088. this.historyScrollArea.setStyle("height", ""+(y-28)+"px");
  1089. this.propertyContentResizeNode.setStyle("height", ""+y+"px");
  1090. this.propertyContentArea.setStyle("height", ""+y+"px");
  1091. if (this.form){
  1092. if (this.form.currentSelectedModule){
  1093. if (this.form.currentSelectedModule.property){
  1094. var tab = this.form.currentSelectedModule.property.propertyTab;
  1095. if (tab){
  1096. var tabTitleSize = tab.tabNodeContainer.getSize();
  1097. tab.pages.each(function(page){
  1098. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1099. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1100. var tabContentNodeAreaHeight = y - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  1101. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1102. }.bind(this));
  1103. }
  1104. }
  1105. }
  1106. }
  1107. },
  1108. resizeNode: function(percent){
  1109. if (this.options.style=="bottom"){
  1110. this.resizeNodeTopBottom(percent);
  1111. this.setPropertyContentResizeBottom();
  1112. }else{
  1113. this.resizeNodeLeftRight(percent);
  1114. this.setPropertyContentResize();
  1115. }
  1116. },
  1117. //loadForm------------------------------------------
  1118. loadForm: function(){
  1119. // try{
  1120. this.getFormData(function(){
  1121. this.pcForm = new MWF.CMSFCForm(this, this.designNode);
  1122. this.pcForm.load(this.formData);
  1123. this.form = this.pcForm;
  1124. }.bind(this));
  1125. // }catch(e){
  1126. // layout.notice("error", {x: "right", y:"top"}, e.message, this.designNode);
  1127. // }
  1128. // MWF.getJSON(COMMON.contentPath+"/res/js/testform.json", {
  1129. // "onSuccess": function(obj){
  1130. // this.form = new MWF.FCForm(this);
  1131. // this.form.load(obj);
  1132. // }.bind(this),
  1133. // "onerror": function(text){
  1134. // layout.notice("error", {x: "right", y:"top"}, text, this.designNode);
  1135. // }.bind(this),
  1136. // "onRequestFailure": function(xhr){
  1137. // layout.notice("error", {x: "right", y:"top"}, xhr.responseText, this.designNode);
  1138. // }
  1139. // });
  1140. },
  1141. getFormData: function(callback){
  1142. if (!this.options.id){
  1143. if (this.options.templateId){
  1144. this.loadNewFormDataFormTemplate(callback);
  1145. }else{
  1146. this.loadNewFormData(callback);
  1147. }
  1148. }else{
  1149. this.loadFormData(callback);
  1150. }
  1151. },
  1152. loadNewFormData: function(callback){
  1153. var url = "../x_component_cms_FormDesigner/Module/Form/template/"+this.options.template;
  1154. //MWF.getJSON("../x_component_process_FormDesigner/Module/Form/template.json", {
  1155. MWF.getJSON(url, {
  1156. "onSuccess": function(obj){
  1157. this.formData = obj.pcData;
  1158. this.formData.id="";
  1159. this.formData.isNewForm = true;
  1160. this.formMobileData = obj.mobileData;
  1161. this.formMobileData.id="";
  1162. this.formMobileData.isNewForm = true;
  1163. if (callback) callback();
  1164. }.bind(this),
  1165. "onerror": function(text){
  1166. this.notice(text, "error");
  1167. }.bind(this),
  1168. "onRequestFailure": function(xhr){
  1169. this.notice(xhr.responseText, "error");
  1170. }.bind(this)
  1171. });
  1172. },
  1173. loadNewFormDataFormTemplate: function(callback){
  1174. this.actions.getFormTemplate(this.options.templateId, function(form){
  1175. if (form){
  1176. this.formData = JSON.decode(MWF.decodeJsonString(form.data.data));
  1177. this.formData.isNewForm = true;
  1178. this.formData.json.id = "";
  1179. if (form.data.mobileData){
  1180. this.formMobileData = JSON.decode(MWF.decodeJsonString(form.data.mobileData));
  1181. this.formMobileData.isNewForm = true;
  1182. this.formMobileData.json.id = "";
  1183. }else{
  1184. this.formMobileData = Object.clone(this.formData);
  1185. }
  1186. if (callback) callback();
  1187. //this.actions.getFormCategory(this.formData.json.formCategory, function(category){
  1188. // this.category = {"data": {"name": category.data.name, "id": category.data.id}};
  1189. // if (callback) callback();
  1190. //}.bind(this));
  1191. }
  1192. }.bind(this));
  1193. },
  1194. loadFormData: function(callback){
  1195. this.actions.getForm(this.options.id, function(form){
  1196. if (form){
  1197. var formTemplete = null;
  1198. MWF.getJSON("../x_component_cms_FormDesigner/Module/Form/template/form.json", {
  1199. "onSuccess": function(obj){ formTemplete = obj; }.bind(this)
  1200. }, false);
  1201. this.formData = JSON.decode(MWF.decodeJsonString(form.data.data));
  1202. if (formTemplete.pcData){
  1203. Object.merge(formTemplete.pcData, this.formData);
  1204. Object.merge(this.formData, formTemplete.pcData);
  1205. }
  1206. this.formData.isNewForm = false;
  1207. this.formData.json.id = form.data.id;
  1208. if (form.data.mobileData){
  1209. this.formMobileData = JSON.decode(MWF.decodeJsonString(form.data.mobileData));
  1210. if (formTemplete.mobileData){
  1211. Object.merge(formTemplete.mobileData, this.formMobileData);
  1212. Object.merge(this.formMobileData, formTemplete.mobileData);
  1213. }
  1214. this.formMobileData.isNewForm = false;
  1215. this.formMobileData.json.id = form.data.id;
  1216. }else{
  1217. this.formMobileData = Object.clone(this.formData);
  1218. }
  1219. this.setTitle(this.options.appTitle + "-"+this.formData.json.name);
  1220. if(this.taskitem)this.taskitem.setText(this.options.appTitle + "-"+this.formData.json.name);
  1221. this.options.appTitle = this.options.appTitle + "-"+this.formData.json.name;
  1222. if (!this.application){
  1223. this.actions.getColumn(form.data.appId, function(json){
  1224. this.application = {"name": json.data.appName, "id": json.data.id};
  1225. if (callback) callback();
  1226. }.bind(this));
  1227. }else{
  1228. if (callback) callback();
  1229. }
  1230. //this.actions.getFormCategory(this.formData.json.formCategory, function(category){
  1231. // this.category = {"data": {"name": category.data.name, "id": category.data.id}};
  1232. // if (callback) callback();
  1233. //}.bind(this));
  1234. }
  1235. }.bind(this));
  1236. },
  1237. getFieldList: function(){
  1238. //fieldTypes = ["calender", "checkbox", "datagrid", "htmledit", "number", "personfield", "radio", "select", "textarea", "textfield"];
  1239. dataTypes = {
  1240. "string": ["htmledit", "radio", "select", "textarea", "textfield","imageclipper","htmleditor","tinymceeditor","ooinput","ootextarea","ooselect","ooradioGroup"],
  1241. "person": ["personfield","orgfield","org","ooorg"],
  1242. "date": ["calender","oodatetime"],
  1243. "number": ["number","currency"],
  1244. "array": ["checkbox"]
  1245. };
  1246. fieldList = [];
  1247. this.pcForm.moduleList.each(function(moudle){
  1248. var key = "";
  1249. for (k in dataTypes){
  1250. if (dataTypes[k].indexOf(moudle.moduleName.toLowerCase())!=-1){
  1251. key = k;
  1252. break;
  1253. }
  1254. }
  1255. if (key){
  1256. fieldList.push({
  1257. "name": moudle.json.id,
  1258. "dataType": key
  1259. });
  1260. }
  1261. }.bind(this));
  1262. return fieldList;
  1263. },
  1264. checkSubform: function(){
  1265. var pcSubforms = [];
  1266. if (this.pcForm){
  1267. this.pcForm.data.json.subformList = [];
  1268. this.pcForm.moduleList.each(function(module){
  1269. if (module.moduleName==="subform"){
  1270. if (module.json.subformSelected && module.json.subformSelected!=="none" && module.json.subformType!=="script"){
  1271. if (this.pcForm.data.json.subformList.indexOf(module.json.subformSelected) === -1) this.pcForm.data.json.subformList.push(module.json.subformSelected);
  1272. }
  1273. if (module.regetSubformData()){
  1274. module.subformData.updateTime = "";
  1275. var moduleNames = module.getConflictFields();
  1276. if (moduleNames.length){
  1277. var o = {
  1278. "id": module.json.id,
  1279. "fields": moduleNames
  1280. };
  1281. pcSubforms.push(o);
  1282. }
  1283. }
  1284. }
  1285. }.bind(this));
  1286. }
  1287. var mobileSubforms = [];
  1288. if (this.mobileForm){
  1289. this.mobileForm.data.json.subformList = [];
  1290. this.mobileForm.moduleList.each(function(module){
  1291. if (module.moduleName==="subform"){
  1292. if (module.json.subformSelected && module.json.subformSelected!=="none" && module.json.subformType!=="script"){
  1293. if (this.mobileForm.data.json.subformList.indexOf(module.json.subformSelected) === -1) this.mobileForm.data.json.subformList.push(module.json.subformSelected);
  1294. }
  1295. if (module.regetSubformData()){
  1296. module.subformData.updateTime = "";
  1297. var moduleNames = module.getConflictFields();
  1298. if (moduleNames.length){
  1299. var o = {
  1300. "id": module.json.id,
  1301. "fields": moduleNames
  1302. };
  1303. mobileSubforms.push(o);
  1304. }
  1305. }
  1306. }
  1307. }.bind(this));
  1308. }
  1309. var txt = "";
  1310. if (pcSubforms.length){
  1311. var pctxt = "";
  1312. pcSubforms.each(function(subform){
  1313. pctxt += subform.id+" ( "+subform.fields.join(", ")+" ) <br>";
  1314. });
  1315. txt += this.lp.checkSubformPcInfor.replace("{subform}", pctxt);
  1316. }
  1317. if (mobileSubforms.length){
  1318. var mobiletxt = "";
  1319. mobileSubforms.each(function(subform){
  1320. mobiletxt += subform.id+" ( "+subform.fields.join(", ")+" ) <br>";
  1321. });
  1322. txt += this.lp.checkSubformMobileInfor.replace("{subform}", mobiletxt);
  1323. }
  1324. return txt;
  1325. },
  1326. saveForm: function(){
  1327. debugger;
  1328. if (!this.isSave){
  1329. var txt = this.checkSubform();
  1330. if (txt){
  1331. txt = this.lp.checkFormSaveError+txt;
  1332. this.notice(txt, "error", this.form.node);
  1333. return false;
  1334. }
  1335. var pcData, mobileData;
  1336. if (this.pcForm){
  1337. pcData = this.pcForm._getFormData();
  1338. // pcData = this.pcForm.data;
  1339. }
  1340. if (this.mobileForm){
  1341. mobileData = this.mobileForm._getFormData();
  1342. // mobileData = this.mobileForm.data;
  1343. }else{
  1344. if (this.formMobileData) mobileData = this.formMobileData;
  1345. }
  1346. this.isSave = true;
  1347. var fieldList = this.getFieldList();
  1348. //this.actions.saveForm(pcData, mobileData, fieldList, function(responseJSON){ modify by cxy
  1349. this.actions.saveForm(pcData, mobileData, fieldList, function(responseJSON){
  1350. this.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  1351. if (!this.pcForm.json.name) this.pcForm.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  1352. this.pcForm.treeNode.setTitle(this.pcForm.json.id);
  1353. this.pcForm.node.set("id", this.pcForm.json.id);
  1354. if (this.mobileForm){
  1355. if (!this.mobileForm.json.name) this.mobileForm.treeNode.setText("<"+this.mobileForm.json.type+"> "+this.mobileForm.json.id);
  1356. this.mobileForm.treeNode.setTitle(this.mobileForm.json.id);
  1357. this.mobileForm.node.set("id", this.mobileForm.json.id+"_"+this.options.mode);
  1358. }
  1359. var name = this.pcForm.json.name;
  1360. if (this.pcForm.data.isNewForm) this.setTitle(this.options.appTitle + "-"+name);
  1361. this.pcForm.data.isNewForm = false;
  1362. if (this.mobileForm) this.mobileForm.data.isNewForm = false;
  1363. this.options.desktopReload = true;
  1364. this.options.id = this.pcForm.json.id;
  1365. //this.fireAppEvent("postSave"); //add by cxy
  1366. if (this.pcForm) this.pcForm.fireEvent("postSave");
  1367. if (this.mobileForm) this.mobileForm.fireEvent("postSave");
  1368. this.fireEvent("postSave");
  1369. this.isSave = false;
  1370. }.bind(this), function(xhr, text, error){
  1371. this.isSave = false;
  1372. if (this.pcForm) this.pcForm.fireEvent("postSaveError");
  1373. if (this.mobileForm) this.mobileForm.fireEvent("postSaveError");
  1374. var errorText = error+":"+text;
  1375. if (xhr) errorText = xhr.responseText;
  1376. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1377. }.bind(this));
  1378. }else{
  1379. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  1380. }
  1381. //this.form.save(function(){
  1382. //
  1383. // var name = this.form.json.name;
  1384. // if (this.form.data.isNewForm) this.setTitle(this.options.appTitle + "-"+name);
  1385. // this.form.data.isNewForm = false;
  1386. // this.options.desktopReload = true;
  1387. // this.options.id = this.form.json.id;
  1388. //}.bind(this));
  1389. },
  1390. previewForm: function(){
  1391. this.form.preview();
  1392. },
  1393. formExplode: function(){
  1394. this.form.explode();
  1395. },
  1396. formImplode: function(){
  1397. this.form.implode();
  1398. },
  1399. htmlImplode: function(){
  1400. this.form.implodeHTML();
  1401. },
  1402. officeImplode: function(){
  1403. this.form.implodeOffice();
  1404. },
  1405. recordStatus: function(){
  1406. return {"id": this.options.id};
  1407. },
  1408. showFormVersion: function(){
  1409. this.form.showFormVersion();
  1410. },
  1411. clearNoDomModule: function(){
  1412. var _self = this;
  1413. this.confirm("warn", new Event(), MWF.APPFD.LP.clearNoDomModuleTitle, MWF.APPFD.LP.clearNoDomModuleContent, 460, 120, function(){
  1414. _self.form._clearNoDomModule();
  1415. this.close();
  1416. }, function(){
  1417. this.close();
  1418. });
  1419. },
  1420. copyPropertyToModule: function (){
  1421. if( !this.form.currentSelectedModule ){
  1422. this.notice( MWF.APPFD.LP.selectCopyModuleNotice, 'info');
  1423. return;
  1424. }
  1425. var module = this.form.currentSelectedModule;
  1426. var modulesTypes = [
  1427. ['Org', 'OOOrg','Author','Reader'],
  1428. ['Checkbox', 'OOCheckGroup', 'Radio', 'OORadioGroup', 'Select', 'OOSelect'],
  1429. ['Calendar', 'OODatetime'],
  1430. ['Textfield', 'Textarea', 'OOInput', 'OOTextarea'],,
  1431. ['Button', 'OOButton']
  1432. ].filter(function (types){
  1433. return types.contains( module.json.type );
  1434. });
  1435. modulesTypes = modulesTypes.length ? modulesTypes[0] : [module.json.type];
  1436. console.log(modulesTypes);
  1437. this.selector = new MWF.O2Selector(this.content, {
  1438. count: 1,
  1439. title: MWF.APPFD.LP.selectCopyModule,
  1440. type: 'FieldProperty',
  1441. moduleTypes: modulesTypes,
  1442. currentFormFields: Object.values(this.form.json.moduleList),
  1443. onComplete: function (items){
  1444. if( !items.length )return;
  1445. for( var key in items[0].data ){
  1446. var value = items[0].data[key];
  1447. if( !['id', 'type', 'pid'].contains(key) && module.json[key] !== value ){
  1448. module.json[key] = value;
  1449. module.setPropertiesOrStyles(key, value);
  1450. module._setEditStyle(key, null, value);
  1451. // this.setScriptJsEditor(module, change.name, change.fromValue);
  1452. }
  1453. }
  1454. if( module.property ){
  1455. module.property.reset();
  1456. }
  1457. }.bind(this)
  1458. });
  1459. },
  1460. onPostClose: function(){
  1461. if (this.pcForm){
  1462. MWF.release(this.pcForm.moduleList);
  1463. MWF.release(this.pcForm.moduleNodeList);
  1464. MWF.release(this.pcForm.moduleContainerNodeList);
  1465. MWF.release(this.pcForm.moduleElementNodeList);
  1466. MWF.release(this.pcForm.moduleComponentNodeList);
  1467. MWF.release(this.pcForm);
  1468. }
  1469. if (this.mobileForm){
  1470. MWF.release(this.mobileForm.moduleList);
  1471. MWF.release(this.mobileForm.moduleNodeList);
  1472. MWF.release(this.mobileForm.moduleContainerNodeList);
  1473. MWF.release(this.mobileForm.moduleElementNodeList);
  1474. MWF.release(this.mobileForm.moduleComponentNodeList);
  1475. MWF.release(this.mobileForm);
  1476. }
  1477. },
  1478. setTemplateFormNode: function(formNode){
  1479. var html = "<table align=\"center\" width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  1480. "<tr><td colSpan=\"2\" style=\"height: 50px; line-height: 60px; text-align: center; font-size: 24px; font-weight: bold\">" +
  1481. this.lp.saveTemplate+"</td></tr>" +
  1482. "<tr><td style=\"height: 40px;\" width=\"80px\">" +this.lp.templateName+"</td><td>"+
  1483. "<input value=\""+this.pcForm.json.name+"\" type=\"text\" style=\"width: 98%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  1484. "<tr><td style=\"height: 40px;\">" +this.lp.templateCategory+"</td><td>"+
  1485. "<select style=\"width: 30%; height: 24px; border: 1px solid #cccccc\"></select>"+
  1486. "<input type=\"text\" style=\"width: 68%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  1487. "<tr><td style=\"height: 40px;\">" +this.lp.templateDescription+"</td><td>"+
  1488. "<textarea type=\"text\" style=\"width: 98%; height: 44px; border: 1px solid #cccccc\">"+this.pcForm.json.description+"</textarea>"+"</td></tr>" +
  1489. "<tr><td colSpan=\"2\" id=\"form_templatePreview\">" +
  1490. "<div style=\"position: relative; width: 180px; height: 180px; margin: 20px auto 0px auto; overflow: hidden\"></div>" +
  1491. "</td></tr>" +
  1492. "</table>";
  1493. formNode.set("html", html);
  1494. var tds = formNode.getElements("td");
  1495. var iconNode = tds[tds.length-1].getFirst();
  1496. var previewNode = this.pcForm.node.clone();
  1497. previewNode.setStyles({
  1498. "transform-origin": "0px 0px",
  1499. "transform": "scale(0.15,0.15)",
  1500. "position": "absolute",
  1501. "top": "0px",
  1502. "left": "0px"
  1503. }).inject(iconNode);
  1504. return iconNode;
  1505. },
  1506. setCategorySelect: function(categorySelect){
  1507. if (categorySelect){
  1508. new Element("option", {"value": "$newCategory","text": this.lp.newCategory}).inject(categorySelect);
  1509. this.actions.listFormTemplateCategory(function(json){
  1510. json.data.each(function(category){
  1511. new Element("option", {"value": category.name,"text": category.name}).inject(categorySelect);
  1512. }.bind(this));
  1513. }.bind(this));
  1514. }
  1515. },
  1516. setTemplateActions: function(markNode, areaNode, formNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1517. var actionAreaNode= new Element("div", {
  1518. "styles": this.css.templateActionNode
  1519. }).inject(formNode);
  1520. var cancelActionNode = new Element("div", {
  1521. "styles": this.css.templateCancelActionNode,
  1522. "text": this.lp.cancel,
  1523. "events":{
  1524. "click": function(){
  1525. markNode.destroy();
  1526. areaNode.destroy();
  1527. }
  1528. }
  1529. }).inject(actionAreaNode);
  1530. var saveActionNode = new Element("div", {
  1531. "styles": this.css.templateSaveActionNode,
  1532. "text": this.lp.save,
  1533. "events":{
  1534. "click": function(){
  1535. this.saveTemplate(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1536. }.bind(this)
  1537. }
  1538. }).inject(actionAreaNode);
  1539. },
  1540. saveTemplate: function(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1541. var pcData, mobileData;
  1542. if (this.pcForm){
  1543. pcData = this.pcForm._getFormData();
  1544. //pcData = this.pcForm.data;
  1545. }
  1546. if (this.mobileForm){
  1547. mobileData = this.mobileForm._getFormData();
  1548. //mobileData = this.mobileForm.data;
  1549. }
  1550. var name = nameNode.get("value");
  1551. var category = (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory") ? newCategoryNode.get("value") : categorySelect.options[categorySelect.selectedIndex].value;
  1552. var description = descriptionNode.get("value");
  1553. if (!name){
  1554. this.notice(MWF.APPFD.LP.notice["saveTemplate_inputName"], "error", nameNode, {x: "left", y:"top"});
  1555. return false;
  1556. }
  1557. if (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory" && !newCategoryNode.get("value")){
  1558. this.notice(MWF.APPFD.LP.notice["saveTemplate_inputCategory"], "error", categorySelect, {x: "left", y:"top"});
  1559. return false;
  1560. }
  1561. //var tds = formNode.getElements("td");
  1562. //var iconNode = tds[tds.length-1].getFirst();
  1563. var data = {
  1564. "name": name,
  1565. "category": category,
  1566. "description": description,
  1567. "outline": iconNode.get("html")
  1568. };
  1569. this.actions.addFormTemplate(pcData, mobileData, data, function(){
  1570. this.notice(MWF.APPFD.LP.notice["saveTemplate_success"], "ok", null, {x: "left", y:"bottom"});
  1571. markNode.destroy();
  1572. areaNode.destroy();
  1573. }.bind(this), function(xhr, text, error){
  1574. var errorText = error+":"+text;
  1575. if (xhr) errorText = xhr.responseText;
  1576. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1577. });
  1578. },
  1579. createTemplateSaveNode: function(){
  1580. var markNode = new Element("div", {
  1581. "styles": this.css.templateMarkNode,
  1582. "events": {
  1583. "mouseover": function(e){e.stopPropagation();},
  1584. "mouseout": function(e){e.stopPropagation();}
  1585. }
  1586. }).inject(this.content);
  1587. var areaNode = new Element("div", {
  1588. "styles": this.css.templateAreaNode
  1589. }).inject(this.content);
  1590. var createNode = new Element("div", {
  1591. "styles": this.css.templateInfoNode
  1592. }).inject(areaNode);
  1593. var formNode = new Element("div", {
  1594. "styles": this.css.templateFormNode
  1595. }).inject(createNode);
  1596. var iconNode = this.setTemplateFormNode(formNode);
  1597. var nodes = formNode.getElements("input");
  1598. var nameNode = nodes[0];
  1599. var newCategoryNode = nodes[1];
  1600. var descriptionNode = formNode.getElement("textarea");
  1601. var categorySelect = formNode.getElement("select");
  1602. this.setCategorySelect(categorySelect);
  1603. this.setTemplateActions(markNode, areaNode, formNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1604. },
  1605. saveFormAsTemplate: function(){
  1606. if (!this.isSave){
  1607. this.createTemplateSaveNode();
  1608. }else{
  1609. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  1610. }
  1611. },
  1612. styleBrush: function(status, bt){
  1613. if (status==="on"){
  1614. var module = this.form.currentSelectedModule;
  1615. if (module && module.json.type!=="Form"){
  1616. this.form.brushStyle = module.json.styles;
  1617. if (module.json.inputStyles) this.form.brushInputStyle = Object.clone(module.json.inputStyles);
  1618. this.brushCursor = new Element("div", {"styles": {
  1619. "position": "absolute",
  1620. "width": "16px",
  1621. "height": "16px",
  1622. "z-index": 20000,
  1623. "background": "url("+this.path+this.options.style+"/pageToolbar/wand.png)"
  1624. }}).inject(this.content);
  1625. this.brushCursorMoveFun = this.brushCursorMove.bind(this);
  1626. this.contentPosition = this.content.getPosition();
  1627. this.content.addEvent("mousemove", this.brushCursorMoveFun);
  1628. //this.designNode.setStyle("cursor", "url(/"+this.path+this.options.style+"/pageToolbar/brush.png)");
  1629. }else{
  1630. bt.off();
  1631. }
  1632. }else{
  1633. this.form.brushStyle = null;
  1634. this.form.brushInputStyle = null;
  1635. if (this.brushCursorMoveFun) this.content.removeEvent("mousemove", this.brushCursorMoveFun);
  1636. if (this.brushCursor){
  1637. this.brushCursor.destroy();
  1638. this.brushCursor = null;
  1639. }
  1640. }
  1641. },
  1642. brushCursorMove: function(e){
  1643. if (this.brushCursor){
  1644. var x = e.page.x-this.contentPosition.x+10;
  1645. var y = e.page.y-this.contentPosition.y+10;
  1646. this.brushCursor.setStyles({
  1647. "left": ""+x+"px",
  1648. "top": ""+y+"px"
  1649. });
  1650. }
  1651. },
  1652. checkDatatemplateRelativeId: function( json, idMap ){
  1653. ["outerAddActionId","outerDeleteActionId","outerSelectAllId",
  1654. "addActionId","deleteActionId","sequenceId","selectorId"].each(function(key){
  1655. var str = json[key];
  1656. if(str){
  1657. var strArr;
  1658. if( str.indexOf("/") > -1 ) {
  1659. strArr = str.split("/");
  1660. }else if(str.indexOf(".*.") > -1){
  1661. strArr = str.split(".*.");
  1662. }
  1663. if(strArr){
  1664. strArr = strArr.map(function (s) {
  1665. return idMap[s] || s;
  1666. });
  1667. json[key] = strArr.join("/");
  1668. }else{
  1669. if( str && idMap[str] ){
  1670. json[key] = idMap[str];
  1671. }
  1672. }
  1673. }
  1674. }.bind(this));
  1675. },
  1676. openApp: function (){
  1677. layout.openApplication(null, 'cms.ColumnManager', {
  1678. column: this.application,
  1679. appId: 'cms.ColumnManager'+this.application.id
  1680. }, {
  1681. "navi": "formConfig"
  1682. });
  1683. }
  1684. });
  1685. MWF.xApplication.cms.FormDesigner.ToolsGroup = new Class({
  1686. Implements: [Events],
  1687. initialize: function(data, app, showing){
  1688. this.data = data;
  1689. this.app = app;
  1690. this.css = this.app.css;
  1691. this.tools = [];
  1692. this.showing = showing;
  1693. this.load();
  1694. },
  1695. load: function(){
  1696. this.toolbarGroupNode = new Element("div", {
  1697. "styles": this.css.toolbarGroupNode,
  1698. }).inject(this.app.toolbarGroupContentNode);
  1699. // this.toolbarGroupTitleNode = new Element("div", {
  1700. // "class": "mainColor_bg",
  1701. // "styles": this.css.toolbarGroupTitleNode,
  1702. // "text": this.data.text,
  1703. // "events": {
  1704. // "click": this.show.bind(this)
  1705. // }
  1706. // }).inject(this.toolbarGroupNode);
  1707. this.toolbarContentNode = new Element("div", {
  1708. "styles": this.css.toolbarContentNode,
  1709. }).inject(this.toolbarGroupNode);
  1710. this.loadTools();
  1711. if (this.toolbarContentNode){
  1712. this.app.setScrollBar(this.toolbarContentNode, null, {
  1713. "V": {"x": 0, "y": 0},
  1714. "H": {"x": 0, "y": 0}
  1715. }, function(scrollBar){
  1716. this.scrollBar = scrollBar;
  1717. }.bind(this));
  1718. }
  1719. this.toolbarContentNode.setStyle("height", "0px");
  1720. this.toolbarContentNode.hide();
  1721. var memuItem = this.app.categoryActionMenu.addMenuItem(this.data.text, "click", function(){this.show();}.bind(this));
  1722. //memuItem.styleName = style.style;
  1723. // var imgDiv = memuItem.item.getFirst();
  1724. // var imgNode = new Element("div", {"styles": memuItem.menu.css.menuItemImg}).inject(imgDiv);
  1725. // imgNode.setStyle("background-color", color);
  1726. },
  1727. setContentHeight: function(height){
  1728. this.height = height;
  1729. if (this.isShow){
  1730. this.toolbarContentNode.setStyle("height", ""+this.height+"px");
  1731. }
  1732. },
  1733. show: function( notSetDefault ){
  1734. if (this.app.currentToolGroup != this){
  1735. if (this.app.currentToolGroup) this.app.currentToolGroup.hide();
  1736. // if (!this.morph){
  1737. // this.morph = new Fx.Morph(this.toolbarContentNode, {
  1738. // "duration": "100",
  1739. // transition: Fx.Transitions.Sine.easeOut
  1740. // });
  1741. // }
  1742. // this.toolbarContentNode.show();
  1743. // this.morph.start({"height": [0, this.height]}).chain(function(){
  1744. // if (this.scrollBar && this.scrollBar.scrollVAreaNode) this.scrollBar.scrollVAreaNode.show();
  1745. // this.app.currentToolGroup = this;
  1746. // this.isShow = true;
  1747. // }.bind(this));
  1748. this.toolbarContentNode.show();
  1749. this.toolbarContentNode.setStyle("height", this.height);
  1750. if (this.scrollBar && this.scrollBar.scrollVAreaNode) this.scrollBar.scrollVAreaNode.show();
  1751. this.app.currentToolGroup = this;
  1752. this.isShow = true;
  1753. if (this.app.toolbarMode=="all") this.app.toolbarTitleNode.set("text", this.data.text);
  1754. if(!notSetDefault)this.app.setDefaultTool( this.data.name );
  1755. }
  1756. },
  1757. hide: function(){
  1758. if (this.app.currentToolGroup==this) this.app.currentToolGroup = null;
  1759. // if (!this.morph){
  1760. // this.morph = new Fx.Morph(this.toolbarContentNode, {
  1761. // "duration": "100",
  1762. // transition: Fx.Transitions.Sine.easeOut
  1763. // });
  1764. // }
  1765. // this.isShow = false;
  1766. // if (this.scrollBar && this.scrollBar.scrollVAreaNode) this.scrollBar.scrollVAreaNode.hide();
  1767. // this.morph.start({
  1768. // "height": [this.height, 0]
  1769. // }).chain(function(){
  1770. // this.toolbarContentNode.hide();
  1771. // }.bind(this));
  1772. this.toolbarContentNode.hide();
  1773. if (this.scrollBar && this.scrollBar.scrollVAreaNode) this.scrollBar.scrollVAreaNode.hide();
  1774. this.isShow = false;
  1775. },
  1776. loadTools: function(){
  1777. var designer = this.app;
  1778. var group = this;
  1779. this.getTools(function(){
  1780. Object.each(this.toolsData, function(value, key){
  1781. var toolNode = new Element("div", {
  1782. "styles": this.css.toolbarToolNode,
  1783. "title": value.text,
  1784. "events": {
  1785. "mouseover": function(e){
  1786. try {
  1787. this.setStyles(designer.css.toolbarToolNodeOver);
  1788. }catch(e){
  1789. this.setStyles(designer.css.toolbarToolNodeOverCSS2);
  1790. };
  1791. },
  1792. "mouseout": function(e){
  1793. try {
  1794. this.setStyles(designer.css.toolbarToolNode);
  1795. }catch(e){};
  1796. },
  1797. "mousedown": function(e){
  1798. try {
  1799. this.setStyles(designer.css.toolbarToolNodeDown);
  1800. }catch(e){
  1801. this.setStyles(designer.css.toolbarToolNodeDownCSS2);
  1802. };
  1803. },
  1804. "mouseup": function(e){
  1805. try {
  1806. this.setStyles(designer.css.toolbarToolNodeUp);
  1807. }catch(e){
  1808. this.setStyles(designer.css.toolbarToolNodeUpCSS2);
  1809. };
  1810. }
  1811. }
  1812. }).inject(this.toolbarContentNode);
  1813. toolNode.store("toolClass", value.className);
  1814. var iconNode = new Element("div", {
  1815. "styles": this.css.toolbarToolIconNode
  1816. }).inject(toolNode);
  1817. if (value.icon) iconNode.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/"+value.icon+")");
  1818. if (value.fontIcon){
  1819. iconNode.addClass("mainColor_color");
  1820. iconNode.set("html", "<i class=\""+value.fontIcon+"\"></i>");
  1821. }
  1822. var textNode = new Element("div.o2formModuleTools", {
  1823. "styles": this.css.toolbarToolTextNode,
  1824. "text": value.text
  1825. });
  1826. textNode.inject(toolNode);
  1827. toolNode.addEvent("mousedown", function(e){
  1828. var className = this.retrieve("toolClass");
  1829. designer.form.createModule(className, e, group.data.name);
  1830. });
  1831. this.tools.push(toolNode);
  1832. }.bind(this));
  1833. //if (this.data.name==="default") this.show();
  1834. if( this.showing )this.show( true );
  1835. }.bind(this));
  1836. },
  1837. getTools: function(callback){
  1838. if (this.toolsData){
  1839. if (callback) callback();
  1840. }else{
  1841. var toolsDataUrl = this.app.path+this.app.options.style+"/"+this.data.json;
  1842. o2.JSON.get(toolsDataUrl, function(responseJSON){
  1843. this.toolsData = responseJSON;
  1844. if (!this.app.toolsData){
  1845. this.app.toolsData = this.toolsData;
  1846. }else{
  1847. this.app.toolsData = Object.merge(this.app.toolsData, this.toolsData)
  1848. }
  1849. if (callback) callback();
  1850. }.bind(this));
  1851. }
  1852. }
  1853. });