PortalPage.js 6.5 KB

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