Main.js 12 KB

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