forum.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. layout = window.layout || {};
  2. layout.desktop = layout;
  3. var href = window.location.href;
  4. if (href.indexOf("debugger")!=-1) layout.debugger = true;
  5. COMMON.DOM.addReady(function(){
  6. COMMON.AjaxModule.load("/x_desktop/res/framework/mootools/plugin/mBox.Notice.js", null, false);
  7. COMMON.AjaxModule.load("/x_desktop/res/framework/mootools/plugin/mBox.Tooltip.js", null, false);
  8. COMMON.setContentPath("/x_desktop");
  9. COMMON.AjaxModule.load("mwf", function(){
  10. MWF.defaultPath = "/x_desktop"+MWF.defaultPath;
  11. MWF.loadLP("zh-cn");
  12. MWF.require("MWF.widget.Mask", null, false);
  13. layout.mask = new MWF.widget.Mask({"style": "desktop"});
  14. layout.mask.load();
  15. MWF.require("MWF.xDesktop.Layout", function(){
  16. MWF.require("MWF.xDesktop.Authentication", null, false);
  17. MWF.xDesktop.requireApp("Common", "", null, false);
  18. (function(){
  19. layout.requireApp = function(appNames, callback, clazzName){
  20. var appPath = appNames.split(".");
  21. var appName = appPath[appPath.length-1];
  22. var appObject = "MWF.xApplication."+appNames;
  23. var className = clazzName || "Main";
  24. var appClass = appObject+"."+className;
  25. var appLp = appObject+".lp."+MWF.language;
  26. var baseObject = MWF.xApplication;
  27. appPath.each(function(path, i){
  28. if (i<(appPath.length-1)){
  29. baseObject[path] = baseObject[path] || {};
  30. }else {
  31. baseObject[path] = baseObject[path] || {"options": Object.clone(MWF.xApplication.Common.options)};
  32. }
  33. baseObject = baseObject[path];
  34. }.bind(this));
  35. if (!baseObject.options) baseObject.options = Object.clone(MWF.xApplication.Common.options);
  36. MWF.xDesktop.requireApp(appNames, "lp."+MWF.language, null, false);
  37. MWF.xDesktop.requireApp(appNames, clazzName, function(){
  38. if (callback) callback(baseObject);
  39. });
  40. //
  41. //MWF.require(appLp, null, false);
  42. //MWF.require(appClass, function(){
  43. // if (callback) callback(baseObject);
  44. //});
  45. };
  46. layout.openApplication = function(e, appNames, options, status){
  47. var id;
  48. if (layout.app){
  49. //layout.desktop.openBrowserApp = appNames;
  50. //layout.desktop.openBrowserStatus = status;
  51. //layout.desktop.openBrowserOption = options;
  52. if( !appNames || appNames == "Forum"){
  53. id = options.id;
  54. }else if(appNames=="ForumCategory"){
  55. id = options.categoryId;
  56. }else if(appNames=="ForumDocument"){
  57. id = options.id;
  58. }else if(appNames=="ForumPerson"){
  59. //var id = encodeURI( options.personName );
  60. }else if(appNames=="ForumSearch"){
  61. }else if(appNames=="ForumSection"){
  62. id = options.sectionId;
  63. }
  64. //sessionStorage.setItem(appNames+id+"options", options);
  65. //sessionStorage.getItem( appName+id+"status", status );
  66. sessionStorage[appNames+(id ? id : "")+"options"] = JSON.stringify( options );
  67. sessionStorage[appName+(id ? id : "")+"status"] = JSON.stringify( status );
  68. if( layout.debugger ){
  69. window.open("forum.html?debugger&app="+appNames+ ( id ? "&id="+id : ""), "_blank");
  70. }else{
  71. window.open("forum.html?app="+appNames+ ( id ? "&id="+id : ""), "_blank");
  72. }
  73. }else{
  74. var appPath = appNames.split(".");
  75. var appName = appPath[appPath.length-1];
  76. layout.requireApp(appNames, function(appNamespace){
  77. this.createNewApplication(e, appNamespace, appName, options, status);
  78. }.bind(this));
  79. }
  80. };
  81. layout.createNewApplication = function(e, appNamespace, appName, options, status){
  82. var app = new appNamespace["Main"](this, options);
  83. app.desktop = layout;
  84. app.inBrowser = true;
  85. app.status = status;
  86. app.load(true);
  87. var appId = appName;
  88. if (options.appId){
  89. appId = options.appId;
  90. }else{
  91. if (appNamespace.options.multitask) appId = appId+"-"+(new MWF.widget.UUID());
  92. }
  93. app.appId = appId;
  94. layout.app = app;
  95. };
  96. layout.load = function(){
  97. MWF.require("MWF.xDesktop.MessageMobile", function(){
  98. layout.message = new MWF.xDesktop.MessageMobile();
  99. layout.message.load();
  100. }.bind(this));
  101. this.isAuthentication(function(){
  102. layout.apps = [];
  103. this.node = $("layout");
  104. //var topWindow = window.opener;
  105. //if (topWindow){
  106. //
  107. // var appName = topWindow.layout.desktop.openBrowserApp;
  108. // var status = topWindow.layout.desktop.openBrowserStatus;
  109. // var option = topWindow.layout.desktop.openBrowserOption;
  110. // layout.openApplication(null, appName, option||{}, status);
  111. //}
  112. //sessionStorage.getItem()
  113. var option = {};
  114. var status;
  115. var urlParams = layout.getUrlParam();
  116. if( urlParams.app ){
  117. var appName = urlParams.app;
  118. var id = urlParams.id;
  119. //alert(sessionStorage.getItem( appName+id+"options").id)
  120. //alert(sessionStorage.getItem( appName+id+"status").id)
  121. option = sessionStorage[ appName+ (id ? id : "") +"options" ];
  122. if(option){
  123. option = JSON.parse(option)
  124. }else if(id){
  125. if( appName == "ForumCategory" ) {
  126. option = {categoryId: id};
  127. }else if( appName=="ForumSection" ){
  128. option = {sectionId: id};
  129. }else if( appName=="ForumDocument" ){
  130. option = {
  131. isNew : false,
  132. isEdited : false,
  133. id: id
  134. };
  135. }else{
  136. option = {id : id};
  137. }
  138. }
  139. status = sessionStorage[ appName+ (id ? id : "") +"status" ];
  140. if(status){
  141. status = JSON.parse(option)
  142. }
  143. }else{
  144. var appName = "Forum";
  145. }
  146. layout.openApplication(null, appName, option, status);
  147. layout.mask.hide();
  148. }.bind(this));
  149. };
  150. layout.getUrlParam = function(){
  151. var href = window.location.href;
  152. var qStr = href.substr(href.indexOf("?")+1, href.length);
  153. var qDatas = qStr.split("&");
  154. var obj = {};
  155. qDatas.each(function(d){
  156. var q = d.split("=");
  157. obj[q[0]] = q[1];
  158. });
  159. return obj;
  160. };
  161. //layout.getServiceAddress = function(callback){
  162. // var host = layout.config.center.host || window.location.hostname;
  163. // var port = layout.config.center.port;
  164. // var uri = "";
  165. // if (!port || port=="80"){
  166. // uri = "http://"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  167. // }else{
  168. // uri = "http://"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  169. // }
  170. // var currenthost = window.location.hostname;
  171. // uri = uri.replace(/{source}/g, currenthost);
  172. // //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
  173. // MWF.restful("get", uri, null, function(json){
  174. // this.serviceAddressList = json.data;
  175. // if (callback) callback();
  176. // }.bind(this));
  177. //};
  178. layout.getServiceAddress = function(callback){
  179. if (typeOf(layout.config.center)=="object"){
  180. this.getServiceAddressConfigObject(callback);
  181. }else if (typeOf(layout.config.center)=="array"){
  182. this.getServiceAddressConfigArray(callback);
  183. }
  184. };
  185. layout.getServiceAddressConfigArray = function(callback) {
  186. var requests = [];
  187. layout.config.center.each(function(center){
  188. requests.push(
  189. this.getServiceAddressConfigObject(function(){
  190. requests.each(function(res){
  191. if (res.isRunning()){res.cancel();}
  192. });
  193. if (callback) callback();
  194. }.bind(this), center)
  195. );
  196. }.bind(this));
  197. };
  198. layout.getServiceAddressConfigObject = function(callback, center){
  199. var centerConfig = center;
  200. if (!centerConfig) centerConfig = layout.config.center;
  201. var host = centerConfig.host || window.location.hostname;
  202. var port = centerConfig.port;
  203. var uri = "";
  204. if (!port || port=="80"){
  205. uri = "http://"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  206. }else{
  207. uri = "http://"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  208. }
  209. var currenthost = window.location.hostname;
  210. uri = uri.replace(/{source}/g, currenthost);
  211. //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
  212. return MWF.restful("get", uri, null, function(json){
  213. this.serviceAddressList = json.data;
  214. this.centerServer = center;
  215. if (callback) callback();
  216. }.bind(this));
  217. };
  218. layout.isAuthentication = function(callback){
  219. this.authentication = new MWF.xDesktop.Authentication({
  220. "onLogin": layout.load.bind(layout)
  221. });
  222. var returnValue = true;
  223. this.authentication.isAuthenticated(function(json){
  224. this.user = json.data;
  225. this.session = {};
  226. this.session.user = json.data;
  227. if (callback) callback();
  228. }.bind(this), function(){
  229. //this.authentication.loadLogin(this.node);
  230. //returnValue = false;
  231. this.user = "anonymous";
  232. this.session = {};
  233. this.session.user = {
  234. name : this.user,
  235. roleList : []
  236. };
  237. if (callback) callback();
  238. returnValue = false;
  239. }.bind(this));
  240. return returnValue;
  241. };
  242. MWF.getJSON("res/config/config.json", function(config){
  243. layout.config = config;
  244. layout.getServiceAddress(function(){
  245. layout.load();
  246. });
  247. });
  248. })();
  249. });
  250. });
  251. });