Main.js 83 KB

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