TopNode.js 11 KB

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