Main.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. MWF.xApplication.portal = MWF.xApplication.portal || {};
  2. MWF.xApplication.portal.Portal = MWF.xApplication.portal.Portal || {};
  3. MWF.xApplication.portal.Portal.options = Object.clone(o2.xApplication.Common.options);
  4. MWF.xApplication.portal.Portal.options.multitask = true;
  5. MWF.xApplication.portal.Portal.Main = new Class({
  6. Extends: MWF.xApplication.Common.Main,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default",
  10. "name": "portal.Portal",
  11. "icon": "icon.png",
  12. "width": "1200",
  13. "height": "800",
  14. "title": MWF.xApplication.portal.Portal.LP.title,
  15. "portalId": "",
  16. "pageId": "",
  17. "widgetId" : "",
  18. "isControl": false,
  19. "taskObject": null,
  20. "parameters": "",
  21. "readonly": false
  22. },
  23. onQueryLoad: function(){
  24. this.lp = MWF.xApplication.portal.Portal.LP;
  25. if (this.status){
  26. this.options.portalId = this.status.portalId;
  27. this.options.pageId = this.status.pageId;
  28. this.options.widgetId = this.status.widgetId;
  29. this.options.parameters = this.status.parameters;
  30. }
  31. },
  32. loadApplication: function(callback){
  33. this.node = new Element("div", {"styles": this.css.content}).inject(this.content);
  34. //MWF.require("MWF.widget.Mask", function(){
  35. //this.mask = new MWF.widget.Mask({"style": "desktop"});
  36. this.formNode = new Element("div", {"styles": {"min-height": "100%", "font-size": "14px"}}).inject(this.node);
  37. this.action = MWF.Actions.get("x_portal_assemble_surface");
  38. //MWF.xDesktop.requireApp("portal.Portal", "Actions.RestActions", function(){
  39. // this.action = new MWF.xApplication.portal.Portal.Actions.RestActions();
  40. if (!this.options.isRefresh){
  41. this.maxSize(function(){
  42. //this.mask.loadNode(this.content);
  43. this.loadPortal(this.options.parameters, callback);
  44. }.bind(this));
  45. }else {
  46. //this.mask.loadNode(this.content);
  47. this.loadPortal(this.options.parameters, callback);
  48. }
  49. //if (callback) callback();
  50. //}.bind(this));
  51. //}.bind(this));
  52. },
  53. //reload: function(data){
  54. // if (this.form){
  55. // this.formNode.empty();
  56. // MWF.release(this.form);
  57. // this.form = null;
  58. // }
  59. // //this.parseData(data);
  60. // this.openPortal();
  61. //},
  62. toPortal: function(portal, page, par, nohis){
  63. this.options.portalId = portal;
  64. this.options.pageId = page;
  65. if (!nohis) this.doHistory(page,this.options.portalId);
  66. if (this.appForm) this.appForm.fireEvent("beforeClose");
  67. Object.keys(this.$events).each(function(k){
  68. this.removeEvents(k);
  69. }.bind(this));
  70. MWF.release(this.appForm);
  71. this.appForm = null;
  72. this.formNode.empty();
  73. this.loadPortal(par);
  74. },
  75. doHistory: function(name, portal){
  76. if (this.inBrowser){
  77. var stateObj = { "page": name, "id": portal || this.options.portalId };
  78. history.pushState(stateObj, "page");
  79. }
  80. },
  81. toPage: function(name, par, nohis){
  82. if (!nohis) this.doHistory(name, this.portal.id);
  83. var pageJson = null;
  84. var loadModuleFlag = false;
  85. var check = function(){
  86. if (!!pageJson && loadModuleFlag){
  87. this.pageJson = pageJson;
  88. layout.sessionPromise.finally(function(){
  89. this.pageInfor = pageJson.data;
  90. this.setTitle(this.portal.name+"-"+pageJson.data.name);
  91. var page = (pageJson.data.data) ? JSON.decode(MWF.decodeJsonString(pageJson.data.data)): null;
  92. if (page){
  93. this.options.pageId = pageJson.data.id;
  94. if (this.appForm) this.appForm.fireEvent("beforeClose");
  95. Object.keys(this.$events).each(function(k){
  96. this.removeEvents(k);
  97. }.bind(this));
  98. MWF.release(this.appForm);
  99. this.appForm = null;
  100. this.formNode.empty();
  101. this.page = page;
  102. this.openPortal(par);
  103. }
  104. }.bind(this));
  105. }
  106. }.bind(this);
  107. if (name){
  108. var m = (layout.mobile) ? "getPageByNameMobile" : "getPageByName";
  109. this.action[m](name, this.portal.id, function(json){
  110. pageJson = json;
  111. check();
  112. }.bind(this));
  113. var cl = "$all";
  114. MWF.xDesktop.requireApp("process.Xform", cl, function(){
  115. loadModuleFlag = true;
  116. check();
  117. });
  118. }else{
  119. if (this.options.pageId){
  120. var m = (layout.mobile) ? "getPageByNameMobile" : "getPageByName";
  121. this.action[m](this.options.pageId, this.portal.id, function(json){
  122. pageJson = json;
  123. check();
  124. }.bind(this));
  125. MWF.xDesktop.requireApp("process.Xform", "$all", function(){
  126. loadModuleFlag = true;
  127. check();
  128. });
  129. }
  130. }
  131. },
  132. loadPortal: function(par, callback){
  133. if (this.options.pageId || this.options.widgetId){
  134. this.loadPortalPage(par, callback);
  135. this.getPageData();
  136. }else{
  137. this.getPageData(function(json){
  138. this.options.pageId = this.portal.firstPage;
  139. this.loadPortalPage();
  140. }.bind(this));
  141. }
  142. },
  143. openPage: function(pageJson, par, callback){
  144. this.setTitle((this.portal && this.portal.name) ? this.portal.name+"-"+pageJson.data.page.name : pageJson.data.page.name);
  145. if (pageJson.data.page){
  146. this.page = (pageJson.data.page.data) ? JSON.decode(MWF.decodeJsonString(pageJson.data.page.data)): null;
  147. this.relatedFormMap = pageJson.data.relatedWidgetMap;
  148. this.relatedScriptMap = pageJson.data.relatedScriptMap;
  149. delete pageJson.data.page.data;
  150. this.pageInfor = pageJson.data.page;
  151. }else{
  152. this.page = (pageJson.data.data) ? JSON.decode(MWF.decodeJsonString(pageJson.data.data)): null;
  153. delete pageJson.data.data;
  154. this.pageInfor = pageJson.data;
  155. }
  156. this.openPortal(par, callback);
  157. },
  158. loadPortalPage: function(par, callback){
  159. var pageJson = null;
  160. var loadModuleFlag = false;
  161. var check = function(){
  162. if (!!pageJson && loadModuleFlag){
  163. this.pageJson = pageJson;
  164. layout.sessionPromise.then(function(){
  165. this.openPage(pageJson, par, callback);
  166. }.bind(this), function(){
  167. this.openPage(pageJson, par, callback);
  168. }.bind(this));
  169. }
  170. }.bind(this);
  171. var m;
  172. if( this.options.widgetId ){
  173. m = (layout.mobile) ? "getWidgetByNameMobile" : "getWidgetByName";
  174. }else{
  175. m = (layout.mobile) ? "getPageByNameMobileV2" : "getPageByNameV2";
  176. }
  177. this.action[m]( this.options.widgetId || this.options.pageId, this.options.portalId, function(json){
  178. pageJson = json;
  179. check();
  180. }.bind(this));
  181. MWF.xDesktop.requireApp("process.Xform", "$all", function(){
  182. loadModuleFlag = true;
  183. check();
  184. });
  185. },
  186. getPageData: function(callback){
  187. if (this.portal){
  188. if (callback) callback(this.portal);
  189. return ;
  190. }
  191. this.action.getApplication(this.options.portalId, function(json){
  192. this.portal = json.data;
  193. if (this.pageJson) this.setTitle(this.portal.name+"-"+this.pageJson.data.page.name);
  194. if (this.portal.icon){
  195. if (this.taskitem){
  196. this.taskitem.iconNode.setStyles({
  197. "background-image": "url(data:image/png;base64,"+this.portal.icon+")",
  198. "background-size": "24px 24px"
  199. });
  200. }
  201. }
  202. if (callback) callback(json)
  203. }.bind(this));
  204. },
  205. openPortal: function(par, callback){
  206. debugger;
  207. if (this.page){
  208. //MWF.xDesktop.requireApp("process.Xform", "Form", function(){
  209. this.appForm = new MWF.APPForm(this.formNode, this.page, {
  210. "macro": "PageContext",
  211. "parameters": par
  212. });
  213. this.appForm.businessData = {
  214. "control": {
  215. "allowSave": true
  216. },
  217. "pageInfor": this.pageInfor,
  218. "data": {}
  219. };
  220. this.appForm.workAction = this.action;
  221. this.appForm.app = this;
  222. this.appForm.load();
  223. if (callback) callback();
  224. if (this.mask) this.mask.hide();
  225. //}.bind(this));
  226. }
  227. },
  228. recordStatus: function(){
  229. return {"portalId": this.options.portalId, "pageId": this.options.pageId, "parameters" : this.options.parameters};
  230. },
  231. onPostClose: function(){
  232. if (this.appForm){
  233. this.appForm.modules.each(function(module){
  234. MWF.release(module);
  235. });
  236. MWF.release(this.appForm);
  237. }
  238. }
  239. });