Main.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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){
  59. this.options.portalId = portal;
  60. this.options.pageId = page;
  61. if (this.appForm) this.appForm.fireEvent("beforeClose");
  62. Object.keys(this.$events).each(function(k){
  63. this.removeEvents(k);
  64. }.bind(this));
  65. MWF.release(this.appForm);
  66. this.appForm = null;
  67. this.formNode.empty();
  68. this.loadPortal(par);
  69. },
  70. toPage: function(name, par){
  71. if (name){
  72. var m = (layout.mobile) ? "getPageByNameMobile" : "getPageByName";
  73. this.action[m](name, this.portal.id, function(json){
  74. this.pageInfor = json.data;
  75. this.setTitle(this.portal.name+"-"+json.data.name);
  76. var page = (json.data.data) ? JSON.decode(MWF.decodeJsonString(json.data.data)): null;
  77. if (page){
  78. this.options.pageId = json.data.id;
  79. if (this.appForm) this.appForm.fireEvent("beforeClose");
  80. Object.keys(this.$events).each(function(k){
  81. this.removeEvents(k);
  82. }.bind(this));
  83. MWF.release(this.appForm);
  84. this.appForm = null;
  85. this.formNode.empty();
  86. this.page = page;
  87. this.openPortal(par);
  88. }
  89. }.bind(this));
  90. }else{
  91. if (this.options.pageId){
  92. var m = (layout.mobile) ? "getPageByNameMobile" : "getPageByName";
  93. this.action[m](this.options.pageId, this.portal.id, function(json){
  94. this.pageInfor = json.data;
  95. this.setTitle(this.portal.name+"-"+json.data.name);
  96. var page = (json.data.data) ? JSON.decode(MWF.decodeJsonString(json.data.data)): null;
  97. if (page){
  98. this.options.pageId = json.data.id;
  99. if (this.appForm) this.appForm.fireEvent("beforeClose");
  100. Object.keys(this.$events).each(function(k){
  101. this.removeEvents(k);
  102. }.bind(this));
  103. MWF.release(this.appForm);
  104. this.appForm = null;
  105. this.formNode.empty();
  106. this.page = page;
  107. this.openPortal(par);
  108. }
  109. }.bind(this));
  110. }
  111. }
  112. },
  113. loadPortal: function(par, callback){
  114. this.action.getApplication(this.options.portalId, function(json){
  115. this.portal = json.data;
  116. this.setTitle(this.portal.name);
  117. if (!this.options.pageId) this.options.pageId = this.portal.firstPage;
  118. if (this.portal.icon){
  119. if (this.taskitem){
  120. this.taskitem.iconNode.setStyles({
  121. "background-image": "url(data:image/png;base64,"+this.portal.icon+")",
  122. "background-size": "24px 24px"
  123. });
  124. }
  125. }
  126. var m;
  127. if( this.options.widgetId ){
  128. m = (layout.mobile) ? "getWidgetByNameMobile" : "getWidgetByName";
  129. }else{
  130. m = (layout.mobile) ? "getPageByNameMobile" : "getPageByName";
  131. }
  132. this.action[m]( this.options.widgetId || this.options.pageId, this.options.portalId, function(json){
  133. // if (layout.mobile) {
  134. // this.page = (json.data.mobileData) ? JSON.decode(MWF.decodeJsonString(json.data.mobileData)): null;
  135. // if (!this.page || !this.page.json.moduleList.length){
  136. // this.page = (json.data.data) ? JSON.decode(MWF.decodeJsonString(json.data.data)): null;
  137. // }
  138. // }else{
  139. this.setTitle(this.portal.name+"-"+json.data.name);
  140. this.page = (json.data.data) ? JSON.decode(MWF.decodeJsonString(json.data.data)): null;
  141. this.pageInfor = json.data;
  142. // }
  143. this.openPortal(par, callback);
  144. }.bind(this));
  145. }.bind(this));
  146. },
  147. openPortal: function(par, callback){
  148. if (this.page){
  149. MWF.xDesktop.requireApp("process.Xform", "Form", function(){
  150. this.appForm = new MWF.APPForm(this.formNode, this.page, {
  151. "macro": "PageContext",
  152. "parameters": par
  153. });
  154. this.appForm.businessData = {
  155. "control": {
  156. "allowSave": true
  157. },
  158. "pageInfor": this.pageInfor,
  159. "data": {}
  160. };
  161. this.appForm.workAction = this.action;
  162. this.appForm.app = this;
  163. this.appForm.load();
  164. if (callback) callback();
  165. if (this.mask) this.mask.hide();
  166. }.bind(this));
  167. }
  168. },
  169. recordStatus: function(){
  170. return {"portalId": this.options.portalId, "pageId": this.options.pageId};
  171. },
  172. onPostClose: function(){
  173. if (this.appForm){
  174. this.appForm.modules.each(function(module){
  175. MWF.release(module);
  176. });
  177. MWF.release(this.appForm);
  178. }
  179. }
  180. });