Main.js 68 KB

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