forum.js 14 KB

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