Main.js 7.8 KB

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