forum.js 14 KB

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