Main.js 88 KB

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