Main.js 42 KB

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