TopNode.js 13 KB

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