Main.js 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795
  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": "form_classical.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 = MWF.Actions.get("x_processplatform_assemble_designer");
  34. //this.actions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  35. this.lp = MWF.xApplication.process.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.node.contains(document.activeElement)) return false;
  90. if (this.form.currentSelectedModule) {
  91. var module = this.form.currentSelectedModule;
  92. if (module.moduleType != "form" && module.moduleName.indexOf("$") == -1) {
  93. debugger;
  94. this.form.fireEvent("queryGetFormData", [module.node]);
  95. var html = module.getHtml();
  96. var json = module.getJson();
  97. this.form.fireEvent("postGetFormData", [module.node]);
  98. MWF.clipboard.data = {
  99. "type": "form",
  100. "data": {
  101. "html": html,
  102. "json": json
  103. }
  104. };
  105. } else {
  106. MWF.clipboard.data = null;
  107. }
  108. }
  109. // }
  110. }
  111. }
  112. },
  113. cutModule: function(){
  114. if (this.shortcut) {
  115. if (this.form) {
  116. // if (this.form.isFocus){
  117. if (!this.form.node.contains(document.activeElement)) return false;
  118. if (this.form.currentSelectedModule) {
  119. var module = this.form.currentSelectedModule;
  120. if (module.moduleType != "form" && module.moduleName.indexOf("$") == -1) {
  121. this.copyModule();
  122. var _form = module.form;
  123. module.destroy();
  124. _form.currentSelectedModule = null;
  125. _form.selected();
  126. _form = null;
  127. //module.form.selected();
  128. }
  129. }
  130. // }
  131. }
  132. }
  133. },
  134. pasteModule: function(){
  135. if (this.shortcut) {
  136. if (this.form) {
  137. if (!this.form.node.contains(document.activeElement)) return false;
  138. // if (this.form.isFocus){
  139. if (MWF.clipboard.data) {
  140. if (MWF.clipboard.data.type == "form") {
  141. var html = MWF.clipboard.data.data.html;
  142. var json = Object.clone(MWF.clipboard.data.data.json);
  143. var tmpNode = Element("div", {
  144. "styles": {"display": "none"},
  145. "html": html
  146. }).inject(this.content);
  147. //var pid = "";
  148. Object.each(json, function (moduleJson) {
  149. var oid = moduleJson.id;
  150. var id = moduleJson.id;
  151. // if (!pid){
  152. var idx = 1;
  153. while (this.form.json.moduleList[id]) {
  154. id = oid + "_" + idx;
  155. idx++;
  156. }
  157. // pid = id;
  158. // }else{
  159. // idx = 1;
  160. // var id = pid+"_"+moduleJson.moduleName;
  161. // var prefix = pid+"_"+moduleJson.moduleName;
  162. // while (this.form.json.moduleList[id]){
  163. // id = prefix+"_"+idx;
  164. // idx++;
  165. // }
  166. // }
  167. if (oid != id) {
  168. moduleJson.id = id;
  169. var moduleNode = tmpNode.getElementById(oid);
  170. if (moduleNode) moduleNode.set("id", id);
  171. }
  172. this.form.json.moduleList[moduleJson.id] = moduleJson;
  173. }.bind(this));
  174. delete json;
  175. var injectNode = this.form.node;
  176. var where = "bottom";
  177. var parent = this.form;
  178. if (this.form.currentSelectedModule) {
  179. var toModule = this.form.currentSelectedModule;
  180. injectNode = toModule.node;
  181. parent = toModule;
  182. if (toModule.moduleType != "container" && toModule.moduleType != "form") {
  183. where = "after";
  184. parent = toModule.parentContainer;
  185. }
  186. }
  187. var copyModuleNode = tmpNode.getFirst();
  188. while (copyModuleNode) {
  189. copyModuleNode.inject(injectNode, where);
  190. var copyModuleJson = this.form.getDomjson(copyModuleNode);
  191. module = this.form.loadModule(copyModuleJson, copyModuleNode, parent);
  192. module._setEditStyle_custom("id");
  193. module.selected();
  194. //loadModule: function(json, dom, parent)
  195. copyModuleNode = tmpNode.getFirst();
  196. }
  197. tmpNode.destroy();
  198. delete tmpNode;
  199. }
  200. }
  201. // }
  202. }
  203. }
  204. },
  205. createNode: function(){
  206. this.content.setStyle("overflow", "hidden");
  207. this.node = new Element("div", {
  208. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  209. }).inject(this.content);
  210. },
  211. openForm: function(){
  212. this.initOptions();
  213. this.loadNodes();
  214. this.loadToolbar();
  215. this.loadFormNode();
  216. this.loadProperty();
  217. this.loadTools();
  218. this.resizeNode();
  219. this.addEvent("resize", this.resizeNode.bind(this));
  220. this.loadForm();
  221. if (this.toolbarContentNode){
  222. this.setScrollBar(this.toolbarContentNode, null, {
  223. "V": {"x": 0, "y": 0},
  224. "H": {"x": 0, "y": 0}
  225. });
  226. //this.setScrollBar(this.propertyDomScrollArea, "form_property", {
  227. // "V": {"x": 0, "y": 0},
  228. // "H": {"x": 0, "y": 0}
  229. //});
  230. MWF.require("MWF.widget.ScrollBar", function(){
  231. new MWF.widget.ScrollBar(this.propertyDomScrollArea, {
  232. "style":"default", "where": "before", "distance": 30, "friction": 4, "indent": false, "axis": {"x": false, "y": true}
  233. });
  234. }.bind(this));
  235. }
  236. this.checkSidebars();
  237. },
  238. checkSidebars: function(){
  239. this.positionSidebarsFun = this.positionSidebars.bind(this);
  240. this.positionSidebarsId = window.setInterval(this.positionSidebarsFun, 1000);
  241. this.addEvent("queryClose", function(){
  242. if (this.positionSidebarsId){
  243. window.clearInterval(this.positionSidebarsId);
  244. this.positionSidebarsId = "";
  245. }
  246. }.bind(this));
  247. },
  248. positionSidebars: function(){
  249. if (this.pcForm){
  250. this.pcForm.moduleList.each(function(module){
  251. if (module.moduleName === "sidebar") module.position();
  252. }.bind(this));
  253. }
  254. },
  255. initOptions: function(){
  256. this.toolsData = null;
  257. this.toolbarMode = "all";
  258. this.tools = [];
  259. this.toolbarDecrease = 0;
  260. this.designNode = null;
  261. this.form = null;
  262. },
  263. loadNodes: function(){
  264. this.toolbarNode = new Element("div", {
  265. "styles": this.css.toolbarNode,
  266. "events": {"selectstart": function(e){e.preventDefault();}}
  267. }).inject(this.node);
  268. this.propertyNode = new Element("div", {
  269. "styles": this.css.propertyNode
  270. }).inject(this.node)
  271. this.formNode = new Element("div", {
  272. "styles": this.css.formNode
  273. }).inject(this.node);
  274. if (this.options.style=="bottom") this.propertyNode.inject(this.formNode, "after");
  275. },
  276. //loadToolbar----------------------
  277. loadToolbar: function(){
  278. this.toolbarTitleNode = new Element("div", {
  279. "styles": this.css.toolbarTitleNode,
  280. "text": MWF.APPFD.LP.tools
  281. }).inject(this.toolbarNode);
  282. this.toolbarTitleActionNode = new Element("div", {
  283. "styles": this.css.toolbarTitleActionNode,
  284. "events": {
  285. "click": function(e){
  286. this.switchToolbarMode();
  287. }.bind(this)
  288. }
  289. }).inject(this.toolbarNode);
  290. this.toolbarContentNode = new Element("div", {
  291. "styles": this.css.toolbarContentNode,
  292. "events": {
  293. "selectstart": function(e){
  294. e.preventDefault();
  295. e.stopPropagation();
  296. }
  297. }
  298. }).inject(this.toolbarNode);
  299. },
  300. switchToolbarMode: function(){
  301. if (this.toolbarMode=="all"){
  302. var size = this.toolbarNode.getSize();
  303. this.toolbarDecrease = (size.x.toFloat())-60;
  304. this.tools.each(function(node){
  305. node.getLast().setStyle("display", "none");
  306. });
  307. this.toolbarTitleNode.set("text", "");
  308. this.toolbarNode.setStyle("width", "60px");
  309. var formMargin = this.formNode.getStyle("margin-left").toFloat();
  310. formMargin = formMargin - this.toolbarDecrease;
  311. this.formNode.setStyle("margin-left", ""+formMargin+"px");
  312. this.toolbarTitleActionNode.setStyles(this.css.toolbarTitleActionNodeRight);
  313. this.toolbarMode="simple";
  314. }else{
  315. sizeX = 60 + this.toolbarDecrease;
  316. var formMargin = this.formNode.getStyle("margin-left").toFloat();
  317. formMargin = formMargin + this.toolbarDecrease;
  318. this.toolbarNode.setStyle("width", ""+sizeX+"px");
  319. this.formNode.setStyle("margin-left", ""+formMargin+"px");
  320. this.tools.each(function(node){
  321. node.getLast().setStyle("display", "block");
  322. });
  323. this.toolbarTitleNode.set("text", MWF.APPFD.LP.tools);
  324. this.toolbarTitleActionNode.setStyles(this.css.toolbarTitleActionNode);
  325. this.toolbarMode="all";
  326. }
  327. },
  328. //loadFormNode------------------------------
  329. loadFormNode: function(){
  330. this.formToolbarNode = new Element("div", {
  331. "styles": this.css.formToolbarNode
  332. }).inject(this.formNode);
  333. this.loadFormToolbar();
  334. this.formContentNode = new Element("div", {
  335. "styles": this.css.formContentNode
  336. }).inject(this.formNode);
  337. this.loadFormContent(function(){
  338. if (this.designDcoument) this.designDcoument.body.setStyles(this.css.designBody);
  339. if (this.designNode) this.designNode.setStyles(this.css.designNode);
  340. }.bind(this));
  341. },
  342. loaddesignerActionNode: function(){
  343. this.pcDesignerActionNode = this.formToolbarNode.getElement("#MWFFormPCDesignerAction");
  344. this.mobileDesignerActionNode = this.formToolbarNode.getElement("#MWFFormMobileDesignerAction");
  345. this.currentDesignerMode = "PC";
  346. this.pcDesignerActionNode.setStyles(this.css.designerActionNode_current);
  347. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode);
  348. var iconNode = new Element("div", {"styles": this.css.designerActionPcIconNode}).inject(this.pcDesignerActionNode);
  349. iconNode = new Element("div", {"styles": this.css.designerActionMobileIconNode}).inject(this.mobileDesignerActionNode);
  350. var textNode = new Element("div", {"styles": this.css.designerActiontextNode, "text": "PC"}).inject(this.pcDesignerActionNode);
  351. textNode = new Element("div", {"styles": this.css.designerActiontextNode, "text": "Mobile"}).inject(this.mobileDesignerActionNode);
  352. this.pcDesignerActionNode.addEvent("click", function(){
  353. if (this.currentDesignerMode!="PC"){
  354. this.changeDesignerModeToPC();
  355. }
  356. }.bind(this));
  357. this.mobileDesignerActionNode.addEvent("click", function(){
  358. if (this.currentDesignerMode=="PC"){
  359. this.changeDesignerModeToMobile();
  360. }
  361. }.bind(this));
  362. },
  363. changeDesignerModeToPC: function(){
  364. this.pcDesignerActionNode.setStyles(this.css.designerActionNode_current);
  365. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode);
  366. this.designMobileNode.setStyle("display", "none");
  367. this.designNode.setStyle("display", "block");
  368. if (this.form.currentSelectedModule){
  369. if (this.form.currentSelectedModule==this){
  370. return true;
  371. }else{
  372. this.form.currentSelectedModule.unSelected();
  373. }
  374. }
  375. if (this.form.propertyMultiTd){
  376. this.form.propertyMultiTd.hide();
  377. this.form.propertyMultiTd = null;
  378. }
  379. this.form.unSelectedMulti();
  380. if (this.form.designTabPageScriptAreaNode) this.form.designTabPageScriptAreaNode.hide();
  381. this.form = this.pcForm;
  382. if ((this.scriptPage && this.scriptPage.isShow) || this.scriptPanel){
  383. this.loadAllScript();
  384. }
  385. this.currentDesignerMode = "PC";
  386. },
  387. changeDesignerModeToMobile: function(){
  388. this.pcDesignerActionNode.setStyles(this.css.designerActionNode);
  389. this.mobileDesignerActionNode.setStyles(this.css.designerActionNode_current);
  390. this.designMobileNode.setStyle("display", "block");
  391. this.designNode.setStyle("display", "none");
  392. if (this.form.currentSelectedModule){
  393. if (this.form.currentSelectedModule==this){
  394. return true;
  395. }else{
  396. this.form.currentSelectedModule.unSelected();
  397. }
  398. }
  399. if (this.form.propertyMultiTd){
  400. this.form.propertyMultiTd.hide();
  401. this.form.propertyMultiTd = null;
  402. }
  403. this.form.unSelectedMulti();
  404. if (!this.mobileForm){
  405. this.mobileForm = new MWF.FCForm(this, this.designMobileNode, {"mode": "Mobile"});
  406. if (!Object.keys(this.formMobileData.json.moduleList).length){
  407. this.formMobileData = Object.clone(this.formData);
  408. }
  409. this.mobileForm.load(this.formMobileData);
  410. }
  411. if (this.form.designTabPageScriptAreaNode) this.form.designTabPageScriptAreaNode.hide();
  412. this.form = this.mobileForm;
  413. if ((this.scriptPage && this.scriptPage.isShow) || this.scriptPanel){
  414. this.loadAllScript();
  415. }
  416. this.currentDesignerMode = "Mobile";
  417. },
  418. loadFormToolbar: function(callback){
  419. this.getFormToolbarHTML(function(toolbarNode){
  420. var spans = toolbarNode.getElements("span");
  421. spans.each(function(item, idx){
  422. var img = item.get("MWFButtonImage");
  423. if (img){
  424. item.set("MWFButtonImage", this.path+""+this.options.style+"/formtoolbar/"+img);
  425. }
  426. }.bind(this));
  427. $(toolbarNode).inject(this.formToolbarNode);
  428. MWF.require("MWF.widget.Toolbar", function(){
  429. this.formToolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "ProcessCategory"}, this);
  430. this.formToolbar.load();
  431. this.loaddesignerActionNode();
  432. if (callback) callback();
  433. }.bind(this));
  434. }.bind(this));
  435. },
  436. getFormToolbarHTML: function(callback){
  437. var toolbarUrl = this.path+this.options.style+"/formToolbars.html";
  438. var r = new Request.HTML({
  439. url: toolbarUrl,
  440. method: "get",
  441. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  442. var toolbarNode = responseTree[0];
  443. if (callback) callback(toolbarNode);
  444. }.bind(this),
  445. onFailure: function(xhr){
  446. this.notice("request processToolbars error: "+xhr.responseText, "error");
  447. }.bind(this)
  448. });
  449. r.send();
  450. },
  451. loadFormContent: function(callback){
  452. //var iframe = new Element("iframe#iframeaa", {
  453. // "styles": {
  454. // "width": "100%",
  455. // "height": "100%"
  456. // },
  457. // //"src": "../x_component_process_FormDesigner/$Main/blank.html",
  458. // "border": "0"
  459. //}).inject(this.formContentNode);
  460. // window.setTimeout(function(){
  461. // iframe.contentDocument.designMode = "on";
  462. //
  463. //
  464. // var x = document.id("iframeaa");
  465. // this.designNode = document.id(iframe.contentDocument.body, false, iframe.contentDocument);
  466. // this.designNode.setStyle("margin", "0px");
  467. // this.designNode.setStyles(this.css.designNode);
  468. MWF.require("MWF.widget.Tab", null, false);
  469. this.designTabNode = new Element("div").inject(this.formContentNode);
  470. this.designTab = new MWF.widget.Tab(this.designTabNode, {"style": "design"});
  471. this.designTab.load();
  472. this.designTabPageAreaNode = Element("div");
  473. this.designNode = new Element("div", {
  474. "styles": this.css.designNode
  475. }).inject(this.designTabPageAreaNode);
  476. //this.designContentNode = new Element("div", {
  477. // "styles": {"overflow": "visible"}
  478. //}).inject(this.designNode);
  479. //MWF.require("MWF.widget.ScrollBar", function(){
  480. // new MWF.widget.ScrollBar(this.designNode, {"distance": 100});
  481. //}.bind(this));
  482. this.designMobileNode = new Element("div", {
  483. "styles": this.css.designMobileNode
  484. }).inject(this.designTabPageAreaNode);
  485. //MWF.require("MWF.widget.ScrollBar", function(){
  486. // new MWF.widget.ScrollBar(this.designMobileNode, {"distance": 50, "style": "xApp_mobileForm"});
  487. //}.bind(this));
  488. // }.bind(this), 2000);
  489. this.designTabScriptAreaNode = Element("div", {"styles": this.css.designTabScriptAreaNode});
  490. this.designPage = this.designTab.addTab(this.designTabPageAreaNode, this.lp.design);
  491. this.scriptPage = this.designTab.addTab(this.designTabScriptAreaNode, this.lp.script);
  492. this.setScriptPageEvent();
  493. this.designPage.showTabIm();
  494. this.scriptPage.addEvent("postShow", function(){
  495. this.checkLoadAllScript();
  496. this.fireEvent("resize");
  497. }.bind(this));
  498. this.designPage.addEvent("postShow", function(){
  499. this.fireEvent("resize");
  500. }.bind(this));
  501. },
  502. createScriptPanel: function(p, s){
  503. MWF.require("MWF.widget.Panel", function(){
  504. this.scriptPanel = new MWF.widget.Panel(this.designTabScriptAreaNode, {
  505. "title": this.lp.script,
  506. "minLeft": "500",
  507. "minTop": "1",
  508. "style": "page",
  509. "target": this.content,
  510. "limitMove": false,
  511. "isClose": false,
  512. "width": s.x,
  513. "height": s.y,
  514. "top": p.y,
  515. "left": p.x,
  516. "onPostLoad": function(){
  517. this.loadAllScript();
  518. this.fireEvent("resize");
  519. }.bind(this),
  520. "onResize": function(){
  521. this.fireEvent("resize");
  522. }.bind(this),
  523. "onDrag": function(el, e){
  524. if (el.getStyle("top").toInt()<0) el.setStyle("top", "0px");
  525. if (!this.scriptPage.tab.tabNodeContainer.isOutside(e)){
  526. this.scriptPage.tabNode.show();
  527. this.scriptPanel.container.setStyle("opacity", "0.5");
  528. }else{
  529. this.scriptPage.tabNode.hide();
  530. this.scriptPanel.container.setStyle("opacity", "1");
  531. }
  532. }.bind(this),
  533. "onCompleteMove": function(el, e){
  534. if (!this.scriptPage.tab.tabNodeContainer.isOutside(e)){
  535. this.scriptPage.tabNode.show();
  536. this.designTabScriptAreaNode.inject(this.designTab.contentNodeContainer.getLast());
  537. this.fireEvent("resize");
  538. this.scriptPage.showTabIm();
  539. this.scriptPanel.closePanel();
  540. this.scriptPanel = null;
  541. }
  542. }.bind(this)
  543. });
  544. this.scriptPanel.load();
  545. }.bind(this));
  546. },
  547. createScriptPageDragNode: function(e){
  548. var size = this.scriptPage.tab.contentNodeContainer.getSize();
  549. var position = this.scriptPage.tab.contentNodeContainer.getPosition(this.content);
  550. if (!this.scriptPageContentDrag){
  551. var dragNode = new Element("div", {"styles": this.css.scriptPageDragNode}).inject(this.content);
  552. this.scriptPageContentDrag = new Drag.Move(dragNode, {
  553. "droppables": [this.scriptPage.tab.tabNodeContainer],
  554. "onEnter": function(el, drop){
  555. this.scriptPage.tabNode.show();
  556. this.designTabScriptAreaNode.show();
  557. // this.scriptPageContentDrag.stop();
  558. // this.scriptPageContentDrag.detach();
  559. this.scriptPageContentDrag = null;
  560. dragNode.destroy();
  561. this.scriptPageDrag.start(e);
  562. }.bind(this),
  563. "onComplete": function(el, e){
  564. if (this.scriptPage.tab.tabNodeContainer.isOutside(e)){
  565. this.createScriptPanel(dragNode.getPosition(this.content), dragNode.getSize());
  566. this.designPage.showTabIm();
  567. }
  568. this.scriptPageContentDrag = null;
  569. if (dragNode) dragNode.destroy();
  570. this.designTabScriptAreaNode.show();
  571. }.bind(this)
  572. });
  573. }
  574. var tabPosition = this.scriptPage.tabNode.getPosition();
  575. var dx = e.page.x-tabPosition.x;
  576. var dy = e.page.y-tabPosition.y;
  577. this.scriptPage.tabNode.hide();
  578. this.designTabScriptAreaNode.hide();
  579. var w = size.x*0.7;
  580. var h = size.y*0.7;
  581. var x = position.x+dx;
  582. var y = position.y+dy-20;
  583. dragNode.setStyles({
  584. "width": ""+w+"px",
  585. "height": ""+h+"px",
  586. "top": ""+y+"px",
  587. "left": ""+x+"px"
  588. });
  589. this.scriptPageContentDrag.start(e);
  590. },
  591. setScriptPageEvent: function(){
  592. this.scriptPageDrag = new Drag(this.scriptPage.tabNode, {
  593. "snap": 20,
  594. "onStart": function(el,e){
  595. el.setStyle("position", "static");
  596. },
  597. "onDrag": function(el,e){
  598. if (this.scriptPage.tab.tabNodeContainer.isOutside(e)){
  599. this.scriptPageDrag.stop();
  600. el.setStyle("left", "auto");
  601. this.createScriptPageDragNode(e);
  602. }
  603. }.bind(this),
  604. "onComplete": function(el){
  605. el.setStyle("left", "auto");
  606. //el.setStyle("position", "relative");
  607. }.bind(this)
  608. });
  609. },
  610. checkLoadAllScript: function(){
  611. if (this.form){
  612. this.loadAllScript();
  613. }else{
  614. this.designPage.showTabIm();
  615. }
  616. },
  617. loadAllScript: function(){
  618. if (!this.form.designTabPageScriptAreaNode) this.form.designTabPageScriptAreaNode = Element("div", {"styles": this.css.designTabScriptPcAreaNode}).inject(this.designTabScriptAreaNode);
  619. this.form.designTabPageScriptAreaNode.show();
  620. if (!this.form.scriptDesigner){
  621. MWF.xDesktop.requireApp("portal.PageDesigner", "Script", function(){
  622. this.form.scriptDesigner = new MWF.xApplication.portal.PageDesigner.Script(this, this.form.designTabPageScriptAreaNode, this.form.json);
  623. // var moduleJson = this.pageData.json;
  624. // if (moduleJson.jsheader){
  625. // if (moduleJson.jsheader.code){
  626. //
  627. // }
  628. // }
  629. }.bind(this));
  630. }
  631. },
  632. reloadPropertyStyles: function(){
  633. //MWF.release(this.css);
  634. this.css = null;
  635. this.cssPath = "../x_component_"+this.options.name.replace(/\./g, "_")+"/$Main/"+this.options.style+"/css.wcss";
  636. this._loadCss();
  637. if (this.options.style=="bottom"){
  638. this.propertyNode.inject(this.formNode, "after");
  639. this.propertyTitleNode.setStyle("cursor", "row-resize");
  640. this.loadPropertyResizeBottom();
  641. }else{
  642. this.propertyNode.inject(this.formNode, "before");
  643. this.propertyTitleNode.setStyle("cursor", "default");
  644. if (this.propertyResizeBottom) this.propertyResizeBottom.detach();
  645. }
  646. this.formNode.clearStyles(false);
  647. this.formNode.setStyles(this.css.formNode);
  648. this.propertyNode.clearStyles(false);
  649. this.propertyNode.setStyles(this.css.propertyNode);
  650. this.propertyTitleNode.clearStyles(false);
  651. this.propertyTitleNode.setStyles(this.css.propertyTitleNode);
  652. this.propertyResizeBar.clearStyles(false);
  653. this.propertyResizeBar.setStyles(this.css.propertyResizeBar);
  654. this.propertyContentNode.clearStyles(false);
  655. this.propertyContentNode.setStyles(this.css.propertyContentNode);
  656. this.propertyDomContentArea.clearStyles(false);
  657. this.propertyDomContentArea.setStyles(this.css.propertyDomContentArea);
  658. this.propertyDomScrollArea.clearStyles(false);
  659. this.propertyDomScrollArea.setStyles(this.css.propertyDomScrollArea);
  660. this.propertyDomArea.clearStyles(false);
  661. this.propertyDomArea.setStyles(this.css.propertyDomArea);
  662. this.propertyContentArea.clearStyles(false);
  663. this.propertyContentArea.setStyles(this.css.propertyContentArea);
  664. this.propertyContentResizeNode.clearStyles(false);
  665. this.propertyContentResizeNode.setStyles(this.css.propertyContentResizeNode);
  666. this.propertyTitleActionNode.clearStyles(false);
  667. this.propertyTitleActionNode.setStyles(this.css.propertyTitleActionNode);
  668. this.resizeNode();
  669. },
  670. //loadProperty------------------------
  671. loadProperty: function(){
  672. this.propertyTitleActionNode = new Element("div", {
  673. "styles": this.css.propertyTitleActionNode
  674. }).inject(this.propertyNode);
  675. this.propertyTitleActionNode.addEvent("click", function(){
  676. this.options.style = (this.options.style=="default") ? "bottom" : "default";
  677. MWF.UD.putData("formDesignerStyle", {"style": this.options.style});
  678. this.reloadPropertyStyles();
  679. }.bind(this));
  680. this.propertyTitleNode = new Element("div", {
  681. "styles": this.css.propertyTitleNode,
  682. "text": MWF.APPFD.LP.property
  683. }).inject(this.propertyNode);
  684. if (this.options.style=="bottom"){
  685. this.propertyTitleNode.setStyle("cursor", "row-resize");
  686. this.loadPropertyResizeBottom();
  687. }
  688. this.propertyResizeBar = new Element("div", {
  689. "styles": this.css.propertyResizeBar
  690. }).inject(this.propertyNode);
  691. this.loadPropertyResize();
  692. this.propertyContentNode = new Element("div", {
  693. "styles": this.css.propertyContentNode
  694. }).inject(this.propertyNode);
  695. this.propertyDomContentArea = new Element("div", {
  696. "styles": this.css.propertyDomContentArea
  697. }).inject(this.propertyContentNode);
  698. this.propertyDomScrollArea = new Element("div", {
  699. "styles": this.css.propertyDomScrollArea
  700. }).inject(this.propertyDomContentArea);
  701. this.propertyDomArea = new Element("div", {
  702. "styles": this.css.propertyDomArea
  703. }).inject(this.propertyDomScrollArea);
  704. this.propertyDomPercent = 0.3;
  705. this.propertyContentResizeNode = new Element("div", {
  706. "styles": this.css.propertyContentResizeNode
  707. }).inject(this.propertyContentNode);
  708. this.propertyContentArea = new Element("div", {
  709. "styles": this.css.propertyContentArea
  710. }).inject(this.propertyContentNode);
  711. this.loadPropertyContentResize();
  712. },
  713. loadPropertyResizeBottom: function(){
  714. if (!this.propertyResizeBottom){
  715. this.propertyResizeBottom = new Drag(this.propertyTitleNode,{
  716. "snap": 1,
  717. "onStart": function(el, e){
  718. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  719. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  720. el.store("position", {"x": x, "y": y});
  721. var size = this.propertyNode.getSize();
  722. el.store("initialWidth", size.x);
  723. el.store("initialHeight", size.y);
  724. }.bind(this),
  725. "onDrag": function(el, e){
  726. // var x = e.event.x;
  727. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  728. var bodySize = this.content.getSize();
  729. var position = el.retrieve("position");
  730. var initialHeight = el.retrieve("initialHeight").toFloat();
  731. var dy = position.y.toFloat()-y.toFloat();
  732. var height = initialHeight+dy;
  733. if (height> bodySize.y/1.5) height = bodySize.y/1.5;
  734. if (height<40) height = 40;
  735. var percent = 1-(height/bodySize.y);
  736. this.resizeNode(percent);
  737. //var formNodeHeight = bodySize.y-height;
  738. //this.formNode.setStyle("height", ""+formNodeHeight+"px");
  739. //this.propertyNode.setStyle("height", ""+height+"px");
  740. }.bind(this)
  741. });
  742. }else{
  743. this.propertyResizeBottom.attach();
  744. }
  745. },
  746. loadPropertyResize: function(){
  747. // var size = this.propertyNode.getSize();
  748. // var position = this.propertyResizeBar.getPosition();
  749. this.propertyResize = new Drag(this.propertyResizeBar,{
  750. "snap": 1,
  751. "onStart": function(el, e){
  752. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  753. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  754. el.store("position", {"x": x, "y": y});
  755. var size = this.propertyNode.getSize();
  756. el.store("initialWidth", size.x);
  757. }.bind(this),
  758. "onDrag": function(el, e){
  759. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  760. // var y = e.event.y;
  761. var bodySize = this.content.getSize();
  762. var position = el.retrieve("position");
  763. var initialWidth = el.retrieve("initialWidth").toFloat();
  764. var dx = position.x.toFloat()-x.toFloat();
  765. var width = initialWidth+dx;
  766. if (width> bodySize.x/2) width = bodySize.x/2;
  767. if (width<40) width = 40;
  768. this.formNode.setStyle("margin-right", width+1);
  769. this.propertyNode.setStyle("width", width);
  770. }.bind(this)
  771. });
  772. },
  773. propertyResizeDragTopBottom: function(el, e){
  774. var size = this.propertyContentNode.getSize();
  775. // var x = e.event.x;
  776. var y = e.event.y;
  777. var position = el.retrieve("position");
  778. var dy = y.toFloat()-position.y.toFloat();
  779. var initialHeight = el.retrieve("initialHeight").toFloat();
  780. var height = initialHeight+dy;
  781. if (height<40) height = 40;
  782. if (height> size.y-40) height = size.y-40;
  783. this.propertyDomPercent = height/size.y;
  784. this.setPropertyContentResize();
  785. },
  786. propertyResizeDragLeftRight: function(el, e){
  787. var size = this.propertyContentNode.getSize();
  788. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  789. //var y = e.event.y;
  790. var position = el.retrieve("position");
  791. var dx = x.toFloat()-position.x.toFloat();
  792. var initialWidth = el.retrieve("initialWidth").toFloat();
  793. var width = initialWidth+dx;
  794. if (width<40) width = 40;
  795. if (width> size.x-40) width = size.x-40;
  796. this.propertyDomPercent = width/size.x;
  797. this.setPropertyContentResizeBottom();
  798. },
  799. loadPropertyContentResize: function(){
  800. this.propertyContentResize = new Drag(this.propertyContentResizeNode, {
  801. "snap": 1,
  802. "onStart": function(el, e){
  803. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  804. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  805. el.store("position", {"x": x, "y": y});
  806. var size = this.propertyDomContentArea.getSize();
  807. el.store("initialHeight", size.y);
  808. el.store("initialWidth", size.x);
  809. }.bind(this),
  810. "onDrag": function(el, e){
  811. if (this.options.style=="bottom"){
  812. this.propertyResizeDragLeftRight(el, e);
  813. }else{
  814. this.propertyResizeDragTopBottom(el, e);
  815. }
  816. }.bind(this)
  817. });
  818. },
  819. setPropertyContentResizeBottom: function(){
  820. var size = this.propertyContentNode.getSize();
  821. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  822. var width = size.x-resizeNodeSize.x-6;
  823. var domWidth = this.propertyDomPercent*width;
  824. var contentMargin = domWidth+resizeNodeSize.x+6;
  825. this.propertyDomContentArea.setStyle("width", ""+domWidth+"px");
  826. this.propertyContentArea.setStyle("margin-left", ""+contentMargin+"px");
  827. },
  828. setPropertyContentResize: function(){
  829. var size = this.propertyContentNode.getSize();
  830. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  831. var height = size.y-resizeNodeSize.y;
  832. var domHeight = this.propertyDomPercent*height;
  833. var contentHeight = height-domHeight;
  834. this.propertyDomContentArea.setStyle("height", ""+domHeight+"px");
  835. this.propertyDomScrollArea.setStyle("height", ""+domHeight+"px");
  836. this.propertyContentArea.setStyle("height", ""+contentHeight+"px");
  837. if (this.form){
  838. if (this.form.currentSelectedModule){
  839. if (this.form.currentSelectedModule.property){
  840. var tab = this.form.currentSelectedModule.property.propertyTab;
  841. if (tab){
  842. var tabTitleSize = tab.tabNodeContainer.getSize();
  843. tab.pages.each(function(page){
  844. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  845. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  846. var tabContentNodeAreaHeight = contentHeight - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  847. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  848. }.bind(this));
  849. }
  850. }
  851. }
  852. }
  853. },
  854. //loadTools------------------------------
  855. loadTools: function(){
  856. var designer = this;
  857. this.getTools(function(){
  858. Object.each(this.toolsData, function(value, key){
  859. var toolNode = new Element("div", {
  860. "styles": this.css.toolbarToolNode,
  861. "title": value.text,
  862. "events": {
  863. "mouseover": function(e){
  864. try {
  865. this.setStyles(designer.css.toolbarToolNodeOver);
  866. }catch(e){
  867. this.setStyles(designer.css.toolbarToolNodeOverCSS2);
  868. };
  869. },
  870. "mouseout": function(e){
  871. try {
  872. this.setStyles(designer.css.toolbarToolNode);
  873. }catch(e){};
  874. },
  875. "mousedown": function(e){
  876. try {
  877. this.setStyles(designer.css.toolbarToolNodeDown);
  878. }catch(e){
  879. this.setStyles(designer.css.toolbarToolNodeDownCSS2);
  880. };
  881. },
  882. "mouseup": function(e){
  883. try {
  884. this.setStyles(designer.css.toolbarToolNodeUp);
  885. }catch(e){
  886. this.setStyles(designer.css.toolbarToolNodeUpCSS2);
  887. };
  888. }
  889. }
  890. }).inject(this.toolbarContentNode);
  891. toolNode.store("toolClass", value.className);
  892. var iconNode = new Element("div", {
  893. "styles": this.css.toolbarToolIconNode
  894. }).inject(toolNode);
  895. iconNode.setStyle("background-image", "url("+this.path+this.options.style+"/icon/"+value.icon+")");
  896. var textNode = new Element("div", {
  897. "styles": this.css.toolbarToolTextNode,
  898. "text": value.text
  899. });
  900. textNode.inject(toolNode);
  901. // var designer = this;
  902. toolNode.addEvent("mousedown", function(e){
  903. var className = this.retrieve("toolClass");
  904. designer.form.createModule(className, e);
  905. });
  906. this.tools.push(toolNode);
  907. }.bind(this));
  908. }.bind(this));
  909. },
  910. getTools: function(callback){
  911. if (this.toolsData){
  912. if (callback) callback();
  913. }else{
  914. var toolsDataUrl = this.path+this.options.style+"/tools.json";
  915. var r = new Request.JSON({
  916. url: toolsDataUrl,
  917. secure: false,
  918. async: false,
  919. method: "get",
  920. noCache: true,
  921. onSuccess: function(responseJSON, responseText){
  922. this.toolsData = responseJSON;
  923. if (callback) callback();
  924. }.bind(this),
  925. onError: function(text, error){
  926. this.notice("request tools data error: "+error, "error");
  927. }.bind(this)
  928. });
  929. r.send();
  930. }
  931. },
  932. //resizeNode------------------------------------------------
  933. resizeNodeLeftRight: function(){
  934. var nodeSize = this.node.getSize();
  935. this.toolbarNode.setStyle("height", ""+nodeSize.y+"px");
  936. this.formNode.setStyle("height", ""+nodeSize.y+"px");
  937. this.propertyNode.setStyle("height", ""+nodeSize.y+"px");
  938. //nodeSize = {"x": nodeSize.x, "y": nodeSize.y*0.6};
  939. var formToolbarMarginTop = this.formToolbarNode.getStyle("margin-top").toFloat();
  940. var formToolbarMarginBottom = this.formToolbarNode.getStyle("margin-bottom").toFloat();
  941. var allFormToolberSize = this.formToolbarNode.getComputedSize();
  942. var y = nodeSize.y - allFormToolberSize.totalHeight - formToolbarMarginTop - formToolbarMarginBottom;
  943. this.formContentNode.setStyle("height", ""+y+"px");
  944. var tabSize = this.designTab.tabNodeContainer.getComputedSize();
  945. var tabMarginTop = this.designTab.tabNodeContainer.getStyle("margin-top").toFloat();
  946. var tabMarginBottom = this.designTab.tabNodeContainer.getStyle("margin-bottom").toFloat();
  947. y = y-tabSize.totalHeight-tabMarginTop-tabMarginBottom;
  948. this.designTab.contentNodeContainer.setStyle("height", ""+y+"px");
  949. if (this.designNode){
  950. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  951. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  952. y = y - designMarginTop - designMarginBottom;
  953. this.designNode.setStyle("height", ""+y+"px");
  954. }
  955. var titleSize = this.toolbarTitleNode.getSize();
  956. var titleMarginTop = this.toolbarTitleNode.getStyle("margin-top").toFloat();
  957. var titleMarginBottom = this.toolbarTitleNode.getStyle("margin-bottom").toFloat();
  958. var titlePaddingTop = this.toolbarTitleNode.getStyle("padding-top").toFloat();
  959. var titlePaddingBottom = this.toolbarTitleNode.getStyle("padding-bottom").toFloat();
  960. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  961. y = nodeSize.y-y;
  962. this.toolbarContentNode.setStyle("height", ""+y+"px");
  963. titleSize = this.propertyTitleNode.getSize();
  964. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  965. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  966. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  967. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  968. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  969. y = nodeSize.y-y;
  970. this.propertyContentNode.setStyle("height", ""+y+"px");
  971. this.propertyResizeBar.setStyle("height", ""+y+"px");
  972. },
  973. resizeNodeTopBottom: function(percent){
  974. var nodeSize = this.node.getSize();
  975. this.toolbarNode.setStyle("height", ""+nodeSize.y+"px");
  976. var percentNumber = percent || 0.6
  977. var designerHeight = nodeSize.y*percentNumber;
  978. var propertyHeight = nodeSize.y - designerHeight;
  979. this.formNode.setStyle("height", ""+designerHeight+"px");
  980. this.propertyNode.setStyle("height", ""+propertyHeight+"px");
  981. var formToolbarMarginTop = this.formToolbarNode.getStyle("margin-top").toFloat();
  982. var formToolbarMarginBottom = this.formToolbarNode.getStyle("margin-bottom").toFloat();
  983. var allFormToolberSize = this.formToolbarNode.getComputedSize();
  984. var y = designerHeight - allFormToolberSize.totalHeight - formToolbarMarginTop - formToolbarMarginBottom;
  985. // this.formContentNode.setStyle("height", ""+designerHeight+"px");
  986. var tabSize = this.designTab.tabNodeContainer.getComputedSize();
  987. var tabMarginTop = this.designTab.tabNodeContainer.getStyle("margin-top").toFloat();
  988. var tabMarginBottom = this.designTab.tabNodeContainer.getStyle("margin-bottom").toFloat();
  989. y = y-tabSize.totalHeight-tabMarginTop-tabMarginBottom;
  990. this.designTab.contentNodeContainer.setStyle("height", ""+y+"px");
  991. if (this.designNode){
  992. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  993. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  994. y = y - designMarginTop - designMarginBottom;
  995. this.designNode.setStyle("height", ""+y+"px");
  996. }
  997. var titleSize = this.toolbarTitleNode.getSize();
  998. var titleMarginTop = this.toolbarTitleNode.getStyle("margin-top").toFloat();
  999. var titleMarginBottom = this.toolbarTitleNode.getStyle("margin-bottom").toFloat();
  1000. var titlePaddingTop = this.toolbarTitleNode.getStyle("padding-top").toFloat();
  1001. var titlePaddingBottom = this.toolbarTitleNode.getStyle("padding-bottom").toFloat();
  1002. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  1003. y = nodeSize.y-y;
  1004. this.toolbarContentNode.setStyle("height", ""+y+"px");
  1005. titleSize = this.propertyTitleNode.getSize();
  1006. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  1007. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  1008. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  1009. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  1010. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  1011. y = propertyHeight-y;
  1012. this.propertyContentNode.setStyle("height", ""+y+"px");
  1013. this.propertyResizeBar.setStyle("height", ""+y+"px");
  1014. this.propertyDomContentArea.setStyle("height", ""+y+"px");
  1015. this.propertyDomScrollArea.setStyle("height", ""+y+"px");
  1016. this.propertyContentResizeNode.setStyle("height", ""+y+"px");
  1017. this.propertyContentArea.setStyle("height", ""+y+"px");
  1018. if (this.form){
  1019. if (this.form.currentSelectedModule){
  1020. if (this.form.currentSelectedModule.property){
  1021. var tab = this.form.currentSelectedModule.property.propertyTab;
  1022. if (tab){
  1023. var tabTitleSize = tab.tabNodeContainer.getSize();
  1024. tab.pages.each(function(page){
  1025. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1026. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1027. var tabContentNodeAreaHeight = y - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  1028. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1029. }.bind(this));
  1030. }
  1031. }
  1032. }
  1033. }
  1034. },
  1035. resizeNode: function(percent){
  1036. if (this.options.style=="bottom"){
  1037. this.resizeNodeTopBottom(percent);
  1038. this.setPropertyContentResizeBottom();
  1039. }else{
  1040. this.resizeNodeLeftRight(percent);
  1041. this.setPropertyContentResize();
  1042. }
  1043. },
  1044. //loadForm------------------------------------------
  1045. loadForm: function(){
  1046. // try{
  1047. this.getFormData(function(){
  1048. this.pcForm = new MWF.FCForm(this, this.designNode);
  1049. this.pcForm.load(this.formData);
  1050. this.form = this.pcForm;
  1051. }.bind(this));
  1052. // }catch(e){
  1053. // layout.notice("error", {x: "right", y:"top"}, e.message, this.designNode);
  1054. // }
  1055. // MWF.getJSON(COMMON.contentPath+"/res/js/testform.json", {
  1056. // "onSuccess": function(obj){
  1057. // this.form = new MWF.FCForm(this);
  1058. // this.form.load(obj);
  1059. // }.bind(this),
  1060. // "onerror": function(text){
  1061. // layout.notice("error", {x: "right", y:"top"}, text, this.designNode);
  1062. // }.bind(this),
  1063. // "onRequestFailure": function(xhr){
  1064. // layout.notice("error", {x: "right", y:"top"}, xhr.responseText, this.designNode);
  1065. // }
  1066. // });
  1067. },
  1068. getFormData: function(callback){
  1069. if (!this.options.id){
  1070. if (this.options.templateId){
  1071. this.loadNewFormDataFormTemplate(callback);
  1072. }else{
  1073. this.loadNewFormData(callback);
  1074. }
  1075. }else{
  1076. this.loadFormData(callback);
  1077. }
  1078. },
  1079. loadNewFormData: function(callback){
  1080. var url = "../x_component_process_FormDesigner/Module/Form/template/"+this.options.template;
  1081. //MWF.getJSON("../x_component_process_FormDesigner/Module/Form/template.json", {
  1082. MWF.getJSON(url, {
  1083. "onSuccess": function(obj){
  1084. this.formData = obj.pcData;
  1085. this.formData.id="";
  1086. this.formData.isNewForm = true;
  1087. this.formMobileData = obj.mobileData;
  1088. this.formMobileData.id="";
  1089. this.formMobileData.isNewForm = true;
  1090. if (callback) callback();
  1091. }.bind(this),
  1092. "onerror": function(text){
  1093. this.notice(text, "error");
  1094. }.bind(this),
  1095. "onRequestFailure": function(xhr){
  1096. this.notice(xhr.responseText, "error");
  1097. }.bind(this)
  1098. });
  1099. },
  1100. loadNewFormDataFormTemplate: function(callback){
  1101. this.actions.getFormTemplate(this.options.templateId, function(form){
  1102. if (form){
  1103. this.formData = JSON.decode(MWF.decodeJsonString(form.data.data));
  1104. this.formData.isNewForm = true;
  1105. this.formData.json.id = "";
  1106. if (form.data.mobileData){
  1107. this.formMobileData = JSON.decode(MWF.decodeJsonString(form.data.mobileData));
  1108. this.formMobileData.isNewForm = true;
  1109. this.formMobileData.json.id = "";
  1110. }else{
  1111. this.formMobileData = Object.clone(this.formData);
  1112. }
  1113. if (callback) callback();
  1114. //this.actions.getFormCategory(this.formData.json.formCategory, function(category){
  1115. // this.category = {"data": {"name": category.data.name, "id": category.data.id}};
  1116. // if (callback) callback();
  1117. //}.bind(this));
  1118. }
  1119. }.bind(this));
  1120. },
  1121. loadFormData: function(callback){
  1122. this.actions.getForm(this.options.id, function(form){
  1123. if (form){
  1124. this.formData = JSON.decode(MWF.decodeJsonString(form.data.data));
  1125. this.formData.isNewForm = false;
  1126. this.formData.json.id = form.data.id;
  1127. if (form.data.mobileData){
  1128. this.formMobileData = JSON.decode(MWF.decodeJsonString(form.data.mobileData));
  1129. this.formMobileData.isNewForm = false;
  1130. this.formMobileData.json.id = form.data.id;
  1131. }else{
  1132. this.formMobileData = Object.clone(this.formData);
  1133. }
  1134. this.setTitle(this.options.appTitle + "-"+this.formData.json.name);
  1135. if (this.taskitem) this.taskitem.setText(this.options.appTitle + "-"+this.formData.json.name);
  1136. this.options.appTitle = this.options.appTitle + "-"+this.formData.json.name;
  1137. if (!this.application){
  1138. this.actions.getApplication(form.data.application, function(json){
  1139. this.application = {"name": json.data.name, "id": json.data.id};
  1140. if (callback) callback();
  1141. }.bind(this));
  1142. }else{
  1143. if (callback) callback();
  1144. }
  1145. //this.actions.getFormCategory(this.formData.json.formCategory, function(category){
  1146. // this.category = {"data": {"name": category.data.name, "id": category.data.id}};
  1147. // if (callback) callback();
  1148. //}.bind(this));
  1149. }
  1150. }.bind(this));
  1151. },
  1152. getFieldList: function(){
  1153. //fieldTypes = ["calender", "checkbox", "datagrid", "htmledit", "number", "personfield", "radio", "select", "textarea", "textfield"];
  1154. dataTypes = {
  1155. "string": ["htmledit", "radio", "select", "textarea", "textfield"],
  1156. "person": ["personfield","orgfield","org"],
  1157. "date": ["calender"],
  1158. "number": ["number"],
  1159. "array": ["checkbox"]
  1160. };
  1161. fieldList = [];
  1162. this.pcForm.moduleList.each(function(moudle){
  1163. var key = "";
  1164. for (k in dataTypes){
  1165. if (dataTypes[k].indexOf(moudle.moduleName.toLowerCase())!=-1){
  1166. key = k;
  1167. break;
  1168. }
  1169. }
  1170. if (key){
  1171. fieldList.push({
  1172. "name": moudle.json.id,
  1173. "dataType": key
  1174. });
  1175. }
  1176. }.bind(this));
  1177. return fieldList;
  1178. },
  1179. checkSubform: function(){
  1180. var pcSubforms = [];
  1181. if (this.pcForm){
  1182. this.pcForm.moduleList.each(function(module){
  1183. if (module.moduleName==="subform"){
  1184. if (module.regetSubformData()){
  1185. module.subformData.updateTime = "";
  1186. var moduleNames = module.getConflictFields();
  1187. if (moduleNames.length){
  1188. var o = {
  1189. "id": module.json.id,
  1190. "fields": moduleNames
  1191. };
  1192. pcSubforms.push(o);
  1193. }
  1194. }
  1195. }
  1196. }.bind(this));
  1197. }
  1198. var mobileSubforms = [];
  1199. if (this.mobileForm){
  1200. this.mobileForm.moduleList.each(function(module){
  1201. if (module.moduleName==="subform"){
  1202. if (module.regetSubformData()){
  1203. module.subformData.updateTime = "";
  1204. var moduleNames = module.getConflictFields();
  1205. if (moduleNames.length){
  1206. var o = {
  1207. "id": module.json.id,
  1208. "fields": moduleNames
  1209. };
  1210. mobileSubforms.push(o);
  1211. }
  1212. }
  1213. }
  1214. }.bind(this));
  1215. }
  1216. var txt = "";
  1217. if (pcSubforms.length){
  1218. var pctxt = "";
  1219. pcSubforms.each(function(subform){
  1220. pctxt += subform.id+" ( "+subform.fields.join(", ")+" ) <br>";
  1221. });
  1222. txt += this.lp.checkSubformPcInfor.replace("{subform}", pctxt);
  1223. }
  1224. if (mobileSubforms.length){
  1225. var mobiletxt = "";
  1226. mobileSubforms.each(function(subform){
  1227. mobiletxt += subform.id+" ( "+subform.fields.join(", ")+" ) <br>";
  1228. });
  1229. txt += this.lp.checkSubformMobileInfor.replace("{subform}", mobiletxt);
  1230. }
  1231. return txt;
  1232. },
  1233. saveForm: function(){
  1234. if (!this.isSave){
  1235. var txt = this.checkSubform();
  1236. if (txt){
  1237. txt = this.lp.checkFormSaveError+txt;
  1238. // var p = this.node.getPosition(document.body);
  1239. // this.alert("error", {
  1240. // "event": {
  1241. // "x": p.x+150,
  1242. // "y": p.y+80
  1243. // }
  1244. // }, this.lp.checkSubformTitle, {"html": txt}, 400, 200);
  1245. this.notice(txt, "error", this.form.node);
  1246. return false;
  1247. }
  1248. // if (this.pcForm){
  1249. // this.pcForm.moduleList.each(function(module){
  1250. // if (module.moduleName==="subform"){
  1251. // module.refreshSubform();
  1252. // }
  1253. // }.bind(this));
  1254. // }
  1255. // if (this.mobileForm){
  1256. // this.mobileForm.moduleList.each(function(module){
  1257. // if (module.moduleName==="subform"){
  1258. // module.refreshSubform();
  1259. // }
  1260. // }.bind(this));
  1261. // }
  1262. // @todo 预先整理表单样式
  1263. // var loadedPcForm = !this.pcForm;
  1264. // var loadedMobileForm = !this.mobileForm;
  1265. // var checkLoad = function(){
  1266. // if (loadedPcForm && loadedMobileForm){
  1267. // this.isSave = true;
  1268. // var fieldList = this.getFieldList();
  1269. // this.actions.saveForm(pcData, mobileData, fieldList, function(responseJSON){
  1270. // this.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  1271. // if (!this.pcForm.json.name) this.pcForm.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  1272. // this.pcForm.treeNode.setTitle(this.pcForm.json.id);
  1273. // this.pcForm.node.set("id", this.pcForm.json.id);
  1274. //
  1275. // if (this.mobileForm){
  1276. // if (!this.mobileForm.json.name) this.mobileForm.treeNode.setText("<"+this.mobileForm.json.type+"> "+this.mobileForm.json.id);
  1277. // this.mobileForm.treeNode.setTitle(this.mobileForm.json.id);
  1278. // this.mobileForm.node.set("id", this.mobileForm.json.id+"_"+this.options.mode);
  1279. // }
  1280. //
  1281. // var name = this.pcForm.json.name;
  1282. // if (this.pcForm.data.isNewForm) this.setTitle(this.options.appTitle + "-"+name);
  1283. // this.pcForm.data.isNewForm = false;
  1284. // if (this.mobileForm) this.mobileForm.data.isNewForm = false;
  1285. //
  1286. // this.options.desktopReload = true;
  1287. // this.options.id = this.pcForm.json.id;
  1288. //
  1289. // if (this.pcForm) this.pcForm.fireEvent("postSave");
  1290. // if (this.mobileForm) this.mobileForm.fireEvent("postSave");
  1291. //
  1292. // this.isSave = false;
  1293. //
  1294. // }.bind(this), function(xhr, text, error){
  1295. // this.isSave = false;
  1296. //
  1297. // if (this.pcForm) this.pcForm.fireEvent("postSaveError");
  1298. // if (this.mobileForm) this.mobileForm.fireEvent("postSaveError");
  1299. //
  1300. // var errorText = error+":"+text;
  1301. // if (xhr) errorText = xhr.responseText;
  1302. // MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1303. // }.bind(this));
  1304. // }
  1305. // }.bind(this);
  1306. //
  1307. //
  1308. // var pcData, mobileData;
  1309. // if (this.pcForm){
  1310. // this.pcForm._getFormData(function(){
  1311. // pcData = this.pcForm.data;
  1312. // loadedPcForm = true;
  1313. // checkLoad();
  1314. // });
  1315. // }
  1316. // if (this.mobileForm){
  1317. // this.mobileForm._getFormData(function(){
  1318. // mobileData = this.mobileForm.data;
  1319. // loadedMobileForm = true;
  1320. // checkLoad();
  1321. // });
  1322. // }else{
  1323. // if (this.formMobileData) mobileData = this.formMobileData;
  1324. // loadedMobileForm = true;
  1325. // checkLoad();
  1326. // }
  1327. var pcData, mobileData;
  1328. if (this.pcForm){
  1329. pcData = this.pcForm._getFormData();
  1330. //pcData = this.pcForm.data;
  1331. }
  1332. if (this.mobileForm){
  1333. mobileData = this.mobileForm._getFormData();
  1334. //mobileData = this.mobileForm.data;
  1335. }else{
  1336. if (this.formMobileData) mobileData = this.formMobileData;
  1337. }
  1338. this.isSave = true;
  1339. var fieldList = this.getFieldList();
  1340. this.actions.saveForm(pcData, mobileData, fieldList, function(responseJSON){
  1341. this.notice(MWF.APPFD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"});
  1342. if (!this.pcForm.json.name) this.pcForm.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  1343. this.pcForm.treeNode.setTitle(this.pcForm.json.id);
  1344. this.pcForm.node.set("id", this.pcForm.json.id);
  1345. if (this.mobileForm){
  1346. if (!this.mobileForm.json.name) this.mobileForm.treeNode.setText("<"+this.mobileForm.json.type+"> "+this.mobileForm.json.id);
  1347. this.mobileForm.treeNode.setTitle(this.mobileForm.json.id);
  1348. this.mobileForm.node.set("id", this.mobileForm.json.id+"_"+this.options.mode);
  1349. }
  1350. var name = this.pcForm.json.name;
  1351. if (this.pcForm.data.isNewForm) this.setTitle(this.options.appTitle + "-"+name);
  1352. this.pcForm.data.isNewForm = false;
  1353. if (this.mobileForm) this.mobileForm.data.isNewForm = false;
  1354. this.options.desktopReload = true;
  1355. this.options.id = this.pcForm.json.id;
  1356. if (this.pcForm) this.pcForm.fireEvent("postSave");
  1357. if (this.mobileForm) this.mobileForm.fireEvent("postSave");
  1358. this.isSave = false;
  1359. }.bind(this), function(xhr, text, error){
  1360. this.isSave = false;
  1361. if (this.pcForm) this.pcForm.fireEvent("postSaveError");
  1362. if (this.mobileForm) this.mobileForm.fireEvent("postSaveError");
  1363. var errorText = error+":"+text;
  1364. if (xhr) errorText = xhr.responseText;
  1365. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1366. }.bind(this));
  1367. }else{
  1368. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  1369. }
  1370. //this.form.save(function(){
  1371. //
  1372. // var name = this.form.json.name;
  1373. // if (this.form.data.isNewForm) this.setTitle(this.options.appTitle + "-"+name);
  1374. // this.form.data.isNewForm = false;
  1375. // this.options.desktopReload = true;
  1376. // this.options.id = this.form.json.id;
  1377. //}.bind(this));
  1378. },
  1379. previewForm: function(){
  1380. this.form.preview();
  1381. },
  1382. formExplode: function(){
  1383. this.form.explode();
  1384. },
  1385. formImplode: function(){
  1386. this.form.implode();
  1387. },
  1388. htmlImplode: function(){
  1389. this.form.implodeHTML();
  1390. },
  1391. officeImplode: function(){
  1392. this.form.implodeOffice();
  1393. },
  1394. recordStatus: function(){
  1395. return {"id": this.options.id};
  1396. },
  1397. onPostClose: function(){
  1398. if (this.pcForm){
  1399. MWF.release(this.pcForm.moduleList);
  1400. MWF.release(this.pcForm.moduleNodeList);
  1401. MWF.release(this.pcForm.moduleContainerNodeList);
  1402. MWF.release(this.pcForm.moduleElementNodeList);
  1403. MWF.release(this.pcForm.moduleComponentNodeList);
  1404. MWF.release(this.pcForm);
  1405. }
  1406. if (this.mobileForm){
  1407. MWF.release(this.mobileForm.moduleList);
  1408. MWF.release(this.mobileForm.moduleNodeList);
  1409. MWF.release(this.mobileForm.moduleContainerNodeList);
  1410. MWF.release(this.mobileForm.moduleElementNodeList);
  1411. MWF.release(this.mobileForm.moduleComponentNodeList);
  1412. MWF.release(this.mobileForm);
  1413. }
  1414. },
  1415. setTemplateFormNode: function(formNode){
  1416. var html = "<table align=\"center\" width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  1417. "<tr><td colSpan=\"2\" style=\"height: 50px; line-height: 60px; text-align: center; font-size: 24px; font-weight: bold\">" +
  1418. this.lp.saveTemplate+"</td></tr>" +
  1419. "<tr><td style=\"height: 40px;\" width=\"80px\">" +this.lp.templateName+"</td><td>"+
  1420. "<input value=\""+this.pcForm.json.name+"\" type=\"text\" style=\"width: 98%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  1421. "<tr><td style=\"height: 40px;\">" +this.lp.templateCategory+"</td><td>"+
  1422. "<select style=\"width: 30%; height: 24px; border: 1px solid #cccccc\"></select>"+
  1423. "<input type=\"text\" style=\"width: 68%; height: 22px; border: 1px solid #cccccc\"/>"+"</td></tr>" +
  1424. "<tr><td style=\"height: 40px;\">" +this.lp.templateDescription+"</td><td>"+
  1425. "<textarea type=\"text\" style=\"width: 98%; height: 44px; border: 1px solid #cccccc\">"+this.pcForm.json.description+"</textarea>"+"</td></tr>" +
  1426. "<tr><td colSpan=\"2\" id=\"form_templatePreview\">" +
  1427. "<div style=\"position: relative; width: 180px; height: 180px; margin: 20px auto 0px auto; overflow: hidden\"></div>" +
  1428. "</td></tr>" +
  1429. "</table>";
  1430. formNode.set("html", html);
  1431. var tds = formNode.getElements("td");
  1432. var iconNode = tds[tds.length-1].getFirst();
  1433. var previewNode = this.pcForm.node.clone();
  1434. previewNode.setStyles({
  1435. "transform-origin": "0px 0px",
  1436. "transform": "scale(0.15,0.15)",
  1437. "position": "absolute",
  1438. "top": "0px",
  1439. "left": "0px"
  1440. }).inject(iconNode);
  1441. return iconNode;
  1442. },
  1443. setCategorySelect: function(categorySelect){
  1444. if (categorySelect){
  1445. new Element("option", {"value": "$newCategory","text": this.lp.newCategory}).inject(categorySelect);
  1446. this.actions.listFormTemplateCategory(function(json){
  1447. json.data.each(function(category){
  1448. new Element("option", {"value": category.name,"text": category.name}).inject(categorySelect);
  1449. }.bind(this));
  1450. }.bind(this));
  1451. }
  1452. },
  1453. setTemplateActions: function(markNode, areaNode, formNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1454. var actionAreaNode= new Element("div", {
  1455. "styles": this.css.templateActionNode
  1456. }).inject(formNode);
  1457. var cancelActionNode = new Element("div", {
  1458. "styles": this.css.templateCancelActionNode,
  1459. "text": this.lp.cancel,
  1460. "events":{
  1461. "click": function(){
  1462. markNode.destroy();
  1463. areaNode.destroy();
  1464. }
  1465. }
  1466. }).inject(actionAreaNode);
  1467. var saveActionNode = new Element("div", {
  1468. "styles": this.css.templateSaveActionNode,
  1469. "text": this.lp.save,
  1470. "events":{
  1471. "click": function(){
  1472. this.saveTemplate(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1473. }.bind(this)
  1474. }
  1475. }).inject(actionAreaNode);
  1476. },
  1477. saveTemplate: function(markNode, areaNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode){
  1478. var pcData, mobileData;
  1479. if (this.pcForm){
  1480. pcData = this.pcForm._getFormData();
  1481. //pcData = this.pcForm.data;
  1482. }
  1483. if (this.mobileForm){
  1484. mobileData = this.mobileForm._getFormData();
  1485. //mobileData = this.mobileForm.data;
  1486. }
  1487. var name = nameNode.get("value");
  1488. var category = (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory") ? newCategoryNode.get("value") : categorySelect.options[categorySelect.selectedIndex].value;
  1489. var description = descriptionNode.get("value");
  1490. if (!name){
  1491. this.notice(MWF.APPFD.LP.notice["saveTemplate_inputName"], "error", nameNode, {x: "left", y:"top"});
  1492. return false;
  1493. }
  1494. if (categorySelect.options[categorySelect.selectedIndex].value=="$newCategory" && !newCategoryNode.get("value")){
  1495. this.notice(MWF.APPFD.LP.notice["saveTemplate_inputCategory"], "error", categorySelect, {x: "left", y:"top"});
  1496. return false;
  1497. }
  1498. //var tds = formNode.getElements("td");
  1499. //var iconNode = tds[tds.length-1].getFirst();
  1500. var data = {
  1501. "name": name,
  1502. "category": category,
  1503. "description": description,
  1504. "outline": iconNode.get("html")
  1505. };
  1506. this.actions.addFormTemplate(pcData, mobileData, data, function(){
  1507. this.notice(MWF.APPFD.LP.notice["saveTemplate_success"], "ok", null, {x: "left", y:"bottom"});
  1508. markNode.destroy();
  1509. areaNode.destroy();
  1510. }.bind(this), function(xhr, text, error){
  1511. var errorText = error+":"+text;
  1512. if (xhr) errorText = xhr.responseText;
  1513. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1514. });
  1515. },
  1516. createTemplateSaveNode: function(){
  1517. var markNode = new Element("div", {
  1518. "styles": this.css.templateMarkNode,
  1519. "events": {
  1520. "mouseover": function(e){e.stopPropagation();},
  1521. "mouseout": function(e){e.stopPropagation();}
  1522. }
  1523. }).inject(this.content);
  1524. var areaNode = new Element("div", {
  1525. "styles": this.css.templateAreaNode
  1526. }).inject(this.content);
  1527. var createNode = new Element("div", {
  1528. "styles": this.css.templateInfoNode
  1529. }).inject(areaNode);
  1530. var formNode = new Element("div", {
  1531. "styles": this.css.templateFormNode
  1532. }).inject(createNode);
  1533. var iconNode = this.setTemplateFormNode(formNode);
  1534. var nodes = formNode.getElements("input");
  1535. var nameNode = nodes[0];
  1536. var newCategoryNode = nodes[1];
  1537. var descriptionNode = formNode.getElement("textarea");
  1538. var categorySelect = formNode.getElement("select");
  1539. this.setCategorySelect(categorySelect);
  1540. this.setTemplateActions(markNode, areaNode, formNode, iconNode, nameNode, categorySelect, newCategoryNode, descriptionNode);
  1541. },
  1542. saveFormAsTemplate: function(){
  1543. if (!this.isSave){
  1544. this.createTemplateSaveNode();
  1545. }else{
  1546. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.lp.isSave);
  1547. }
  1548. },
  1549. styleBrush: function(status, bt){
  1550. if (status==="on"){
  1551. var module = this.form.currentSelectedModule;
  1552. if (module && module.json.type!=="Form"){
  1553. this.form.brushStyle = module.json.styles;
  1554. if (module.json.inputStyles) this.form.brushInputStyle = Object.clone(module.json.inputStyles);
  1555. this.brushCursor = new Element("div", {"styles": {
  1556. "position": "absolute",
  1557. "width": "16px",
  1558. "height": "16px",
  1559. "z-index": 20000,
  1560. "background": "url("+this.path+this.options.style+"/formtoolbar/wand.png)"
  1561. }}).inject(this.content);
  1562. this.brushCursorMoveFun = this.brushCursorMove.bind(this);
  1563. this.contentPosition = this.content.getPosition();
  1564. this.content.addEvent("mousemove", this.brushCursorMoveFun);
  1565. //this.designNode.setStyle("cursor", "url(/"+this.path+this.options.style+"/pageToolbar/brush.png)");
  1566. }else{
  1567. bt.off();
  1568. }
  1569. }else{
  1570. this.form.brushStyle = null;
  1571. this.form.brushInputStyle = null;
  1572. if (this.brushCursorMoveFun) this.content.removeEvent("mousemove", this.brushCursorMoveFun);
  1573. if (this.brushCursor){
  1574. this.brushCursor.destroy();
  1575. this.brushCursor = null;
  1576. }
  1577. }
  1578. },
  1579. brushCursorMove: function(e){
  1580. if (this.brushCursor){
  1581. var x = e.page.x-this.contentPosition.x+10;
  1582. var y = e.page.y-this.contentPosition.y+10;
  1583. this.brushCursor.setStyles({
  1584. "left": ""+x+"px",
  1585. "top": ""+y+"px"
  1586. });
  1587. }
  1588. }
  1589. });