TopNode.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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.path = "/x_component_Forum/$TopNode/";
  23. this.cssPath = "/x_component_Forum/$TopNode/" + this.options.style + "/css.wcss";
  24. this._loadCss();
  25. },
  26. load: function(){
  27. this.createTopNode();
  28. },
  29. getMainPageTitle : function(){
  30. var tail = this.app.inBrowser ? (MWFForum.getSystemConfigValue( MWFForum.BBS_TITLE_TAIL ) || "") : "";
  31. return ( MWFForum.getBBSName() || MWF.xApplication.Forum.LP.title ) + tail;
  32. },
  33. openMainPage : function(){
  34. if( this.app.inBrowser || this.options.naviMode ){
  35. this.app.clearContent();
  36. if(this.app.node)this.app.node.destroy();
  37. MWF.xDesktop.requireApp("Forum", "MainInContainer", null, false);
  38. var forum = new MWF.xApplication.Forum.MainInContainer( this.app.desktop, {
  39. "hasTop" : true,
  40. "hasBreadCrumb" : true,
  41. "naviMode" : false,
  42. "autoWidth" : false
  43. }, this.app.content, this.app.content , this.app.content );
  44. forum.inBrowser = this.app.inBrowser;
  45. forum.window = this.app.window;
  46. forum.taskitem = this.app.taskitem;
  47. forum.load();
  48. this.app.setTitle( this.getMainPageTitle() );
  49. }else{
  50. var appId = "Forum";
  51. if (this.app.desktop.apps[appId]){
  52. var app = this.app.desktop.apps[appId];
  53. app.setCurrent();
  54. app.clearContent();
  55. app.loadApplicationLayout();
  56. }else {
  57. this.app.desktop.openApplication(null, "Forum", { "appId": appId });
  58. this.app.close();
  59. }
  60. }
  61. },
  62. createTopNode: function () {
  63. this.topContainerNode = new Element("div.topContainerNode", {
  64. "styles": this.css.topContainerNode
  65. }).inject(this.container);
  66. this.topNode = new Element("div.topNode", {
  67. "styles": this.css.topNode
  68. }).inject(this.topContainerNode);
  69. this.topMainPageNode = new Element("div.topMainPageNode",{
  70. "styles" : { "cursor" : "pointer" }
  71. }).inject(this.topNode);
  72. this.topMainPageNode.addEvent("click", function(){
  73. this.openMainPage();
  74. }.bind(this));
  75. //this.getSystemSetting( "BBS_LOGO_NAME", function( data ){
  76. this.restActions.getBBSName( function( json ){
  77. var data = json.data;
  78. if( data.configValue && data.configValue!="" && data.configValue!="O2社区" ){
  79. this.bbsName = data.configValue;
  80. this.topTextNode = new Element("div.topTextNode", {
  81. "styles": this.css.topTextNode,
  82. "text": data.configValue
  83. }).inject(this.topMainPageNode)
  84. }else{
  85. this.topIconNode = new Element("div", {
  86. "styles": this.css.topIconNode
  87. }).inject(this.topMainPageNode)
  88. }
  89. }.bind(this), null, false );
  90. //}.bind(this), false )
  91. this.topContentNode = new Element("div", {
  92. "styles": this.css.topContentNode
  93. }).inject(this.topNode);
  94. if( this.access.isAnonymous() ){
  95. if( this.access.signUpMode != "disable" ){
  96. this.signupNode = new Element("div", {
  97. "styles": this.css.signupNode
  98. }).inject(this.topContentNode);
  99. //this.signupIconNode = new Element("div", {
  100. // "styles": this.css.signupIconNode
  101. //}).inject(this.signupNode);
  102. this.signupTextNode = new Element("div", {
  103. "styles": this.css.signupTextNode,
  104. "text": this.lp.signup
  105. }).inject(this.signupNode);
  106. this.signupNode.addEvent("click", function(){ this.openSignUpForm( ) }.bind(this));
  107. new Element("div",{
  108. "styles" : this.css.topSepNode,
  109. "text" : "|"
  110. }).inject(this.topContentNode);
  111. }
  112. this.loginNode = new Element("div", {
  113. "styles": this.css.loginNode
  114. }).inject(this.topContentNode);
  115. //this.loginIconNode = new Element("div", {
  116. // "styles": this.css.loginIconNode
  117. //}).inject(this.loginNode);
  118. this.loginTextNode = new Element("div", {
  119. "styles": this.css.loginTextNode,
  120. "text": this.lp.login
  121. }).inject(this.loginNode);
  122. this.loginNode.addEvent("click", function(){ this.openLoginForm( ) }.bind(this));
  123. if( this.options.naviModeEnable ){
  124. new Element("div",{
  125. "styles" : this.css.topSepNode,
  126. "text" : "|"
  127. }).inject(this.topContentNode);
  128. this.loadNaviNode();
  129. }
  130. }else{
  131. if( this.app.inBrowser && this.options.logoutEnable ){
  132. this.logoutNode = new Element("div", {
  133. "styles": this.css.logoutNode
  134. }).inject(this.topContentNode);
  135. //this.logoutIconNode = new Element("div", {
  136. // "styles": this.css.logoutIconNode
  137. //}).inject(this.logoutNode);
  138. this.logoutTextNode = new Element("div", {
  139. "styles": this.css.logoutTextNode,
  140. "text": this.lp.logout
  141. }).inject(this.logoutNode);
  142. this.logoutNode.addEvent("click", function(){ this.logout( ) }.bind(this));
  143. new Element("div",{
  144. "styles" : this.css.topSepNode,
  145. "text" : "|"
  146. }).inject(this.topContentNode);
  147. }
  148. if( this.options.settingEnable ){
  149. this.settingNode = new Element("div", {
  150. "styles": this.css.settingNode
  151. }).inject(this.topContentNode);
  152. //this.settingIconNode = new Element("div", {
  153. // "styles": this.css.settingIconNode
  154. //}).inject(this.settingNode);
  155. this.settingTextNode = new Element("div", {
  156. "styles": this.css.settingTextNode,
  157. "text": this.lp.setting,
  158. "title" : this.lp.forumConfig
  159. }).inject(this.settingNode);
  160. this.settingNode.addEvent("click", function(){ this.app.openSetting( ) }.bind(this));
  161. }
  162. if( this.options.settingEnable ) {
  163. new Element("div", {
  164. "styles": this.css.topSepNode,
  165. "text": "|"
  166. }).inject(this.topContentNode);
  167. }
  168. if( this.options.naviModeEnable ){
  169. this.loadNaviNode();
  170. new Element("div", {
  171. "styles": this.css.topSepNode,
  172. "text": "|"
  173. }).inject(this.topContentNode);
  174. }
  175. this.personNode = new Element("div", {
  176. "styles": this.css.personNode
  177. }).inject(this.topContentNode);
  178. //this.personIconNode = new Element("div", {
  179. // "styles": this.css.personIconNode
  180. //}).inject(this.personNode);
  181. this.personTextNode = new Element("div", {
  182. "styles": this.css.personTextNode,
  183. "text": ( this.userName || "").split("@")[0] + ",您好!",
  184. "title" : "点击查看个人中心"
  185. }).inject(this.personNode);
  186. this.personNode.addEvent("click", function(){ this.openPerson(this.userName ) }.bind(this))
  187. }
  188. this.searchDiv = new Element("div.searchDiv",{
  189. "styles" : this.css.searchDiv
  190. }).inject(this.topNode);
  191. this.searchInput = new Element("input.searchInput",{
  192. "styles" : this.css.searchInput,
  193. "value" : this.lp.searchKey,
  194. "title" : this.lp.searchTitle
  195. }).inject(this.searchDiv);
  196. var _self = this;
  197. this.searchInput.addEvents({
  198. "focus": function(){
  199. if (this.value==_self.lp.searchKey) this.set("value", "");
  200. },
  201. "blur": function(){if (!this.value) this.set("value", _self.lp.searchKey);},
  202. "keydown": function(e){
  203. if (e.code==13){
  204. this.search();
  205. e.preventDefault();
  206. }
  207. }.bind(this)
  208. });
  209. this.searchAction = new Element("div.searchAction",{
  210. "styles" : this.css.searchAction
  211. }).inject(this.searchDiv);
  212. this.searchAction.addEvents({
  213. "click": function(){ this.search(); }.bind(this),
  214. "mouseover": function(e){
  215. this.searchAction.setStyles( this.css.searchAction_over2 );
  216. e.stopPropagation();
  217. }.bind(this),
  218. "mouseout": function(){ this.searchAction.setStyles( this.css.searchAction ) }.bind(this)
  219. });
  220. this.searchDiv.addEvents( {
  221. "mouseover" : function(){
  222. this.searchInput.setStyles( this.css.searchInput_over );
  223. this.searchAction.setStyles( this.css.searchAction_over )
  224. }.bind(this),
  225. "mouseout" : function(){
  226. this.searchInput.setStyles( this.css.searchInput );
  227. this.searchAction.setStyles( this.css.searchAction )
  228. }.bind(this)
  229. });
  230. this._createTopContent();
  231. },
  232. loadNaviNode : function(){
  233. if( this.options.naviModeEnable ){
  234. this.naviNode = new Element("div", {
  235. "styles": this.css.settingNode
  236. }).inject(this.topContentNode);
  237. if( this.options.naviMode ){
  238. this.closeNaviTextNode = new Element("div", {
  239. "styles": this.css.settingTextNode,
  240. "text": "关闭导航",
  241. "title" : "关闭导航"
  242. }).inject(this.naviNode);
  243. this.closeNaviTextNode.addEvent("click", function(){ this.app.closeNavi( ) }.bind(this));
  244. }else{
  245. this.naviTextNode = new Element("div", {
  246. "styles": this.css.settingTextNode,
  247. "text": "导航",
  248. "title" : "导航布局"
  249. }).inject(this.naviNode);
  250. this.naviTextNode.addEvent("click", function(){
  251. this.app.openNavi( )
  252. }.bind(this));
  253. }
  254. }
  255. },
  256. _createTopContent: function () {
  257. },
  258. getSystemSetting : function( code, callback, async ){
  259. this.restActions.getSystemSettingByCode( {configCode : code }, function(json) {
  260. if (callback)callback(json.data);
  261. }.bind(this), null, async )
  262. },
  263. search : function(){
  264. var val = this.searchInput.get("value");
  265. if( val == "" || val == this.lp.searchKey ){
  266. this.notice( this.lp.noSearchContentNotice, "error" );
  267. return;
  268. }
  269. var appId = "ForumSearch";
  270. if( this.app.options.name == "ForumSearch" ){
  271. this.app.search( val );
  272. }else if (this.app.desktop.apps[appId] && !this.app.inBrowser){
  273. var app = this.app.desktop.apps[appId];
  274. app.setCurrent();
  275. app.search( val );
  276. }else{
  277. this.app.desktop.openApplication(null, "ForumSearch", {
  278. "appId": appId,
  279. "searchContent" : val
  280. });
  281. }
  282. },
  283. openPerson : function( userName ){
  284. var appId = "ForumPerson"+userName;
  285. if (this.app.desktop.apps[appId]){
  286. this.app.desktop.apps[appId].setCurrent();
  287. }else {
  288. this.app.desktop.openApplication(null, "ForumPerson", {
  289. "personName" : userName,
  290. "appId": appId
  291. });
  292. }
  293. },
  294. openLoginForm : function(){
  295. MWF.require("MWF.xDesktop.Authentication", null, false);
  296. var authentication = new MWF.xDesktop.Authentication({
  297. style : "application",
  298. onPostOk : function(){
  299. window.location.reload();
  300. }
  301. },this.app);
  302. authentication.openLoginForm({
  303. hasMask : true
  304. });
  305. },
  306. openSignUpForm : function(){
  307. MWF.require("MWF.xDesktop.Authentication", null, false);
  308. var authentication = new MWF.xDesktop.Authentication( {
  309. style : "application",
  310. onPostOk : function(){
  311. }
  312. }, this.app);
  313. authentication.openSignUpForm({
  314. hasMask : true
  315. });
  316. },
  317. logout: function(){
  318. MWF.Actions.get("x_organization_assemble_authentication").logout( function(){
  319. layout.desktop.session.user.distinguishedName = "anonymous";
  320. this.app.clearContent();
  321. this.app.loadApplicationContent();
  322. this.openLoginForm();
  323. }.bind(this))
  324. }
  325. });