Main.js 70 KB

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