Main.js 66 KB

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