Main.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  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 = MWF.Actions.get("x_cms_assemble_control"); //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. var className = this.retrieve("toolClass");
  720. designer.form.createModule(className, e);
  721. });
  722. this.tools.push(toolNode);
  723. }.bind(this));
  724. }.bind(this));
  725. },
  726. getTools: function(callback){
  727. if (this.toolsData){
  728. if (callback) callback();
  729. }else{
  730. var toolsDataUrl = this.path+this.options.style+"/tools.json";
  731. var r = new Request.JSON({
  732. url: toolsDataUrl,
  733. secure: false,
  734. async: false,
  735. method: "get",
  736. noCache: true,
  737. onSuccess: function(responseJSON, responseText){
  738. this.toolsData = responseJSON;
  739. if (callback) callback();
  740. }.bind(this),
  741. onError: function(text, error){
  742. this.notice("request tools data error: "+error, "error");
  743. }.bind(this)
  744. });
  745. r.send();
  746. }
  747. },
  748. //resizeNode------------------------------------------------
  749. resizeNodeLeftRight: function(){
  750. var nodeSize = this.node.getSize();
  751. this.toolbarNode.setStyle("height", ""+nodeSize.y+"px");
  752. this.formNode.setStyle("height", ""+nodeSize.y+"px");
  753. this.propertyNode.setStyle("height", ""+nodeSize.y+"px");
  754. //nodeSize = {"x": nodeSize.x, "y": nodeSize.y*0.6};
  755. var formToolbarMarginTop = this.formToolbarNode.getStyle("margin-top").toFloat();
  756. var formToolbarMarginBottom = this.formToolbarNode.getStyle("margin-bottom").toFloat();
  757. var allFormToolberSize = this.formToolbarNode.getComputedSize();
  758. var y = nodeSize.y - allFormToolberSize.totalHeight - formToolbarMarginTop - formToolbarMarginBottom;
  759. this.formContentNode.setStyle("height", ""+y+"px");
  760. if (this.designNode){
  761. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  762. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  763. y = nodeSize.y - allFormToolberSize.totalHeight - formToolbarMarginTop - formToolbarMarginBottom - designMarginTop - designMarginBottom;
  764. this.designNode.setStyle("height", ""+y+"px");
  765. }
  766. var titleSize = this.toolbarTitleNode.getSize();
  767. var titleMarginTop = this.toolbarTitleNode.getStyle("margin-top").toFloat();
  768. var titleMarginBottom = this.toolbarTitleNode.getStyle("margin-bottom").toFloat();
  769. var titlePaddingTop = this.toolbarTitleNode.getStyle("padding-top").toFloat();
  770. var titlePaddingBottom = this.toolbarTitleNode.getStyle("padding-bottom").toFloat();
  771. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  772. y = nodeSize.y-y;
  773. this.toolbarContentNode.setStyle("height", ""+y+"px");
  774. titleSize = this.propertyTitleNode.getSize();
  775. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  776. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  777. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  778. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  779. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  780. y = nodeSize.y-y;
  781. this.propertyContentNode.setStyle("height", ""+y+"px");
  782. this.propertyResizeBar.setStyle("height", ""+y+"px");
  783. },
  784. resizeNodeTopBottom: function(percent){
  785. var nodeSize = this.node.getSize();
  786. this.toolbarNode.setStyle("height", ""+nodeSize.y+"px");
  787. var percentNumber = percent || 0.6;
  788. var designerHeight = nodeSize.y*percentNumber;
  789. var propertyHeight = nodeSize.y - designerHeight;
  790. this.formNode.setStyle("height", ""+designerHeight+"px");
  791. this.propertyNode.setStyle("height", ""+propertyHeight+"px");
  792. var formToolbarMarginTop = this.formToolbarNode.getStyle("margin-top").toFloat();
  793. var formToolbarMarginBottom = this.formToolbarNode.getStyle("margin-bottom").toFloat();
  794. var allFormToolberSize = this.formToolbarNode.getComputedSize();
  795. var y = designerHeight - allFormToolberSize.totalHeight - formToolbarMarginTop - formToolbarMarginBottom;
  796. // this.formContentNode.setStyle("height", ""+designerHeight+"px");
  797. if (this.designNode){
  798. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  799. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  800. y = designerHeight - allFormToolberSize.totalHeight - formToolbarMarginTop - formToolbarMarginBottom - designMarginTop - designMarginBottom;
  801. this.designNode.setStyle("height", ""+y+"px");
  802. }
  803. var titleSize = this.toolbarTitleNode.getSize();
  804. var titleMarginTop = this.toolbarTitleNode.getStyle("margin-top").toFloat();
  805. var titleMarginBottom = this.toolbarTitleNode.getStyle("margin-bottom").toFloat();
  806. var titlePaddingTop = this.toolbarTitleNode.getStyle("padding-top").toFloat();
  807. var titlePaddingBottom = this.toolbarTitleNode.getStyle("padding-bottom").toFloat();
  808. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  809. y = nodeSize.y-y;
  810. this.toolbarContentNode.setStyle("height", ""+y+"px");
  811. titleSize = this.propertyTitleNode.getSize();
  812. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  813. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  814. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  815. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  816. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  817. y = propertyHeight-y;
  818. this.propertyContentNode.setStyle("height", ""+y+"px");
  819. this.propertyResizeBar.setStyle("height", ""+y+"px");
  820. this.propertyDomContentArea.setStyle("height", ""+y+"px");
  821. this.propertyDomScrollArea.setStyle("height", ""+y+"px");
  822. this.propertyContentResizeNode.setStyle("height", ""+y+"px");
  823. this.propertyContentArea.setStyle("height", ""+y+"px");
  824. if (this.form){
  825. if (this.form.currentSelectedModule){
  826. if (this.form.currentSelectedModule.property){
  827. var tab = this.form.currentSelectedModule.property.propertyTab;
  828. if (tab){
  829. var tabTitleSize = tab.tabNodeContainer.getSize();
  830. tab.pages.each(function(page){
  831. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  832. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  833. var tabContentNodeAreaHeight = y - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  834. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  835. }.bind(this));
  836. }
  837. }
  838. }
  839. }
  840. },
  841. resizeNode: function(percent){
  842. if (this.options.style=="bottom"){
  843. this.resizeNodeTopBottom(percent);
  844. this.setPropertyContentResizeBottom();
  845. }else{
  846. this.resizeNodeLeftRight(percent);
  847. this.setPropertyContentResize();
  848. }
  849. },
  850. //loadForm------------------------------------------
  851. loadForm: function(){
  852. // try{
  853. this.getFormData(function(){
  854. this.pcForm = new MWF.CMSFCForm(this, this.designNode);
  855. this.pcForm.load(this.formData);
  856. this.form = this.pcForm;
  857. }.bind(this));
  858. // }catch(e){
  859. // layout.notice("error", {x: "right", y:"top"}, e.message, this.designNode);
  860. // }
  861. // MWF.getJSON(COMMON.contentPath+"/res/js/testform.json", {
  862. // "onSuccess": function(obj){
  863. // this.form = new MWF.FCForm(this);
  864. // this.form.load(obj);
  865. // }.bind(this),
  866. // "onerror": function(text){
  867. // layout.notice("error", {x: "right", y:"top"}, text, this.designNode);
  868. // }.bind(this),
  869. // "onRequestFailure": function(xhr){
  870. // layout.notice("error", {x: "right", y:"top"}, xhr.responseText, this.designNode);
  871. // }
  872. // });
  873. },
  874. getFormData: function(callback){
  875. if (!this.options.id){
  876. if (this.options.templateId){
  877. this.loadNewFormDataFormTemplate(callback);
  878. }else{
  879. this.loadNewFormData(callback);
  880. }
  881. }else{
  882. this.loadFormData(callback);
  883. }
  884. },
  885. loadNewFormData: function(callback){
  886. var url = "/x_component_cms_FormDesigner/Module/Form/template/"+this.options.template;
  887. //MWF.getJSON("/x_component_process_FormDesigner/Module/Form/template.json", {
  888. MWF.getJSON(url, {
  889. "onSuccess": function(obj){
  890. this.formData = obj.pcData;
  891. this.formData.id="";
  892. this.formData.isNewForm = true;
  893. this.formMobileData = obj.mobileData;
  894. this.formMobileData.id="";
  895. this.formMobileData.isNewForm = true;
  896. if (callback) callback();
  897. }.bind(this),
  898. "onerror": function(text){
  899. this.notice(text, "error");
  900. }.bind(this),
  901. "onRequestFailure": function(xhr){
  902. this.notice(xhr.responseText, "error");
  903. }.bind(this)
  904. });
  905. },
  906. loadNewFormDataFormTemplate: function(callback){
  907. this.actions.getFormTemplate(this.options.templateId, function(form){
  908. if (form){
  909. this.formData = JSON.decode(MWF.decodeJsonString(form.data.data));
  910. this.formData.isNewForm = true;
  911. this.formData.json.id = "";
  912. if (form.data.mobileData){
  913. this.formMobileData = JSON.decode(MWF.decodeJsonString(form.data.mobileData));
  914. this.formMobileData.isNewForm = true;
  915. this.formMobileData.json.id = "";
  916. }else{
  917. this.formMobileData = Object.clone(this.formData);
  918. }
  919. if (callback) callback();
  920. //this.actions.getFormCategory(this.formData.json.formCategory, function(category){
  921. // this.category = {"data": {"name": category.data.name, "id": category.data.id}};
  922. // if (callback) callback();
  923. //}.bind(this));
  924. }
  925. }.bind(this));
  926. },
  927. loadFormData: function(callback){
  928. this.actions.getForm(this.options.id, function(form){
  929. if (form){
  930. this.formData = JSON.decode(MWF.decodeJsonString(form.data.data));
  931. this.formData.isNewForm = false;
  932. this.formData.json.id = form.data.id;
  933. if (form.data.mobileData){
  934. this.formMobileData = JSON.decode(MWF.decodeJsonString(form.data.mobileData));
  935. this.formMobileData.isNewForm = false;
  936. this.formMobileData.json.id = form.data.id;
  937. }else{
  938. this.formMobileData = Object.clone(this.formData);
  939. }
  940. this.setTitle(this.options.appTitle + "-"+this.formData.json.name);
  941. this.taskitem.setText(this.options.appTitle + "-"+this.formData.json.name);
  942. this.options.appTitle = this.options.appTitle + "-"+this.formData.json.name;
  943. if (!this.application){
  944. this.actions.getColumn(form.data.appId, function(json){
  945. this.application = {"name": json.data.appName, "id": json.data.id};
  946. if (callback) callback();
  947. }.bind(this));
  948. }else{
  949. if (callback) callback();
  950. }
  951. //this.actions.getFormCategory(this.formData.json.formCategory, function(category){
  952. // this.category = {"data": {"name": category.data.name, "id": category.data.id}};
  953. // if (callback) callback();
  954. //}.bind(this));
  955. }
  956. }.bind(this));
  957. },
  958. getFieldList: function(){
  959. //fieldTypes = ["calender", "checkbox", "datagrid", "htmledit", "number", "personfield", "radio", "select", "textarea", "textfield"];
  960. dataTypes = {
  961. "string": ["htmledit", "radio", "select", "textarea", "textfield"],
  962. "person": ["personfield","readerfield","authorfield"],
  963. "date": ["calender"],
  964. "number": ["number"],
  965. "array": ["checkbox"]
  966. };
  967. fieldList = [];
  968. this.pcForm.moduleList.each(function(moudle){
  969. var key = "";
  970. for (k in dataTypes){
  971. if (dataTypes[k].indexOf(moudle.moduleName.toLowerCase())!=-1){
  972. key = k;
  973. break;
  974. }
  975. }
  976. if (key){
  977. fieldList.push({
  978. "name": moudle.json.id,
  979. "dataType": key
  980. });
  981. }
  982. }.bind(this));
  983. return fieldList;
  984. },
  985. saveForm: function(){
  986. if (!this.isSave){
  987. var pcData, mobileData;
  988. if (this.pcForm){
  989. this.pcForm._getFormData();
  990. pcData = this.pcForm.data;
  991. }
  992. if (this.mobileForm){
  993. this.mobileForm._getFormData();
  994. mobileData = this.mobileForm.data;
  995. }else{
  996. if (this.formMobileData) mobileData = this.formMobileData;
  997. }
  998. this.isSave = true;
  999. var fieldList = this.getFieldList();
  1000. //this.actions.saveForm(pcData, mobileData, fieldList, function(responseJSON){ modify by cxy
  1001. this.actions.saveForm(pcData, mobileData, fieldList, function(responseJSON){
  1002. this.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  1003. if (!this.pcForm.json.name) this.pcForm.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  1004. this.pcForm.treeNode.setTitle(this.pcForm.json.id);
  1005. this.pcForm.node.set("id", this.pcForm.json.id);
  1006. if (this.mobileForm){
  1007. if (!this.mobileForm.json.name) this.mobileForm.treeNode.setText("<"+this.mobileForm.json.type+"> "+this.mobileForm.json.id);
  1008. this.mobileForm.treeNode.setTitle(this.mobileForm.json.id);
  1009. this.mobileForm.node.set("id", this.mobileForm.json.id+"_"+this.options.mode);
  1010. }
  1011. var name = this.pcForm.json.name;
  1012. if (this.pcForm.data.isNewForm) this.setTitle(this.options.appTitle + "-"+name);
  1013. this.pcForm.data.isNewForm = false;
  1014. if (this.mobileForm) this.mobileForm.data.isNewForm = false;
  1015. this.options.desktopReload = true;
  1016. this.options.id = this.pcForm.json.id;
  1017. this.isSave = false;
  1018. this.fireAppEvent("postSave"); //add by cxy
  1019. }.bind(this), function(xhr, text, error){
  1020. this.isSave = false;
  1021. var errorText = error+":"+text;
  1022. if (xhr) errorText = xhr.responseText;
  1023. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1024. }.bind(this));
  1025. }else{
  1026. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  1027. }
  1028. //this.form.save(function(){
  1029. //
  1030. // var name = this.form.json.name;
  1031. // if (this.form.data.isNewForm) this.setTitle(this.options.appTitle + "-"+name);
  1032. // this.form.data.isNewForm = false;
  1033. // this.options.desktopReload = true;
  1034. // this.options.id = this.form.json.id;
  1035. //}.bind(this));
  1036. },
  1037. previewForm: function(){
  1038. this.form.preview();
  1039. },
  1040. formExplode: function(){
  1041. this.form.explode();
  1042. },
  1043. recordStatus: function(){
  1044. return {"id": this.options.id};
  1045. },
  1046. onPostClose: function(){
  1047. if (this.pcForm){
  1048. MWF.release(this.pcForm.moduleList);
  1049. MWF.release(this.pcForm.moduleNodeList);
  1050. MWF.release(this.pcForm.moduleContainerNodeList);
  1051. MWF.release(this.pcForm.moduleElementNodeList);
  1052. MWF.release(this.pcForm.moduleComponentNodeList);
  1053. MWF.release(this.pcForm);
  1054. }
  1055. if (this.mobileForm){
  1056. MWF.release(this.mobileForm.moduleList);
  1057. MWF.release(this.mobileForm.moduleNodeList);
  1058. MWF.release(this.mobileForm.moduleContainerNodeList);
  1059. MWF.release(this.mobileForm.moduleElementNodeList);
  1060. MWF.release(this.mobileForm.moduleComponentNodeList);
  1061. MWF.release(this.mobileForm);
  1062. }
  1063. },
  1064. setTemplateFormNode: function(formNode){
  1065. var html = "<table align=\"center\" width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  1066. "<tr><td colSpan=\"2\" style=\"height: 50px; line-height: 60px; text-align: center; font-size: 24px; font-weight: bold\">" +
  1067. this.lp.saveTemplate+"</td></tr>" +
  1068. "<tr><td style=\"height: 40px;\" width=\"80px\">" +this.lp.templateName+"</td><td>"+
  1069. "<input value=\""+this.pcForm.json.name+"\" type=\"text\" style=\"width: 98%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  1070. "<tr><td style=\"height: 40px;\">" +this.lp.templateCategory+"</td><td>"+
  1071. "<select style=\"width: 30%; height: 24px; border: 1px solid #cccccc\"></select>"+
  1072. "<input type=\"text\" style=\"width: 68%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  1073. "<tr><td style=\"height: 40px;\">" +this.lp.templateDescription+"</td><td>"+
  1074. "<textarea type=\"text\" style=\"width: 98%; height: 44px; border: 1px solid #cccccc\">"+this.pcForm.json.description+"</textarea>"+"</td></tr>" +
  1075. "<tr><td colSpan=\"2\" id=\"form_templatePreview\">" +
  1076. "<div style=\"position: relative; width: 180px; height: 180px; margin: 20px auto 0px auto; overflow: hidden\"></div>" +
  1077. "</td></tr>" +
  1078. "</table>";
  1079. formNode.set("html", html);
  1080. var tds = formNode.getElements("td");
  1081. var iconNode = tds[tds.length-1].getFirst();
  1082. var previewNode = this.pcForm.node.clone();
  1083. previewNode.setStyles({
  1084. "transform-origin": "0px 0px",
  1085. "transform": "scale(0.15,0.15)",
  1086. "position": "absolute",
  1087. "top": "0px",
  1088. "left": "0px"
  1089. }).inject(iconNode);
  1090. return iconNode;
  1091. },
  1092. setCategorySelect: function(categorySelect){
  1093. if (categorySelect){
  1094. new Element("option", {"value": "$newCategory","text": this.lp.newCategory}).inject(categorySelect);
  1095. this.actions.listFormTemplateCategory(function(json){
  1096. json.data.each(function(category){
  1097. new Element("option", {"value": category.name,"text": category.name}).inject(categorySelect);
  1098. }.bind(this));
  1099. }.bind(this));
  1100. }
  1101. },
  1102. setTemplateActions: function(markNode, areaNode, formNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1103. var actionAreaNode= new Element("div", {
  1104. "styles": this.css.templateActionNode
  1105. }).inject(formNode);
  1106. var cancelActionNode = new Element("div", {
  1107. "styles": this.css.templateCancelActionNode,
  1108. "text": this.lp.cancel,
  1109. "events":{
  1110. "click": function(){
  1111. markNode.destroy();
  1112. areaNode.destroy();
  1113. }
  1114. }
  1115. }).inject(actionAreaNode);
  1116. var saveActionNode = new Element("div", {
  1117. "styles": this.css.templateSaveActionNode,
  1118. "text": this.lp.save,
  1119. "events":{
  1120. "click": function(){
  1121. this.saveTemplate(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1122. }.bind(this)
  1123. }
  1124. }).inject(actionAreaNode);
  1125. },
  1126. saveTemplate: function(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1127. var pcData, mobileData;
  1128. if (this.pcForm){
  1129. this.pcForm._getFormData();
  1130. pcData = this.pcForm.data;
  1131. }
  1132. if (this.mobileForm){
  1133. this.mobileForm._getFormData();
  1134. mobileData = this.mobileForm.data;
  1135. }
  1136. var name = nameNode.get("value");
  1137. var category = (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory") ? newCategoryNode.get("value") : categorySelect.options[categorySelect.selectedIndex].value;
  1138. var description = descriptionNode.get("value");
  1139. if (!name){
  1140. this.notice(MWF.APPFD.LP.notice["saveTemplate_inputName"], "error", nameNode, {x: "left", y:"top"});
  1141. return false;
  1142. }
  1143. if (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory" && !newCategoryNode.get("value")){
  1144. this.notice(MWF.APPFD.LP.notice["saveTemplate_inputCategory"], "error", categorySelect, {x: "left", y:"top"});
  1145. return false;
  1146. }
  1147. //var tds = formNode.getElements("td");
  1148. //var iconNode = tds[tds.length-1].getFirst();
  1149. var data = {
  1150. "name": name,
  1151. "category": category,
  1152. "description": description,
  1153. "outline": iconNode.get("html")
  1154. };
  1155. this.actions.addFormTemplate(pcData, mobileData, data, function(){
  1156. this.notice(MWF.APPFD.LP.notice["saveTemplate_success"], "ok", null, {x: "left", y:"bottom"});
  1157. markNode.destroy();
  1158. areaNode.destroy();
  1159. }.bind(this), function(xhr, text, error){
  1160. var errorText = error+":"+text;
  1161. if (xhr) errorText = xhr.responseText;
  1162. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1163. });
  1164. },
  1165. createTemplateSaveNode: function(){
  1166. var markNode = new Element("div", {
  1167. "styles": this.css.templateMarkNode,
  1168. "events": {
  1169. "mouseover": function(e){e.stopPropagation();},
  1170. "mouseout": function(e){e.stopPropagation();}
  1171. }
  1172. }).inject(this.content);
  1173. var areaNode = new Element("div", {
  1174. "styles": this.css.templateAreaNode
  1175. }).inject(this.content);
  1176. var createNode = new Element("div", {
  1177. "styles": this.css.templateInfoNode
  1178. }).inject(areaNode);
  1179. var formNode = new Element("div", {
  1180. "styles": this.css.templateFormNode
  1181. }).inject(createNode);
  1182. var iconNode = this.setTemplateFormNode(formNode);
  1183. var nodes = formNode.getElements("input");
  1184. var nameNode = nodes[0];
  1185. var newCategoryNode = nodes[1];
  1186. var descriptionNode = formNode.getElement("textarea");
  1187. var categorySelect = formNode.getElement("select");
  1188. this.setCategorySelect(categorySelect);
  1189. this.setTemplateActions(markNode, areaNode, formNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1190. },
  1191. saveFormAsTemplate: function(){
  1192. if (!this.isSave){
  1193. this.createTemplateSaveNode();
  1194. }else{
  1195. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  1196. }
  1197. }
  1198. });