Main.js 65 KB

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