Main.js 66 KB

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