Main.js 51 KB

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