Main.js 70 KB

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