Main.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370
  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. }else{
  995. if (this.formMobileData) mobileData = this.formMobileData;
  996. }
  997. this.isSave = true;
  998. var fieldList = this.getFieldList();
  999. this.actions.saveForm(pcData, mobileData, fieldList, function(responseJSON){
  1000. this.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  1001. if (!this.pcForm.json.name) this.pcForm.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  1002. this.pcForm.treeNode.setTitle(this.pcForm.json.id);
  1003. this.pcForm.node.set("id", this.pcForm.json.id);
  1004. if (this.mobileForm){
  1005. if (!this.mobileForm.json.name) this.mobileForm.treeNode.setText("<"+this.mobileForm.json.type+"> "+this.mobileForm.json.id);
  1006. this.mobileForm.treeNode.setTitle(this.mobileForm.json.id);
  1007. this.mobileForm.node.set("id", this.mobileForm.json.id+"_"+this.options.mode);
  1008. }
  1009. var name = this.pcForm.json.name;
  1010. if (this.pcForm.data.isNewForm) this.setTitle(this.options.appTitle + "-"+name);
  1011. this.pcForm.data.isNewForm = false;
  1012. if (this.mobileForm) this.mobileForm.data.isNewForm = false;
  1013. this.options.desktopReload = true;
  1014. this.options.id = this.pcForm.json.id;
  1015. this.isSave = false;
  1016. }.bind(this), function(xhr, text, error){
  1017. this.isSave = false;
  1018. var errorText = error+":"+text;
  1019. if (xhr) errorText = xhr.responseText;
  1020. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1021. }.bind(this));
  1022. }else{
  1023. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  1024. }
  1025. //this.form.save(function(){
  1026. //
  1027. // var name = this.form.json.name;
  1028. // if (this.form.data.isNewForm) this.setTitle(this.options.appTitle + "-"+name);
  1029. // this.form.data.isNewForm = false;
  1030. // this.options.desktopReload = true;
  1031. // this.options.id = this.form.json.id;
  1032. //}.bind(this));
  1033. },
  1034. previewForm: function(){
  1035. this.form.preview();
  1036. },
  1037. formExplode: function(){
  1038. this.form.explode();
  1039. },
  1040. recordStatus: function(){
  1041. return {"id": this.options.id};
  1042. },
  1043. onPostClose: function(){
  1044. if (this.pcForm){
  1045. MWF.release(this.pcForm.moduleList);
  1046. MWF.release(this.pcForm.moduleNodeList);
  1047. MWF.release(this.pcForm.moduleContainerNodeList);
  1048. MWF.release(this.pcForm.moduleElementNodeList);
  1049. MWF.release(this.pcForm.moduleComponentNodeList);
  1050. MWF.release(this.pcForm);
  1051. }
  1052. if (this.mobileForm){
  1053. MWF.release(this.mobileForm.moduleList);
  1054. MWF.release(this.mobileForm.moduleNodeList);
  1055. MWF.release(this.mobileForm.moduleContainerNodeList);
  1056. MWF.release(this.mobileForm.moduleElementNodeList);
  1057. MWF.release(this.mobileForm.moduleComponentNodeList);
  1058. MWF.release(this.mobileForm);
  1059. }
  1060. },
  1061. setTemplateFormNode: function(formNode){
  1062. var html = "<table align=\"center\" width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  1063. "<tr><td colSpan=\"2\" style=\"height: 50px; line-height: 60px; text-align: center; font-size: 24px; font-weight: bold\">" +
  1064. this.lp.saveTemplate+"</td></tr>" +
  1065. "<tr><td style=\"height: 40px;\" width=\"80px\">" +this.lp.templateName+"</td><td>"+
  1066. "<input value=\""+this.pcForm.json.name+"\" type=\"text\" style=\"width: 98%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  1067. "<tr><td style=\"height: 40px;\">" +this.lp.templateCategory+"</td><td>"+
  1068. "<select style=\"width: 30%; height: 24px; border: 1px solid #cccccc\"></select>"+
  1069. "<input type=\"text\" style=\"width: 68%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  1070. "<tr><td style=\"height: 40px;\">" +this.lp.templateDescription+"</td><td>"+
  1071. "<textarea type=\"text\" style=\"width: 98%; height: 44px; border: 1px solid #cccccc\">"+this.pcForm.json.description+"</textarea>"+"</td></tr>" +
  1072. "<tr><td colSpan=\"2\" id=\"form_templatePreview\">" +
  1073. "<div style=\"position: relative; width: 180px; height: 180px; margin: 20px auto 0px auto; overflow: hidden\"></div>" +
  1074. "</td></tr>" +
  1075. "</table>";
  1076. formNode.set("html", html);
  1077. var tds = formNode.getElements("td");
  1078. var iconNode = tds[tds.length-1].getFirst();
  1079. var previewNode = this.pcForm.node.clone();
  1080. previewNode.setStyles({
  1081. "transform-origin": "0px 0px",
  1082. "transform": "scale(0.15,0.15)",
  1083. "position": "absolute",
  1084. "top": "0px",
  1085. "left": "0px"
  1086. }).inject(iconNode);
  1087. return iconNode;
  1088. },
  1089. setCategorySelect: function(categorySelect){
  1090. if (categorySelect){
  1091. new Element("option", {"value": "$newCategory","text": this.lp.newCategory}).inject(categorySelect);
  1092. this.actions.listFormTemplateCategory(function(json){
  1093. json.data.each(function(category){
  1094. new Element("option", {"value": category.name,"text": category.name}).inject(categorySelect);
  1095. }.bind(this));
  1096. }.bind(this));
  1097. }
  1098. },
  1099. setTemplateActions: function(markNode, areaNode, formNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1100. var actionAreaNode= new Element("div", {
  1101. "styles": this.css.templateActionNode
  1102. }).inject(formNode);
  1103. var cancelActionNode = new Element("div", {
  1104. "styles": this.css.templateCancelActionNode,
  1105. "text": this.lp.cancel,
  1106. "events":{
  1107. "click": function(){
  1108. markNode.destroy();
  1109. areaNode.destroy();
  1110. }
  1111. }
  1112. }).inject(actionAreaNode);
  1113. var saveActionNode = new Element("div", {
  1114. "styles": this.css.templateSaveActionNode,
  1115. "text": this.lp.save,
  1116. "events":{
  1117. "click": function(){
  1118. this.saveTemplate(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1119. }.bind(this)
  1120. }
  1121. }).inject(actionAreaNode);
  1122. },
  1123. saveTemplate: function(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1124. var pcData, mobileData;
  1125. if (this.pcForm){
  1126. this.pcForm._getFormData();
  1127. pcData = this.pcForm.data;
  1128. }
  1129. if (this.mobileForm){
  1130. this.mobileForm._getFormData();
  1131. mobileData = this.mobileForm.data;
  1132. }
  1133. var name = nameNode.get("value");
  1134. var category = (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory") ? newCategoryNode.get("value") : categorySelect.options[categorySelect.selectedIndex].value;
  1135. var description = descriptionNode.get("value");
  1136. if (!name){
  1137. this.notice(MWF.APPFD.LP.notice["saveTemplate_inputName"], "error", nameNode, {x: "left", y:"top"});
  1138. return false;
  1139. }
  1140. if (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory" && !newCategoryNode.get("value")){
  1141. this.notice(MWF.APPFD.LP.notice["saveTemplate_inputCategory"], "error", categorySelect, {x: "left", y:"top"});
  1142. return false;
  1143. }
  1144. //var tds = formNode.getElements("td");
  1145. //var iconNode = tds[tds.length-1].getFirst();
  1146. var data = {
  1147. "name": name,
  1148. "category": category,
  1149. "description": description,
  1150. "outline": iconNode.get("html")
  1151. };
  1152. this.actions.addFormTemplate(pcData, mobileData, data, function(){
  1153. this.notice(MWF.APPFD.LP.notice["saveTemplate_success"], "ok", null, {x: "left", y:"bottom"});
  1154. markNode.destroy();
  1155. areaNode.destroy();
  1156. }.bind(this), function(xhr, text, error){
  1157. var errorText = error+":"+text;
  1158. if (xhr) errorText = xhr.responseText;
  1159. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1160. });
  1161. },
  1162. createTemplateSaveNode: function(){
  1163. var markNode = new Element("div", {
  1164. "styles": this.css.templateMarkNode,
  1165. "events": {
  1166. "mouseover": function(e){e.stopPropagation();},
  1167. "mouseout": function(e){e.stopPropagation();}
  1168. }
  1169. }).inject(this.content);
  1170. var areaNode = new Element("div", {
  1171. "styles": this.css.templateAreaNode
  1172. }).inject(this.content);
  1173. var createNode = new Element("div", {
  1174. "styles": this.css.templateInfoNode
  1175. }).inject(areaNode);
  1176. var formNode = new Element("div", {
  1177. "styles": this.css.templateFormNode
  1178. }).inject(createNode);
  1179. var iconNode = this.setTemplateFormNode(formNode);
  1180. var nodes = formNode.getElements("input");
  1181. var nameNode = nodes[0];
  1182. var newCategoryNode = nodes[1];
  1183. var descriptionNode = formNode.getElement("textarea");
  1184. var categorySelect = formNode.getElement("select");
  1185. this.setCategorySelect(categorySelect);
  1186. this.setTemplateActions(markNode, areaNode, formNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1187. },
  1188. saveFormAsTemplate: function(){
  1189. if (!this.isSave){
  1190. this.createTemplateSaveNode();
  1191. }else{
  1192. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  1193. }
  1194. }
  1195. });