Main.js 70 KB

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