This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/controllers/header.js.es6
Robin Ward e503c3859a Allow plugins to change the header to show two rows
This allows the discourse-tagging plugin to correctly use two rows in
the header if it needs to display tags, or one row if there are no tags.
This works in tandem with the same logic for when there is a category
badge to display or not.
2015-02-19 14:56:45 -05:00

76 lines
2.1 KiB
JavaScript

import DiscourseController from 'discourse/controllers/controller';
export default DiscourseController.extend({
topic: null,
showExtraInfo: null,
notifications: null,
loadingNotifications: false,
needs: ['application'],
loginRequired: Em.computed.alias('controllers.application.loginRequired'),
canSignUp: Em.computed.alias('controllers.application.canSignUp'),
showSignUpButton: function() {
return this.get('canSignUp') && !this.get('showExtraInfo');
}.property('canSignUp', 'showExtraInfo'),
showStarButton: function() {
return Discourse.User.current() && !this.get('topic.isPrivateMessage');
}.property('topic.isPrivateMessage'),
_resetCachedNotifications: function(){
// a bit hacky, but if we have no focus, hide notifications first
var visible = $("#notifications-dropdown").is(":visible");
if(!Discourse.get("hasFocus")) {
if(visible){
$("html").click();
}
this.set("notifications", null);
return;
}
if(visible){
this.refreshNotifications();
} else {
this.set("notifications", null);
}
}.observes("currentUser.lastNotificationChange"),
refreshNotifications: function(){
var self = this;
if (self.get("loadingNotifications")) { return; }
self.set("loadingNotifications", true);
Discourse.NotificationContainer.loadRecent().then(function(result) {
self.setProperties({
'currentUser.unread_notifications': 0,
notifications: result
});
}).catch(function() {
self.setProperties({
notifications: null
});
}).finally(function() {
self.set("loadingNotifications", false);
});
},
actions: {
toggleStar: function() {
var topic = this.get('topic');
if (topic) topic.toggleStar();
return false;
},
showNotifications: function(headerView) {
var self = this;
if (self.get('currentUser.unread_notifications') || self.get('currentUser.unread_private_messages') || !self.get('notifications')) {
self.refreshNotifications();
}
headerView.showDropdownBySelector("#user-notifications");
}
}
});