diff --git a/app/assets/javascripts/discourse/controllers/header_controller.js b/app/assets/javascripts/discourse/controllers/header_controller.js index 69413093bed..f7a5429c464 100644 --- a/app/assets/javascripts/discourse/controllers/header_controller.js +++ b/app/assets/javascripts/discourse/controllers/header_controller.js @@ -9,6 +9,7 @@ Discourse.HeaderController = Discourse.Controller.extend({ topic: null, showExtraInfo: null, + notifications: null, categories: function() { return Discourse.Category.list(); @@ -39,6 +40,16 @@ Discourse.HeaderController = Discourse.Controller.extend({ toggleMobileView: function() { Discourse.Mobile.toggleMobileView(); + }, + + showNotifications: function(headerView) { + var self = this; + + Discourse.ajax("/notifications").then(function(result) { + self.set("notifications", result); + self.set("currentUser.unread_notifications", 0); + headerView.showDropdownBySelector("#user-notifications"); + }); } } diff --git a/app/assets/javascripts/discourse/controllers/notification_controller.js b/app/assets/javascripts/discourse/controllers/notification_controller.js new file mode 100644 index 00000000000..19db113cad7 --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/notification_controller.js @@ -0,0 +1,17 @@ +Discourse.NotificationController = Discourse.ObjectController.extend({ + scope: function() { + return "notifications." + Discourse.Site.currentProp("notificationLookup")[this.get("notification_type")]; + }.property(), + + username: function() { + return this.get("data.display_username"); + }.property(), + + link: function() { + if (this.blank("data.topic_title")) { + return ""; + } + var url = Discourse.Utilities.postUrl(this.get("slug"), this.get("topic_id"), this.get("post_number")); + return '' + this.get("data.topic_title") + ''; + }.property() +}); diff --git a/app/assets/javascripts/discourse/controllers/notifications_controller.js b/app/assets/javascripts/discourse/controllers/notifications_controller.js new file mode 100644 index 00000000000..1268515f449 --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/notifications_controller.js @@ -0,0 +1,3 @@ +Discourse.NotificationsController = Ember.ArrayController.extend(Discourse.HasCurrentUser, { + itemController: "notification" +}); diff --git a/app/assets/javascripts/discourse/helpers/i18n_helpers.js b/app/assets/javascripts/discourse/helpers/i18n_helpers.js index 92e2335c883..56d57ea2a4c 100644 --- a/app/assets/javascripts/discourse/helpers/i18n_helpers.js +++ b/app/assets/javascripts/discourse/helpers/i18n_helpers.js @@ -34,6 +34,13 @@ Ember.Handlebars.registerHelper('i18n', function(property, options) { return I18n.t(property, params); }); +/** + Bound version of i18n helper. + **/ +Ember.Handlebars.registerBoundHelper("boundI18n", function(property, options) { + return new Handlebars.SafeString(I18n.t(property, options.hash)); +}); + /** Set up an i18n binding that will update as a count changes, complete with pluralization. diff --git a/app/assets/javascripts/discourse/models/notification.js b/app/assets/javascripts/discourse/models/notification.js deleted file mode 100644 index 8d55a6f19b3..00000000000 --- a/app/assets/javascripts/discourse/models/notification.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - A data model representing a notification a user receives - - @class Notification - @extends Discourse.Model - @namespace Discourse - @module Discourse -**/ -Discourse.Notification = Discourse.Model.extend({ - - readClass: (function() { - if (this.read) return 'read'; - return ''; - }).property('read'), - - url: function() { - if (this.blank('data.topic_title')) return ""; - return Discourse.Utilities.postUrl(this.get('slug'), this.get('topic_id'), this.get('post_number')); - }.property(), - - rendered: function() { - var notificationName = Discourse.Site.currentProp('notificationLookup')[this.notification_type]; - return I18n.t("notifications." + notificationName, { - username: this.data.display_username, - link: "" + this.data.topic_title + "" - }); - }.property() - -}); - -Discourse.Notification.reopenClass({ - create: function(obj) { - obj = obj || {}; - - if (obj.data) { - obj.data = Em.Object.create(obj.data); - } - return this._super(obj); - } -}); - - diff --git a/app/assets/javascripts/discourse/templates/header.js.handlebars b/app/assets/javascripts/discourse/templates/header.js.handlebars index 5e59f0c8314..c483fc287f0 100644 --- a/app/assets/javascripts/discourse/templates/header.js.handlebars +++ b/app/assets/javascripts/discourse/templates/header.js.handlebars @@ -94,20 +94,7 @@ {{render search}} -
- {{#if view.notifications}} - - {{else}} -
{{i18n notifications.none}}
- {{/if}} -
+ {{render notifications notifications}}