Main.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  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": "template.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. },
  27. onQueryLoad: function(){
  28. this.shortcut = true;
  29. if (this.status){
  30. this.options.id = this.status.id;
  31. }
  32. if (!this.options.id){
  33. this.options.desktopReload = false;
  34. this.options.title = this.options.title + "-"+MWF.CMSFD.LP.newForm;
  35. }
  36. this.actions = new MWF.xApplication.cms.ColumnManager.Actions.RestActions();
  37. this.lp = MWF.xApplication.cms.FormDesigner.LP;
  38. // this.processData = this.options.processData;
  39. },
  40. loadApplication: function(callback){
  41. this.createNode();
  42. if (!this.options.isRefresh){
  43. this.maxSize(function(){
  44. this.openForm();
  45. }.bind(this));
  46. }else{
  47. this.openForm();
  48. }
  49. this.addKeyboardEvents();
  50. if (callback) callback();
  51. },
  52. addKeyboardEvents: function(){
  53. this.addEvent("copy", function(){
  54. this.copyModule();
  55. }.bind(this));
  56. this.addEvent("paste", function(){
  57. this.pasteModule();
  58. }.bind(this));
  59. this.addEvent("cut", function(){
  60. this.cutModule();
  61. }.bind(this));
  62. this.addEvent("keySave", function(e){
  63. this.keySave(e);
  64. }.bind(this));
  65. this.addEvent("keyDelete", function(e){
  66. this.keyDelete(e);
  67. }.bind(this));
  68. },
  69. keySave: function(e){
  70. if (this.shortcut) {
  71. if (this.form) this.saveForm();
  72. e.preventDefault();
  73. }
  74. },
  75. keyDelete: function(e){
  76. if (this.form){
  77. if (this.shortcut){
  78. if (this.form.currentSelectedModule){
  79. var module = this.form.currentSelectedModule;
  80. if (module.moduleType!="form" && module.moduleName.indexOf("$")==-1){
  81. module["delete"](module.node);
  82. }
  83. }
  84. }
  85. }
  86. },
  87. copyModule: function(){
  88. if (this.shortcut) {
  89. if (this.form) {
  90. // if (this.form.isFocus){
  91. if (this.form.currentSelectedModule) {
  92. var module = this.form.currentSelectedModule;
  93. if (module.moduleType != "form" && module.moduleName.indexOf("$") == -1) {
  94. var html = module.getHtml();
  95. var json = module.getJson();
  96. MWF.clipboard.data = {
  97. "type": "form",
  98. "data": {
  99. "html": html,
  100. "json": json
  101. }
  102. };
  103. } else {
  104. MWF.clipboard.data = null;
  105. }
  106. }
  107. // }
  108. }
  109. }
  110. },
  111. cutModule: function(){
  112. if (this.shortcut) {
  113. if (this.form) {
  114. // if (this.form.isFocus){
  115. if (this.form.currentSelectedModule) {
  116. var module = this.form.currentSelectedModule;
  117. if (module.moduleType != "form" && module.moduleName.indexOf("$") == -1) {
  118. this.copyModule();
  119. module.destroy();
  120. module.form.selected();
  121. }
  122. }
  123. // }
  124. }
  125. }
  126. },
  127. pasteModule: function(){
  128. if (this.shortcut) {
  129. if (this.form) {
  130. // if (this.form.isFocus){
  131. if (MWF.clipboard.data) {
  132. if (MWF.clipboard.data.type == "form") {
  133. var html = MWF.clipboard.data.data.html;
  134. var json = Object.clone(MWF.clipboard.data.data.json);
  135. var tmpNode = Element("div", {
  136. "styles": {"display": "none"},
  137. "html": html
  138. }).inject(this.content);
  139. //var pid = "";
  140. Object.each(json, function (moduleJson) {
  141. var oid = moduleJson.id;
  142. var id = moduleJson.id;
  143. // if (!pid){
  144. var idx = 1;
  145. while (this.form.json.moduleList[id]) {
  146. id = oid + "_" + idx;
  147. idx++;
  148. }
  149. // pid = id;
  150. // }else{
  151. // idx = 1;
  152. // var id = pid+"_"+moduleJson.moduleName;
  153. // var prefix = pid+"_"+moduleJson.moduleName;
  154. // while (this.form.json.moduleList[id]){
  155. // id = prefix+"_"+idx;
  156. // idx++;
  157. // }
  158. // }
  159. if (oid != id) {
  160. moduleJson.id = id;
  161. var moduleNode = tmpNode.getElementById(oid);
  162. if (moduleNode) moduleNode.set("id", id);
  163. }
  164. this.form.json.moduleList[moduleJson.id] = moduleJson;
  165. }.bind(this));
  166. delete json;
  167. var injectNode = this.form.node;
  168. var where = "bottom";
  169. var parent = this.form;
  170. if (this.form.currentSelectedModule) {
  171. var toModule = this.form.currentSelectedModule;
  172. injectNode = toModule.node;
  173. parent = toModule;
  174. if (toModule.moduleType != "container" && toModule.moduleType != "form") {
  175. where = "after";
  176. parent = toModule.parentContainer;
  177. }
  178. }
  179. var copyModuleNode = tmpNode.getFirst();
  180. while (copyModuleNode) {
  181. copyModuleNode.inject(injectNode, where);
  182. var copyModuleJson = this.form.getDomjson(copyModuleNode);
  183. module = this.form.loadModule(copyModuleJson, copyModuleNode, parent);
  184. module._setEditStyle_custom("id");
  185. module.selected();
  186. //loadModule: function(json, dom, parent)
  187. copyModuleNode = tmpNode.getFirst();
  188. }
  189. tmpNode.destroy();
  190. delete tmpNode;
  191. }
  192. }
  193. // }
  194. }
  195. }
  196. },
  197. createNode: function(){
  198. this.content.setStyle("overflow", "hidden");
  199. this.node = new Element("div", {
  200. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  201. }).inject(this.content);
  202. },
  203. openForm: function(){
  204. this.initOptions();
  205. this.loadNodes();
  206. this.loadToolbar();
  207. this.loadFormNode();
  208. this.loadProperty();
  209. this.loadTools();
  210. this.resizeNode();
  211. this.addEvent("resize", this.resizeNode.bind(this));
  212. this.loadForm();
  213. if (this.toolbarContentNode){
  214. this.setScrollBar(this.toolbarContentNode, null, {
  215. "V": {"x": 0, "y": 0},
  216. "H": {"x": 0, "y": 0}
  217. });
  218. //this.setScrollBar(this.propertyDomScrollArea, "form_property", {
  219. // "V": {"x": 0, "y": 0},
  220. // "H": {"x": 0, "y": 0}
  221. //});
  222. MWF.require("MWF.widget.ScrollBar", function(){
  223. new MWF.widget.ScrollBar(this.propertyDomScrollArea, {
  224. "style":"default", "where": "before", "distance": 30, "friction": 4, "indent": false, "axis": {"x": false, "y": true}
  225. });
  226. }.bind(this));
  227. }
  228. },
  229. initOptions: function(){
  230. this.toolsData = null;
  231. this.toolbarMode = "all";
  232. this.tools = [];
  233. this.toolbarDecrease = 0;
  234. this.designNode = null;
  235. this.form = null;
  236. },
  237. loadNodes: function(){
  238. this.toolbarNode = new Element("div", {
  239. "styles": this.css.toolbarNode,
  240. "events": {"selectstart": function(e){e.preventDefault();}}
  241. }).inject(this.node);
  242. this.propertyNode = new Element("div", {
  243. "styles": this.css.propertyNode
  244. }).inject(this.node)
  245. this.formNode = new Element("div", {
  246. "styles": this.css.formNode
  247. }).inject(this.node);
  248. if (this.options.style=="bottom") this.propertyNode.inject(this.formNode, "after");
  249. },
  250. //loadToolbar----------------------
  251. loadToolbar: function(){
  252. this.toolbarTitleNode = new Element("div", {
  253. "styles": this.css.toolbarTitleNode,
  254. "text": MWF.APPFD.LP.tools
  255. }).inject(this.toolbarNode);
  256. this.toolbarTitleActionNode = new Element("div", {
  257. "styles": this.css.toolbarTitleActionNode,
  258. "events": {
  259. "click": function(e){
  260. this.switchToolbarMode();
  261. }.bind(this)
  262. }
  263. }).inject(this.toolbarNode);
  264. this.toolbarContentNode = new Element("div", {
  265. "styles": this.css.toolbarContentNode,
  266. "events": {
  267. "selectstart": function(e){
  268. e.preventDefault();
  269. e.stopPropagation();
  270. }
  271. }
  272. }).inject(this.toolbarNode);
  273. },
  274. switchToolbarMode: function(){
  275. if (this.toolbarMode=="all"){
  276. var size = this.toolbarNode.getSize();
  277. this.toolbarDecrease = (size.x.toFloat())-60;
  278. this.tools.each(function(node){
  279. node.getLast().setStyle("display", "none");
  280. });
  281. this.toolbarTitleNode.set("text", "");
  282. this.toolbarNode.setStyle("width", "60px");
  283. var formMargin = this.formNode.getStyle("margin-left").toFloat();
  284. formMargin = formMargin - this.toolbarDecrease;
  285. this.formNode.setStyle("margin-left", ""+formMargin+"px");
  286. this.toolbarTitleActionNode.setStyles(this.css.toolbarTitleActionNodeRight);
  287. this.toolbarMode="simple";
  288. }else{
  289. sizeX = 60 + this.toolbarDecrease;
  290. var formMargin = this.formNode.getStyle("margin-left").toFloat();
  291. formMargin = formMargin + this.toolbarDecrease;
  292. this.toolbarNode.setStyle("width", ""+sizeX+"px");
  293. this.formNode.setStyle("margin-left", ""+formMargin+"px");
  294. this.tools.each(function(node){
  295. node.getLast().setStyle("display", "block");
  296. });
  297. this.toolbarTitleNode.set("text", MWF.APPFD.LP.tools);
  298. this.toolbarTitleActionNode.setStyles(this.css.toolbarTitleActionNode);
  299. this.toolbarMode="all";
  300. }
  301. },
  302. //loadFormNode------------------------------
  303. loadFormNode: function(){
  304. this.formToolbarNode = new Element("div", {
  305. "styles": this.css.formToolbarNode
  306. }).inject(this.formNode);
  307. this.loadFormToolbar();
  308. this.formContentNode = new Element("div", {
  309. "styles": this.css.formContentNode
  310. }).inject(this.formNode);
  311. this.loadFormContent(function(){
  312. if (this.designDcoument) this.designDcoument.body.setStyles(this.css.designBody);
  313. if (this.designNode) this.designNode.setStyles(this.css.designNode);
  314. }.bind(this));
  315. },
  316. loaddesignerActionNode: function(){
  317. this.pcDesignerActionNode = this.formToolbarNode.getElement("#MWFFormPCDesignerAction");
  318. this.mobileDesignerActionNode = this.formToolbarNode.getElement("#MWFFormMobileDesignerAction");
  319. this.currentDesignerMode = "PC";
  320. this.pcDesignerActionNode.setStyles(this.css.designerActionNode_current);
  321. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode);
  322. var iconNode = new Element("div", {"styles": this.css.designerActionPcIconNode}).inject(this.pcDesignerActionNode);
  323. iconNode = new Element("div", {"styles": this.css.designerActionMobileIconNode}).inject(this.mobileDesignerActionNode);
  324. var textNode = new Element("div", {"styles": this.css.designerActiontextNode, "text": "PC"}).inject(this.pcDesignerActionNode);
  325. textNode = new Element("div", {"styles": this.css.designerActiontextNode, "text": "Mobile"}).inject(this.mobileDesignerActionNode);
  326. this.pcDesignerActionNode.addEvent("click", function(){
  327. if (this.currentDesignerMode!="PC"){
  328. this.changeDesignerModeToPC();
  329. }
  330. }.bind(this));
  331. this.mobileDesignerActionNode.addEvent("click", function(){
  332. if (this.currentDesignerMode=="PC"){
  333. this.changeDesignerModeToMobile();
  334. }
  335. }.bind(this));
  336. },
  337. changeDesignerModeToPC: function(){
  338. this.pcDesignerActionNode.setStyles(this.css.designerActionNode_current);
  339. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode);
  340. this.designMobileNode.setStyle("display", "none");
  341. this.designNode.setStyle("display", "block");
  342. if (this.form.currentSelectedModule){
  343. if (this.form.currentSelectedModule==this){
  344. return true;
  345. }else{
  346. this.form.currentSelectedModule.unSelected();
  347. }
  348. }
  349. if (this.form.propertyMultiTd){
  350. this.form.propertyMultiTd.hide();
  351. this.form.propertyMultiTd = null;
  352. }
  353. this.form.unSelectedMulti();
  354. this.form = this.pcForm;
  355. this.currentDesignerMode = "PC";
  356. },
  357. changeDesignerModeToMobile: function(){
  358. this.pcDesignerActionNode.setStyles(this.css.designerActionNode);
  359. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode_current);
  360. this.designMobileNode.setStyle("display", "block");
  361. this.designNode.setStyle("display", "none");
  362. if (this.form.currentSelectedModule){
  363. if (this.form.currentSelectedModule==this){
  364. return true;
  365. }else{
  366. this.form.currentSelectedModule.unSelected();
  367. }
  368. }
  369. if (this.form.propertyMultiTd){
  370. this.form.propertyMultiTd.hide();
  371. this.form.propertyMultiTd = null;
  372. }
  373. this.form.unSelectedMulti();
  374. if (!this.mobileForm){
  375. this.mobileForm = new MWF.CMSFCForm(this, this.designMobileNode, {"mode": "Mobile"});
  376. this.mobileForm.load(this.formMobileData);
  377. }
  378. this.form = this.mobileForm;
  379. this.currentDesignerMode = "Mobile";
  380. },
  381. loadFormToolbar: function(callback){
  382. this.getFormToolbarHTML(function(toolbarNode){
  383. var spans = toolbarNode.getElements("span");
  384. spans.each(function(item, idx){
  385. var img = item.get("MWFButtonImage");
  386. if (img){
  387. item.set("MWFButtonImage", this.path+""+this.options.style+"/formtoolbar/"+img);
  388. }
  389. }.bind(this));
  390. $(toolbarNode).inject(this.formToolbarNode);
  391. MWF.require("MWF.widget.Toolbar", function(){
  392. this.formToolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "ProcessCategory"}, this);
  393. this.formToolbar.load();
  394. this.loaddesignerActionNode();
  395. if (callback) callback();
  396. }.bind(this));
  397. }.bind(this));
  398. },
  399. getFormToolbarHTML: function(callback){
  400. var toolbarUrl = this.path+this.options.style+"/formToolbars.html";
  401. var r = new Request.HTML({
  402. url: toolbarUrl,
  403. method: "get",
  404. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  405. var toolbarNode = responseTree[0];
  406. if (callback) callback(toolbarNode);
  407. }.bind(this),
  408. onFailure: function(xhr){
  409. this.notice("request processToolbars error: "+xhr.responseText, "error");
  410. }.bind(this)
  411. });
  412. r.send();
  413. },
  414. loadFormContent: function(callback){
  415. //var iframe = new Element("iframe#iframeaa", {
  416. // "styles": {
  417. // "width": "100%",
  418. // "height": "100%"
  419. // },
  420. // //"src": "/x_component_process_FormDesigner/$Main/blank.html",
  421. // "border": "0"
  422. //}).inject(this.formContentNode);
  423. // window.setTimeout(function(){
  424. // iframe.contentDocument.designMode = "on";
  425. //
  426. //
  427. // var x = document.id("iframeaa");
  428. // this.designNode = document.id(iframe.contentDocument.body, false, iframe.contentDocument);
  429. // this.designNode.setStyle("margin", "0px");
  430. // this.designNode.setStyles(this.css.designNode);
  431. this.designNode = new Element("div", {
  432. "styles": this.css.designNode
  433. }).inject(this.formContentNode);
  434. //this.designContentNode = new Element("div", {
  435. // "styles": {"overflow": "visible"}
  436. //}).inject(this.designNode);
  437. //MWF.require("MWF.widget.ScrollBar", function(){
  438. // new MWF.widget.ScrollBar(this.designNode, {"distance": 100});
  439. //}.bind(this));
  440. this.designMobileNode = new Element("div", {
  441. "styles": this.css.designMobileNode
  442. }).inject(this.formContentNode);
  443. //MWF.require("MWF.widget.ScrollBar", function(){
  444. // new MWF.widget.ScrollBar(this.designMobileNode, {"distance": 50, "style": "xApp_mobileForm"});
  445. //}.bind(this));
  446. // }.bind(this), 2000);
  447. },
  448. reloadPropertyStyles: function(){
  449. //MWF.release(this.css);
  450. this.css = null;
  451. this.cssPath = "/x_component_"+this.options.name.replace(/\./g, "_")+"/$Main/"+this.options.style+"/css.wcss";
  452. this._loadCss();
  453. if (this.options.style=="bottom"){
  454. this.propertyNode.inject(this.formNode, "after");
  455. this.propertyTitleNode.setStyle("cursor", "row-resize");
  456. this.loadPropertyResizeBottom();
  457. }else{
  458. this.propertyNode.inject(this.formNode, "before");
  459. this.propertyTitleNode.setStyle("cursor", "default");
  460. if (this.propertyResizeBottom) this.propertyResizeBottom.detach();
  461. }
  462. this.formNode.clearStyles(false);
  463. this.formNode.setStyles(this.css.formNode);
  464. this.propertyNode.clearStyles(false);
  465. this.propertyNode.setStyles(this.css.propertyNode);
  466. this.propertyTitleNode.clearStyles(false);
  467. this.propertyTitleNode.setStyles(this.css.propertyTitleNode);
  468. this.propertyResizeBar.clearStyles(false);
  469. this.propertyResizeBar.setStyles(this.css.propertyResizeBar);
  470. this.propertyContentNode.clearStyles(false);
  471. this.propertyContentNode.setStyles(this.css.propertyContentNode);
  472. this.propertyDomContentArea.clearStyles(false);
  473. this.propertyDomContentArea.setStyles(this.css.propertyDomContentArea);
  474. this.propertyDomScrollArea.clearStyles(false);
  475. this.propertyDomScrollArea.setStyles(this.css.propertyDomScrollArea);
  476. this.propertyDomArea.clearStyles(false);
  477. this.propertyDomArea.setStyles(this.css.propertyDomArea);
  478. this.propertyContentArea.clearStyles(false);
  479. this.propertyContentArea.setStyles(this.css.propertyContentArea);
  480. this.propertyContentResizeNode.clearStyles(false);
  481. this.propertyContentResizeNode.setStyles(this.css.propertyContentResizeNode);
  482. this.propertyTitleActionNode.clearStyles(false);
  483. this.propertyTitleActionNode.setStyles(this.css.propertyTitleActionNode);
  484. this.resizeNode();
  485. },
  486. //loadProperty------------------------
  487. loadProperty: function(){
  488. this.propertyTitleActionNode = new Element("div", {
  489. "styles": this.css.propertyTitleActionNode
  490. }).inject(this.propertyNode);
  491. this.propertyTitleActionNode.addEvent("click", function(){
  492. this.options.style = (this.options.style=="default") ? "bottom" : "default";
  493. MWF.UD.putData("formDesignerStyle", {"style": this.options.style});
  494. this.reloadPropertyStyles();
  495. }.bind(this));
  496. this.propertyTitleNode = new Element("div", {
  497. "styles": this.css.propertyTitleNode,
  498. "text": MWF.APPFD.LP.property
  499. }).inject(this.propertyNode);
  500. if (this.options.style=="bottom"){
  501. this.propertyTitleNode.setStyle("cursor", "row-resize");
  502. this.loadPropertyResizeBottom();
  503. }
  504. this.propertyResizeBar = new Element("div", {
  505. "styles": this.css.propertyResizeBar
  506. }).inject(this.propertyNode);
  507. this.loadPropertyResize();
  508. this.propertyContentNode = new Element("div", {
  509. "styles": this.css.propertyContentNode
  510. }).inject(this.propertyNode);
  511. this.propertyDomContentArea = new Element("div", {
  512. "styles": this.css.propertyDomContentArea
  513. }).inject(this.propertyContentNode);
  514. this.propertyDomScrollArea = new Element("div", {
  515. "styles": this.css.propertyDomScrollArea
  516. }).inject(this.propertyDomContentArea);
  517. this.propertyDomArea = new Element("div", {
  518. "styles": this.css.propertyDomArea
  519. }).inject(this.propertyDomScrollArea);
  520. this.propertyDomPercent = 0.3;
  521. this.propertyContentResizeNode = new Element("div", {
  522. "styles": this.css.propertyContentResizeNode
  523. }).inject(this.propertyContentNode);
  524. this.propertyContentArea = new Element("div", {
  525. "styles": this.css.propertyContentArea
  526. }).inject(this.propertyContentNode);
  527. this.loadPropertyContentResize();
  528. },
  529. loadPropertyResizeBottom: function(){
  530. if (!this.propertyResizeBottom){
  531. this.propertyResizeBottom = new Drag(this.propertyTitleNode,{
  532. "snap": 1,
  533. "onStart": function(el, e){
  534. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  535. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  536. el.store("position", {"x": x, "y": y});
  537. var size = this.propertyNode.getSize();
  538. el.store("initialWidth", size.x);
  539. el.store("initialHeight", size.y);
  540. }.bind(this),
  541. "onDrag": function(el, e){
  542. // var x = e.event.x;
  543. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  544. var bodySize = this.content.getSize();
  545. var position = el.retrieve("position");
  546. var initialHeight = el.retrieve("initialHeight").toFloat();
  547. var dy = position.y.toFloat()-y.toFloat();
  548. var height = initialHeight+dy;
  549. if (height> bodySize.y/1.5) height = bodySize.y/1.5;
  550. if (height<40) height = 40;
  551. var percent = 1-(height/bodySize.y);
  552. this.resizeNode(percent);
  553. //var formNodeHeight = bodySize.y-height;
  554. //this.formNode.setStyle("height", ""+formNodeHeight+"px");
  555. //this.propertyNode.setStyle("height", ""+height+"px");
  556. }.bind(this)
  557. });
  558. }else{
  559. this.propertyResizeBottom.attach();
  560. }
  561. },
  562. loadPropertyResize: function(){
  563. // var size = this.propertyNode.getSize();
  564. // var position = this.propertyResizeBar.getPosition();
  565. this.propertyResize = new Drag(this.propertyResizeBar,{
  566. "snap": 1,
  567. "onStart": function(el, e){
  568. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  569. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  570. el.store("position", {"x": x, "y": y});
  571. var size = this.propertyNode.getSize();
  572. el.store("initialWidth", size.x);
  573. }.bind(this),
  574. "onDrag": function(el, e){
  575. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  576. // var y = e.event.y;
  577. var bodySize = this.content.getSize();
  578. var position = el.retrieve("position");
  579. var initialWidth = el.retrieve("initialWidth").toFloat();
  580. var dx = position.x.toFloat()-x.toFloat();
  581. var width = initialWidth+dx;
  582. if (width> bodySize.x/2) width = bodySize.x/2;
  583. if (width<40) width = 40;
  584. this.formNode.setStyle("margin-right", width+1);
  585. this.propertyNode.setStyle("width", width);
  586. }.bind(this)
  587. });
  588. },
  589. propertyResizeDragTopBottom: function(el, e){
  590. var size = this.propertyContentNode.getSize();
  591. // var x = e.event.x;
  592. var y = e.event.y;
  593. var position = el.retrieve("position");
  594. var dy = y.toFloat()-position.y.toFloat();
  595. var initialHeight = el.retrieve("initialHeight").toFloat();
  596. var height = initialHeight+dy;
  597. if (height<40) height = 40;
  598. if (height> size.y-40) height = size.y-40;
  599. this.propertyDomPercent = height/size.y;
  600. this.setPropertyContentResize();
  601. },
  602. propertyResizeDragLeftRight: function(el, e){
  603. var size = this.propertyContentNode.getSize();
  604. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  605. //var y = e.event.y;
  606. var position = el.retrieve("position");
  607. var dx = x.toFloat()-position.x.toFloat();
  608. var initialWidth = el.retrieve("initialWidth").toFloat();
  609. var width = initialWidth+dx;
  610. if (width<40) width = 40;
  611. if (width> size.x-40) width = size.x-40;
  612. this.propertyDomPercent = width/size.x;
  613. this.setPropertyContentResizeBottom();
  614. },
  615. loadPropertyContentResize: function(){
  616. this.propertyContentResize = new Drag(this.propertyContentResizeNode, {
  617. "snap": 1,
  618. "onStart": function(el, e){
  619. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  620. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  621. el.store("position", {"x": x, "y": y});
  622. var size = this.propertyDomContentArea.getSize();
  623. el.store("initialHeight", size.y);
  624. el.store("initialWidth", size.x);
  625. }.bind(this),
  626. "onDrag": function(el, e){
  627. if (this.options.style=="bottom"){
  628. this.propertyResizeDragLeftRight(el, e);
  629. }else{
  630. this.propertyResizeDragTopBottom(el, e);
  631. }
  632. }.bind(this)
  633. });
  634. },
  635. setPropertyContentResizeBottom: function(){
  636. var size = this.propertyContentNode.getSize();
  637. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  638. var width = size.x-resizeNodeSize.x-6;
  639. var domWidth = this.propertyDomPercent*width;
  640. var contentMargin = domWidth+resizeNodeSize.x+6;
  641. this.propertyDomContentArea.setStyle("width", ""+domWidth+"px");
  642. this.propertyContentArea.setStyle("margin-left", ""+contentMargin+"px");
  643. },
  644. setPropertyContentResize: function(){
  645. var size = this.propertyContentNode.getSize();
  646. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  647. var height = size.y-resizeNodeSize.y;
  648. var domHeight = this.propertyDomPercent*height;
  649. var contentHeight = height-domHeight;
  650. this.propertyDomContentArea.setStyle("height", ""+domHeight+"px");
  651. this.propertyDomScrollArea.setStyle("height", ""+domHeight+"px");
  652. this.propertyContentArea.setStyle("height", ""+contentHeight+"px");
  653. if (this.form){
  654. if (this.form.currentSelectedModule){
  655. if (this.form.currentSelectedModule.property){
  656. var tab = this.form.currentSelectedModule.property.propertyTab;
  657. if (tab){
  658. var tabTitleSize = tab.tabNodeContainer.getSize();
  659. tab.pages.each(function(page){
  660. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  661. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  662. var tabContentNodeAreaHeight = contentHeight - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  663. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  664. }.bind(this));
  665. }
  666. }
  667. }
  668. }
  669. },
  670. //loadTools------------------------------
  671. loadTools: function(){
  672. var designer = this;
  673. this.getTools(function(){
  674. Object.each(this.toolsData, function(value, key){
  675. var toolNode = new Element("div", {
  676. "styles": this.css.toolbarToolNode,
  677. "title": value.text,
  678. "events": {
  679. "mouseover": function(e){
  680. try {
  681. this.setStyles(designer.css.toolbarToolNodeOver);
  682. }catch(e){
  683. this.setStyles(designer.css.toolbarToolNodeOverCSS2);
  684. };
  685. },
  686. "mouseout": function(e){
  687. try {
  688. this.setStyles(designer.css.toolbarToolNode);
  689. }catch(e){};
  690. },
  691. "mousedown": function(e){
  692. try {
  693. this.setStyles(designer.css.toolbarToolNodeDown);
  694. }catch(e){
  695. this.setStyles(designer.css.toolbarToolNodeDownCSS2);
  696. };
  697. },
  698. "mouseup": function(e){
  699. try {
  700. this.setStyles(designer.css.toolbarToolNodeUp);
  701. }catch(e){
  702. this.setStyles(designer.css.toolbarToolNodeUpCSS2);
  703. };
  704. }
  705. }
  706. }).inject(this.toolbarContentNode);
  707. toolNode.store("toolClass", value.className);
  708. var iconNode = new Element("div", {
  709. "styles": this.css.toolbarToolIconNode
  710. }).inject(toolNode);
  711. iconNode.setStyle("background-image", "url("+this.path+this.options.style+"/icon/"+value.icon+")");
  712. var textNode = new Element("div", {
  713. "styles": this.css.toolbarToolTextNode,
  714. "text": value.text
  715. });
  716. textNode.inject(toolNode);
  717. // var designer = this;
  718. toolNode.addEvent("mousedown", function(e){
  719. debugger;
  720. var className = this.retrieve("toolClass");
  721. designer.form.createModule(className, e);
  722. });
  723. this.tools.push(toolNode);
  724. }.bind(this));
  725. }.bind(this));
  726. },
  727. getTools: function(callback){
  728. if (this.toolsData){
  729. if (callback) callback();
  730. }else{
  731. var toolsDataUrl = this.path+this.options.style+"/tools.json";
  732. var r = new Request.JSON({
  733. url: toolsDataUrl,
  734. secure: false,
  735. async: false,
  736. method: "get",
  737. noCache: true,
  738. onSuccess: function(responseJSON, responseText){
  739. this.toolsData = responseJSON;
  740. if (callback) callback();
  741. }.bind(this),
  742. onError: function(text, error){
  743. this.notice("request tools data error: "+error, "error");
  744. }.bind(this)
  745. });
  746. r.send();
  747. }
  748. },
  749. //resizeNode------------------------------------------------
  750. resizeNodeLeftRight: function(){
  751. var nodeSize = this.node.getSize();
  752. this.toolbarNode.setStyle("height", ""+nodeSize.y+"px");
  753. this.formNode.setStyle("height", ""+nodeSize.y+"px");
  754. this.propertyNode.setStyle("height", ""+nodeSize.y+"px");
  755. //nodeSize = {"x": nodeSize.x, "y": nodeSize.y*0.6};
  756. var formToolbarMarginTop = this.formToolbarNode.getStyle("margin-top").toFloat();
  757. var formToolbarMarginBottom = this.formToolbarNode.getStyle("margin-bottom").toFloat();
  758. var allFormToolberSize = this.formToolbarNode.getComputedSize();
  759. var y = nodeSize.y - allFormToolberSize.totalHeight - formToolbarMarginTop - formToolbarMarginBottom;
  760. this.formContentNode.setStyle("height", ""+y+"px");
  761. if (this.designNode){
  762. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  763. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  764. y = nodeSize.y - allFormToolberSize.totalHeight - formToolbarMarginTop - formToolbarMarginBottom - designMarginTop - designMarginBottom;
  765. this.designNode.setStyle("height", ""+y+"px");
  766. }
  767. var titleSize = this.toolbarTitleNode.getSize();
  768. var titleMarginTop = this.toolbarTitleNode.getStyle("margin-top").toFloat();
  769. var titleMarginBottom = this.toolbarTitleNode.getStyle("margin-bottom").toFloat();
  770. var titlePaddingTop = this.toolbarTitleNode.getStyle("padding-top").toFloat();
  771. var titlePaddingBottom = this.toolbarTitleNode.getStyle("padding-bottom").toFloat();
  772. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  773. y = nodeSize.y-y;
  774. this.toolbarContentNode.setStyle("height", ""+y+"px");
  775. titleSize = this.propertyTitleNode.getSize();
  776. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  777. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  778. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  779. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  780. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  781. y = nodeSize.y-y;
  782. this.propertyContentNode.setStyle("height", ""+y+"px");
  783. this.propertyResizeBar.setStyle("height", ""+y+"px");
  784. },
  785. resizeNodeTopBottom: function(percent){
  786. var nodeSize = this.node.getSize();
  787. this.toolbarNode.setStyle("height", ""+nodeSize.y+"px");
  788. var percentNumber = percent || 0.6
  789. var designerHeight = nodeSize.y*percentNumber;
  790. var propertyHeight = nodeSize.y - designerHeight;
  791. this.formNode.setStyle("height", ""+designerHeight+"px");
  792. this.propertyNode.setStyle("height", ""+propertyHeight+"px");
  793. var formToolbarMarginTop = this.formToolbarNode.getStyle("margin-top").toFloat();
  794. var formToolbarMarginBottom = this.formToolbarNode.getStyle("margin-bottom").toFloat();
  795. var allFormToolberSize = this.formToolbarNode.getComputedSize();
  796. var y = designerHeight - allFormToolberSize.totalHeight - formToolbarMarginTop - formToolbarMarginBottom;
  797. // this.formContentNode.setStyle("height", ""+designerHeight+"px");
  798. if (this.designNode){
  799. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  800. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  801. y = designerHeight - allFormToolberSize.totalHeight - formToolbarMarginTop - formToolbarMarginBottom - designMarginTop - designMarginBottom;
  802. this.designNode.setStyle("height", ""+y+"px");
  803. }
  804. var titleSize = this.toolbarTitleNode.getSize();
  805. var titleMarginTop = this.toolbarTitleNode.getStyle("margin-top").toFloat();
  806. var titleMarginBottom = this.toolbarTitleNode.getStyle("margin-bottom").toFloat();
  807. var titlePaddingTop = this.toolbarTitleNode.getStyle("padding-top").toFloat();
  808. var titlePaddingBottom = this.toolbarTitleNode.getStyle("padding-bottom").toFloat();
  809. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  810. y = nodeSize.y-y;
  811. this.toolbarContentNode.setStyle("height", ""+y+"px");
  812. titleSize = this.propertyTitleNode.getSize();
  813. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  814. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  815. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  816. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  817. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  818. y = propertyHeight-y;
  819. this.propertyContentNode.setStyle("height", ""+y+"px");
  820. this.propertyResizeBar.setStyle("height", ""+y+"px");
  821. this.propertyDomContentArea.setStyle("height", ""+y+"px");
  822. this.propertyDomScrollArea.setStyle("height", ""+y+"px");
  823. this.propertyContentResizeNode.setStyle("height", ""+y+"px");
  824. this.propertyContentArea.setStyle("height", ""+y+"px");
  825. if (this.form){
  826. if (this.form.currentSelectedModule){
  827. if (this.form.currentSelectedModule.property){
  828. var tab = this.form.currentSelectedModule.property.propertyTab;
  829. if (tab){
  830. var tabTitleSize = tab.tabNodeContainer.getSize();
  831. tab.pages.each(function(page){
  832. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  833. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  834. var tabContentNodeAreaHeight = y - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  835. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  836. }.bind(this));
  837. }
  838. }
  839. }
  840. }
  841. },
  842. resizeNode: function(percent){
  843. if (this.options.style=="bottom"){
  844. this.resizeNodeTopBottom(percent);
  845. this.setPropertyContentResizeBottom();
  846. }else{
  847. this.resizeNodeLeftRight(percent);
  848. this.setPropertyContentResize();
  849. }
  850. },
  851. //loadForm------------------------------------------
  852. loadForm: function(){
  853. // try{
  854. this.getFormData(function(){
  855. this.pcForm = new MWF.CMSFCForm(this, this.designNode);
  856. this.pcForm.load(this.formData);
  857. this.form = this.pcForm;
  858. }.bind(this));
  859. // }catch(e){
  860. // layout.notice("error", {x: "right", y:"top"}, e.message, this.designNode);
  861. // }
  862. // MWF.getJSON(COMMON.contentPath+"/res/js/testform.json", {
  863. // "onSuccess": function(obj){
  864. // this.form = new MWF.FCForm(this);
  865. // this.form.load(obj);
  866. // }.bind(this),
  867. // "onerror": function(text){
  868. // layout.notice("error", {x: "right", y:"top"}, text, this.designNode);
  869. // }.bind(this),
  870. // "onRequestFailure": function(xhr){
  871. // layout.notice("error", {x: "right", y:"top"}, xhr.responseText, this.designNode);
  872. // }
  873. // });
  874. },
  875. getFormData: function(callback){
  876. if (!this.options.id){
  877. if (this.options.templateId){
  878. this.loadNewFormDataFormTemplate(callback);
  879. }else{
  880. this.loadNewFormData(callback);
  881. }
  882. }else{
  883. this.loadFormData(callback);
  884. }
  885. },
  886. loadNewFormData: function(callback){
  887. var url = "/x_component_cms_FormDesigner/Module/Form/template/"+this.options.template;
  888. //MWF.getJSON("/x_component_process_FormDesigner/Module/Form/template.json", {
  889. MWF.getJSON(url, {
  890. "onSuccess": function(obj){
  891. this.formData = obj.pcData;
  892. this.formData.id="";
  893. this.formData.isNewForm = true;
  894. this.formMobileData = obj.mobileData;
  895. this.formMobileData.id="";
  896. this.formMobileData.isNewForm = true;
  897. if (callback) callback();
  898. }.bind(this),
  899. "onerror": function(text){
  900. this.notice(text, "error");
  901. }.bind(this),
  902. "onRequestFailure": function(xhr){
  903. this.notice(xhr.responseText, "error");
  904. }.bind(this)
  905. });
  906. },
  907. loadNewFormDataFormTemplate: function(callback){
  908. this.actions.getFormTemplate(this.options.templateId, function(form){
  909. if (form){
  910. this.formData = JSON.decode(MWF.decodeJsonString(form.data.data));
  911. this.formData.isNewForm = true;
  912. this.formData.json.id = "";
  913. if (form.data.mobileData){
  914. this.formMobileData = JSON.decode(MWF.decodeJsonString(form.data.mobileData));
  915. this.formMobileData.isNewForm = true;
  916. this.formMobileData.json.id = "";
  917. }else{
  918. this.formMobileData = Object.clone(this.formData);
  919. }
  920. if (callback) callback();
  921. //this.actions.getFormCategory(this.formData.json.formCategory, function(category){
  922. // this.category = {"data": {"name": category.data.name, "id": category.data.id}};
  923. // if (callback) callback();
  924. //}.bind(this));
  925. }
  926. }.bind(this));
  927. },
  928. loadFormData: function(callback){
  929. this.actions.getForm(this.options.id, function(form){
  930. if (form){
  931. this.formData = JSON.decode(MWF.decodeJsonString(form.data.data));
  932. this.formData.isNewForm = false;
  933. this.formData.json.id = form.data.id;
  934. if (form.data.mobileData){
  935. this.formMobileData = JSON.decode(MWF.decodeJsonString(form.data.mobileData));
  936. this.formMobileData.isNewForm = false;
  937. this.formMobileData.json.id = form.data.id;
  938. }else{
  939. this.formMobileData = Object.clone(this.formData);
  940. }
  941. this.setTitle(this.options.appTitle + "-"+this.formData.json.name);
  942. this.taskitem.setText(this.options.appTitle + "-"+this.formData.json.name);
  943. this.options.appTitle = this.options.appTitle + "-"+this.formData.json.name;
  944. if (!this.application){
  945. this.actions.getColumn({id : form.data.appId}, function(json){
  946. this.application = {"name": json.data.appName, "id": json.data.id};
  947. if (callback) callback();
  948. }.bind(this));
  949. }else{
  950. if (callback) callback();
  951. }
  952. //this.actions.getFormCategory(this.formData.json.formCategory, function(category){
  953. // this.category = {"data": {"name": category.data.name, "id": category.data.id}};
  954. // if (callback) callback();
  955. //}.bind(this));
  956. }
  957. }.bind(this));
  958. },
  959. getFieldList: function(){
  960. //fieldTypes = ["calender", "checkbox", "datagrid", "htmledit", "number", "personfield", "radio", "select", "textarea", "textfield"];
  961. dataTypes = {
  962. "string": ["htmledit", "radio", "select", "textarea", "textfield"],
  963. "person": ["personfield","readerfield"],
  964. "date": ["calender"],
  965. "number": ["number"],
  966. "array": ["checkbox"]
  967. };
  968. fieldList = [];
  969. this.pcForm.moduleList.each(function(moudle){
  970. var key = "";
  971. for (k in dataTypes){
  972. if (dataTypes[k].indexOf(moudle.moduleName.toLowerCase())!=-1){
  973. key = k;
  974. break;
  975. }
  976. }
  977. if (key){
  978. fieldList.push({
  979. "name": moudle.json.id,
  980. "dataType": key
  981. });
  982. }
  983. }.bind(this));
  984. return fieldList;
  985. },
  986. saveForm: function(){
  987. if (!this.isSave){
  988. var pcData, mobileData;
  989. if (this.pcForm){
  990. this.pcForm._getFormData();
  991. pcData = this.pcForm.data;
  992. }
  993. if (this.mobileForm){
  994. this.mobileForm._getFormData();
  995. mobileData = this.mobileForm.data;
  996. }else{
  997. if (this.formMobileData) mobileData = this.formMobileData;
  998. }
  999. this.isSave = true;
  1000. var fieldList = this.getFieldList();
  1001. //this.actions.saveForm(pcData, mobileData, fieldList, function(responseJSON){ modify by cxy
  1002. this.actions.saveForm(pcData, mobileData, function(responseJSON){
  1003. this.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  1004. if (!this.pcForm.json.name) this.pcForm.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  1005. this.pcForm.treeNode.setTitle(this.pcForm.json.id);
  1006. this.pcForm.node.set("id", this.pcForm.json.id);
  1007. if (this.mobileForm){
  1008. if (!this.mobileForm.json.name) this.mobileForm.treeNode.setText("<"+this.mobileForm.json.type+"> "+this.mobileForm.json.id);
  1009. this.mobileForm.treeNode.setTitle(this.mobileForm.json.id);
  1010. this.mobileForm.node.set("id", this.mobileForm.json.id+"_"+this.options.mode);
  1011. }
  1012. var name = this.pcForm.json.name;
  1013. if (this.pcForm.data.isNewForm) this.setTitle(this.options.appTitle + "-"+name);
  1014. this.pcForm.data.isNewForm = false;
  1015. if (this.mobileForm) this.mobileForm.data.isNewForm = false;
  1016. this.options.desktopReload = true;
  1017. this.options.id = this.pcForm.json.id;
  1018. this.isSave = false;
  1019. this.fireAppEvent("postSave"); //add by cxy
  1020. }.bind(this), function(xhr, text, error){
  1021. this.isSave = false;
  1022. var errorText = error+":"+text;
  1023. if (xhr) errorText = xhr.responseText;
  1024. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1025. }.bind(this));
  1026. }else{
  1027. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  1028. }
  1029. //this.form.save(function(){
  1030. //
  1031. // var name = this.form.json.name;
  1032. // if (this.form.data.isNewForm) this.setTitle(this.options.appTitle + "-"+name);
  1033. // this.form.data.isNewForm = false;
  1034. // this.options.desktopReload = true;
  1035. // this.options.id = this.form.json.id;
  1036. //}.bind(this));
  1037. },
  1038. previewForm: function(){
  1039. this.form.preview();
  1040. },
  1041. formExplode: function(){
  1042. this.form.explode();
  1043. },
  1044. recordStatus: function(){
  1045. return {"id": this.options.id};
  1046. },
  1047. onPostClose: function(){
  1048. if (this.pcForm){
  1049. MWF.release(this.pcForm.moduleList);
  1050. MWF.release(this.pcForm.moduleNodeList);
  1051. MWF.release(this.pcForm.moduleContainerNodeList);
  1052. MWF.release(this.pcForm.moduleElementNodeList);
  1053. MWF.release(this.pcForm.moduleComponentNodeList);
  1054. MWF.release(this.pcForm);
  1055. }
  1056. if (this.mobileForm){
  1057. MWF.release(this.mobileForm.moduleList);
  1058. MWF.release(this.mobileForm.moduleNodeList);
  1059. MWF.release(this.mobileForm.moduleContainerNodeList);
  1060. MWF.release(this.mobileForm.moduleElementNodeList);
  1061. MWF.release(this.mobileForm.moduleComponentNodeList);
  1062. MWF.release(this.mobileForm);
  1063. }
  1064. },
  1065. setTemplateFormNode: function(formNode){
  1066. var html = "<table align=\"center\" width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  1067. "<tr><td colSpan=\"2\" style=\"height: 50px; line-height: 60px; text-align: center; font-size: 24px; font-weight: bold\">" +
  1068. this.lp.saveTemplate+"</td></tr>" +
  1069. "<tr><td style=\"height: 40px;\" width=\"80px\">" +this.lp.templateName+"</td><td>"+
  1070. "<input value=\""+this.pcForm.json.name+"\" type=\"text\" style=\"width: 98%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  1071. "<tr><td style=\"height: 40px;\">" +this.lp.templateCategory+"</td><td>"+
  1072. "<select style=\"width: 30%; height: 24px; border: 1px solid #cccccc\"></select>"+
  1073. "<input type=\"text\" style=\"width: 68%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  1074. "<tr><td style=\"height: 40px;\">" +this.lp.templateDescription+"</td><td>"+
  1075. "<textarea type=\"text\" style=\"width: 98%; height: 44px; border: 1px solid #cccccc\">"+this.pcForm.json.description+"</textarea>"+"</td></tr>" +
  1076. "<tr><td colSpan=\"2\" id=\"form_templatePreview\">" +
  1077. "<div style=\"position: relative; width: 180px; height: 180px; margin: 20px auto 0px auto; overflow: hidden\"></div>" +
  1078. "</td></tr>" +
  1079. "</table>";
  1080. formNode.set("html", html);
  1081. var tds = formNode.getElements("td");
  1082. var iconNode = tds[tds.length-1].getFirst();
  1083. var previewNode = this.pcForm.node.clone();
  1084. previewNode.setStyles({
  1085. "transform-origin": "0px 0px",
  1086. "transform": "scale(0.15,0.15)",
  1087. "position": "absolute",
  1088. "top": "0px",
  1089. "left": "0px"
  1090. }).inject(iconNode);
  1091. return iconNode;
  1092. },
  1093. setCategorySelect: function(categorySelect){
  1094. if (categorySelect){
  1095. new Element("option", {"value": "$newCategory","text": this.lp.newCategory}).inject(categorySelect);
  1096. this.actions.listFormTemplateCategory(function(json){
  1097. json.data.each(function(category){
  1098. new Element("option", {"value": category.name,"text": category.name}).inject(categorySelect);
  1099. }.bind(this));
  1100. }.bind(this));
  1101. }
  1102. },
  1103. setTemplateActions: function(markNode, areaNode, formNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1104. var actionAreaNode= new Element("div", {
  1105. "styles": this.css.templateActionNode
  1106. }).inject(formNode);
  1107. var cancelActionNode = new Element("div", {
  1108. "styles": this.css.templateCancelActionNode,
  1109. "text": this.lp.cancel,
  1110. "events":{
  1111. "click": function(){
  1112. markNode.destroy();
  1113. areaNode.destroy();
  1114. }
  1115. }
  1116. }).inject(actionAreaNode);
  1117. var saveActionNode = new Element("div", {
  1118. "styles": this.css.templateSaveActionNode,
  1119. "text": this.lp.save,
  1120. "events":{
  1121. "click": function(){
  1122. this.saveTemplate(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1123. }.bind(this)
  1124. }
  1125. }).inject(actionAreaNode);
  1126. },
  1127. saveTemplate: function(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1128. var pcData, mobileData;
  1129. if (this.pcForm){
  1130. this.pcForm._getFormData();
  1131. pcData = this.pcForm.data;
  1132. }
  1133. if (this.mobileForm){
  1134. this.mobileForm._getFormData();
  1135. mobileData = this.mobileForm.data;
  1136. }
  1137. var name = nameNode.get("value");
  1138. var category = (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory") ? newCategoryNode.get("value") : categorySelect.options[categorySelect.selectedIndex].value;
  1139. var description = descriptionNode.get("value");
  1140. if (!name){
  1141. this.notice(MWF.APPFD.LP.notice["saveTemplate_inputName"], "error", nameNode, {x: "left", y:"top"});
  1142. return false;
  1143. }
  1144. if (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory" && !newCategoryNode.get("value")){
  1145. this.notice(MWF.APPFD.LP.notice["saveTemplate_inputCategory"], "error", categorySelect, {x: "left", y:"top"});
  1146. return false;
  1147. }
  1148. //var tds = formNode.getElements("td");
  1149. //var iconNode = tds[tds.length-1].getFirst();
  1150. var data = {
  1151. "name": name,
  1152. "category": category,
  1153. "description": description,
  1154. "outline": iconNode.get("html")
  1155. };
  1156. this.actions.addFormTemplate(pcData, mobileData, data, function(){
  1157. this.notice(MWF.APPFD.LP.notice["saveTemplate_success"], "ok", null, {x: "left", y:"bottom"});
  1158. markNode.destroy();
  1159. areaNode.destroy();
  1160. }.bind(this), function(xhr, text, error){
  1161. var errorText = error+":"+text;
  1162. if (xhr) errorText = xhr.responseText;
  1163. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1164. });
  1165. },
  1166. createTemplateSaveNode: function(){
  1167. var markNode = new Element("div", {
  1168. "styles": this.css.templateMarkNode,
  1169. "events": {
  1170. "mouseover": function(e){e.stopPropagation();},
  1171. "mouseout": function(e){e.stopPropagation();}
  1172. }
  1173. }).inject(this.content);
  1174. var areaNode = new Element("div", {
  1175. "styles": this.css.templateAreaNode
  1176. }).inject(this.content);
  1177. var createNode = new Element("div", {
  1178. "styles": this.css.templateInfoNode
  1179. }).inject(areaNode);
  1180. var formNode = new Element("div", {
  1181. "styles": this.css.templateFormNode
  1182. }).inject(createNode);
  1183. var iconNode = this.setTemplateFormNode(formNode);
  1184. var nodes = formNode.getElements("input");
  1185. var nameNode = nodes[0];
  1186. var newCategoryNode = nodes[1];
  1187. var descriptionNode = formNode.getElement("textarea");
  1188. var categorySelect = formNode.getElement("select");
  1189. this.setCategorySelect(categorySelect);
  1190. this.setTemplateActions(markNode, areaNode, formNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1191. },
  1192. saveFormAsTemplate: function(){
  1193. if (!this.isSave){
  1194. this.createTemplateSaveNode();
  1195. }else{
  1196. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  1197. }
  1198. }
  1199. });