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