Main.js 68 KB

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