TopNode.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /**
  2. * Created by CXY on 2017/5/8.
  3. */
  4. MWF.xApplication.Forum.TopNode = new Class({
  5. Extends: MWF.widget.Common,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "settingEnable" : false,
  10. "logoutEnable" : true,
  11. "naviModeEnable" : false
  12. },
  13. initialize : function( container, app, explorer, options ){
  14. this.setOptions(options);
  15. this.container = container;
  16. this.app = app;
  17. this.lp = app.lp;
  18. this.restActions = app.restActions;
  19. this.access = app.access;
  20. this.explorer = explorer;
  21. this.userName = layout.desktop.session.user.distinguishedName || "";
  22. this.displayName = MWFForum.getDisplayName();
  23. this.path = "../x_component_Forum/$TopNode/";
  24. this.cssPath = "../x_component_Forum/$TopNode/" + this.options.style + "/css.wcss";
  25. this._loadCss();
  26. },
  27. load: function(){
  28. this.createTopNode();
  29. },
  30. getMainPageTitle : function(){
  31. var tail = this.app.inBrowser ? (MWFForum.getSystemConfigValue( MWFForum.BBS_TITLE_TAIL ) || "") : "";
  32. return ( MWFForum.getBBSName() || MWF.xApplication.Forum.LP.title ) + tail;
  33. },
  34. openMainPage : function(){
  35. if( this.app.inBrowser || this.options.naviMode ){
  36. this.app.clearContent();
  37. if(this.app.node)this.app.node.destroy();
  38. MWF.xDesktop.requireApp("Forum", "MainInContainer", null, false);
  39. var forum = new MWF.xApplication.Forum.MainInContainer( this.app.desktop, {
  40. "hasTop" : true,
  41. "hasBreadCrumb" : true,
  42. "naviMode" : false,
  43. "autoWidth" : false
  44. }, this.app.content, this.app.content , this.app.content );
  45. forum.inBrowser = this.app.inBrowser;
  46. forum.window = this.app.window;
  47. forum.taskitem = this.app.taskitem;
  48. forum.load();
  49. this.app.setTitle( this.getMainPageTitle() );
  50. }else{
  51. var appId = "Forum";
  52. if (this.app.desktop.apps[appId]){
  53. var app = this.app.desktop.apps[appId];
  54. app.setCurrent();
  55. app.clearContent();
  56. app.loadApplicationLayout();
  57. }else {
  58. this.app.desktop.openApplication(null, "Forum", { "appId": appId });
  59. this.app.close();
  60. }
  61. }
  62. },
  63. createTopNode: function () {
  64. this.topContainerNode = new Element("div.topContainerNode", {
  65. "styles": this.css.topContainerNode
  66. }).inject(this.container);
  67. this.topNode = new Element("div.topNode", {
  68. "styles": this.css.topNode
  69. }).inject(this.topContainerNode);
  70. this.topMainPageNode = new Element("div.topMainPageNode",{
  71. "styles" : { "cursor" : "pointer" }
  72. }).inject(this.topNode);
  73. this.topMainPageNode.addEvent("click", function(){
  74. this.openMainPage();
  75. }.bind(this));
  76. //this.getSystemSetting( "BBS_LOGO_NAME", function( data ){
  77. this.restActions.getBBSName( function( json ){
  78. var data = json.data;
  79. if( data.configValue && data.configValue!="" && data.configValue!="O2社区" ){
  80. this.bbsName = data.configValue;
  81. this.topTextNode = new Element("div.topTextNode", {
  82. "styles": this.css.topTextNode,
  83. "text": data.configValue
  84. }).inject(this.topMainPageNode)
  85. }else{
  86. this.topIconNode = new Element("div", {
  87. "styles": this.css.topIconNode
  88. }).inject(this.topMainPageNode)
  89. }
  90. }.bind(this), null, false );
  91. //}.bind(this), false )
  92. this.topContentNode = new Element("div", {
  93. "styles": this.css.topContentNode
  94. }).inject(this.topNode);
  95. if( this.access.isAnonymous() ){
  96. if( this.access.signUpMode != "disable" ){
  97. this.signupNode = new Element("div", {
  98. "styles": this.css.signupNode
  99. }).inject(this.topContentNode);
  100. //this.signupIconNode = new Element("div", {
  101. // "styles": this.css.signupIconNode
  102. //}).inject(this.signupNode);
  103. this.signupTextNode = new Element("div", {
  104. "styles": this.css.signupTextNode,
  105. "text": this.lp.signup
  106. }).inject(this.signupNode);
  107. this.signupNode.addEvent("click", function(){ this.openSignUpForm( ) }.bind(this));
  108. new Element("div",{
  109. "styles" : this.css.topSepNode,
  110. "text" : "|"
  111. }).inject(this.topContentNode);
  112. }
  113. this.loginNode = new Element("div", {
  114. "styles": this.css.loginNode
  115. }).inject(this.topContentNode);
  116. //this.loginIconNode = new Element("div", {
  117. // "styles": this.css.loginIconNode
  118. //}).inject(this.loginNode);
  119. this.loginTextNode = new Element("div", {
  120. "styles": this.css.loginTextNode,
  121. "text": this.lp.login
  122. }).inject(this.loginNode);
  123. this.loginNode.addEvent("click", function(){ this.openLoginForm( ) }.bind(this));
  124. if( this.options.naviModeEnable ){
  125. new Element("div",{
  126. "styles" : this.css.topSepNode,
  127. "text" : "|"
  128. }).inject(this.topContentNode);
  129. this.loadNaviNode();
  130. }
  131. }else{
  132. if( this.app.inBrowser && this.options.logoutEnable ){
  133. this.logoutNode = new Element("div", {
  134. "styles": this.css.logoutNode
  135. }).inject(this.topContentNode);
  136. //this.logoutIconNode = new Element("div", {
  137. // "styles": this.css.logoutIconNode
  138. //}).inject(this.logoutNode);
  139. this.logoutTextNode = new Element("div", {
  140. "styles": this.css.logoutTextNode,
  141. "text": this.lp.logout
  142. }).inject(this.logoutNode);
  143. this.logoutNode.addEvent("click", function(){ this.logout( ) }.bind(this));
  144. new Element("div",{
  145. "styles" : this.css.topSepNode,
  146. "text" : "|"
  147. }).inject(this.topContentNode);
  148. }
  149. if( this.options.settingEnable ){
  150. this.settingArea = new Element("div", {
  151. styles : { float : "right" }
  152. }).inject(this.topContentNode);
  153. this.access.getUserPermission(function (permission) {
  154. if( this.access.isAdmin() || permission.bbsAdmin || permission.bbsForumAdmin || permission.bbsSectionAdmin ){
  155. this.settingNode = new Element("div", {
  156. "styles": this.css.settingNode
  157. }).inject(this.settingArea);
  158. //this.settingIconNode = new Element("div", {
  159. // "styles": this.css.settingIconNode
  160. //}).inject(this.settingNode);
  161. this.settingTextNode = new Element("div", {
  162. "styles": this.css.settingTextNode,
  163. "text": this.lp.setting,
  164. "title" : this.lp.forumConfig
  165. }).inject(this.settingNode);
  166. this.settingNode.addEvent("click", function(){ this.app.openSetting( ) }.bind(this));
  167. new Element("div", {
  168. "styles": this.css.topSepNode,
  169. "text": "|"
  170. }).inject(this.settingArea);
  171. }else{
  172. this.settingArea.hide();
  173. }
  174. }.bind(this))
  175. }
  176. if( this.options.naviModeEnable ){
  177. this.loadNaviNode();
  178. new Element("div", {
  179. "styles": this.css.topSepNode,
  180. "text": "|"
  181. }).inject(this.topContentNode);
  182. }
  183. this.personNode = new Element("div", {
  184. "styles": this.css.personNode
  185. }).inject(this.topContentNode);
  186. //this.personIconNode = new Element("div", {
  187. // "styles": this.css.personIconNode
  188. //}).inject(this.personNode);
  189. this.personTextNode = new Element("div", {
  190. "styles": this.css.personTextNode,
  191. "text": MWF.xApplication.Forum.LP.welcomeTitle.replace("{user}", ( this.displayName || "").split("@")[0]),
  192. "title" : MWF.xApplication.Forum.LP.seePersonCenter
  193. }).inject(this.personNode);
  194. this.personNode.addEvent("click", function(){ this.openPerson(this.userName ) }.bind(this))
  195. }
  196. this.searchDiv = new Element("div.searchDiv",{
  197. "styles" : this.css.searchDiv
  198. }).inject(this.topNode);
  199. this.searchInput = new Element("input.searchInput",{
  200. "styles" : this.css.searchInput,
  201. "value" : this.lp.searchKey,
  202. "title" : MWFForum.isUseNickName() ? this.lp.searchTitleNick : this.lp.searchTitle
  203. }).inject(this.searchDiv);
  204. var _self = this;
  205. this.searchInput.addEvents({
  206. "focus": function(){
  207. if (this.value==_self.lp.searchKey) this.set("value", "");
  208. },
  209. "blur": function(){if (!this.value) this.set("value", _self.lp.searchKey);},
  210. "keydown": function(e){
  211. if (e.code==13){
  212. this.search();
  213. e.preventDefault();
  214. }
  215. }.bind(this)
  216. });
  217. this.searchAction = new Element("div.searchAction",{
  218. "styles" : this.css.searchAction
  219. }).inject(this.searchDiv);
  220. this.searchAction.addEvents({
  221. "click": function(){ this.search(); }.bind(this),
  222. "mouseover": function(e){
  223. this.searchAction.setStyles( this.css.searchAction_over2 );
  224. e.stopPropagation();
  225. }.bind(this),
  226. "mouseout": function(){ this.searchAction.setStyles( this.css.searchAction ) }.bind(this)
  227. });
  228. this.searchDiv.addEvents( {
  229. "mouseover" : function(){
  230. this.searchInput.setStyles( this.css.searchInput_over );
  231. this.searchAction.setStyles( this.css.searchAction_over )
  232. }.bind(this),
  233. "mouseout" : function(){
  234. this.searchInput.setStyles( this.css.searchInput );
  235. this.searchAction.setStyles( this.css.searchAction )
  236. }.bind(this)
  237. });
  238. this._createTopContent();
  239. },
  240. loadNaviNode : function(){
  241. if( this.options.naviModeEnable ){
  242. this.naviNode = new Element("div", {
  243. "styles": this.css.settingNode
  244. }).inject(this.topContentNode);
  245. if( this.options.naviMode ){
  246. this.closeNaviTextNode = new Element("div", {
  247. "styles": this.css.settingTextNode,
  248. "text": MWF.xApplication.Forum.LP.closeNavi,
  249. "title" : MWF.xApplication.Forum.LP.closeNavi
  250. }).inject(this.naviNode);
  251. this.closeNaviTextNode.addEvent("click", function(){ this.app.closeNavi( ) }.bind(this));
  252. }else{
  253. this.naviTextNode = new Element("div", {
  254. "styles": this.css.settingTextNode,
  255. "text": MWF.xApplication.Forum.LP.navi,
  256. "title" : MWF.xApplication.Forum.LP.naviLayout
  257. }).inject(this.naviNode);
  258. this.naviTextNode.addEvent("click", function(){
  259. this.app.openNavi( )
  260. }.bind(this));
  261. }
  262. }
  263. },
  264. _createTopContent: function () {
  265. },
  266. getSystemSetting : function( code, callback, async ){
  267. this.restActions.getSystemSettingByCode( {configCode : code }, function(json) {
  268. if (callback)callback(json.data);
  269. }.bind(this), null, async )
  270. },
  271. search : function(){
  272. var val = this.searchInput.get("value");
  273. if( val == "" || val == this.lp.searchKey ){
  274. this.notice( this.lp.noSearchContentNotice, "error" );
  275. return;
  276. }
  277. var appId = "ForumSearch";
  278. if( this.app.options.name == "ForumSearch" ){
  279. this.app.search( val );
  280. }else if (this.app.desktop.apps[appId] && !this.app.inBrowser){
  281. var app = this.app.desktop.apps[appId];
  282. app.setCurrent();
  283. app.search( val );
  284. }else{
  285. this.app.desktop.openApplication(null, "ForumSearch", {
  286. "appId": appId,
  287. "searchContent" : val
  288. });
  289. }
  290. },
  291. openPerson : function( userName, data ){
  292. MWFForum.openPersonCenter( userName, data );
  293. },
  294. openLoginForm : function(){
  295. MWF.require("MWF.xDesktop.Authentication", null, false);
  296. var authentication = new MWF.xDesktop.Authentication({
  297. "style" : "flat",
  298. "popupStyle_password": "o2platformSignupFlat",
  299. onPostOk : function(){
  300. window.location.reload();
  301. }
  302. },this.app);
  303. authentication.popupOptions = {
  304. "draggable": true,
  305. "closeAction": true,
  306. "hasMask": true,
  307. "relativeToApp": true,
  308. "width": "420",
  309. "height": "640"
  310. };
  311. // authentication.loadLogin(this.app.content);
  312. authentication.openLoginForm();
  313. },
  314. openSignUpForm : function(){
  315. MWF.require("MWF.xDesktop.Authentication", null, false);
  316. var authentication = new MWF.xDesktop.Authentication( {
  317. style : "flat",
  318. "popupStyle_password": "o2platformSignupFlat",
  319. onPostOk : function(){
  320. }
  321. }, this.app);
  322. authentication.popupOptions = {
  323. "draggable": true,
  324. "closeAction": true,
  325. "hasMask": true,
  326. "relativeToApp": true,
  327. "width": "420",
  328. "height": "640"
  329. };
  330. authentication.openSignUpForm();
  331. },
  332. logout: function(){
  333. MWF.Actions.get("x_organization_assemble_authentication").logout(function () {
  334. if (this.socket) {
  335. this.socket.close();
  336. this.socket = null;
  337. }
  338. Cookie.dispose(o2.tokenName);
  339. if (layout.session && layout.session.user) layout.session.user.token = "";
  340. layout.desktop.session.user.distinguishedName = "anonymous";
  341. this.app.clearContent();
  342. this.app.loadApplicationContent();
  343. this.openLoginForm();
  344. // if( callback ){
  345. // callback()
  346. // }else{
  347. // window.location.reload();
  348. // }
  349. }.bind(this));
  350. }
  351. });