Main.js 69 KB

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