PortalPage.js 6.4 KB

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