Main.js 8.5 KB

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