Main.js 56 KB

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