Main.js 84 KB

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