Main.js 69 KB

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