diff --git a/assets/javascripts/discourse/controllers/staff-notes.js.es6 b/assets/javascripts/discourse/controllers/staff-notes.js.es6 index 8b2bdb1..babb823 100644 --- a/assets/javascripts/discourse/controllers/staff-notes.js.es6 +++ b/assets/javascripts/discourse/controllers/staff-notes.js.es6 @@ -1,7 +1,7 @@ import { default as computed, on } from 'ember-addons/ember-computed-decorators'; import { popupAjaxError } from 'discourse/lib/ajax-error'; -const StaffNotesController = Ember.Controller.extend({ +export default Ember.Controller.extend({ newNote: null, saving: false, user: null, @@ -28,13 +28,10 @@ const StaffNotesController = Ember.Controller.extend({ const note = this.store.createRecord('staff-note'); const userId = parseInt(this.get('userId')); - const noteCount = StaffNotesController.noteCount; this.set('saving', true); note.save({ raw: this.get('newNote'), user_id: userId }).then(() => { this.set('newNote', ''); this.get('model').pushObject(note); - noteCount[userId] = this.get('model.length'); - this._refreshCount(); }).catch(popupAjaxError).finally(() => this.set('saving', false)); }, @@ -43,15 +40,8 @@ const StaffNotesController = Ember.Controller.extend({ note.destroyRecord().then(() => { const notes = this.get('model'); notes.removeObject(note); - StaffNotesController.noteCount[parseInt(note.get('user_id'))] = notes.get('length'); this._refreshCount(); }); } } }); - -StaffNotesController.reopenClass({ - noteCount: {} -}); - -export default StaffNotesController; diff --git a/assets/javascripts/discourse/initializers/enable-staff-notes.js.es6 b/assets/javascripts/discourse/initializers/enable-staff-notes.js.es6 index b44ee7d..498529a 100644 --- a/assets/javascripts/discourse/initializers/enable-staff-notes.js.es6 +++ b/assets/javascripts/discourse/initializers/enable-staff-notes.js.es6 @@ -22,10 +22,15 @@ export default { function widgetShowStaffNotes() { showStaffNotes(this.attrs.user_id, count => { - this.scheduleRerender(); + this.sendWidgetAction('refreshStaffNotes', count); }); } + api.attachWidgetAction('post', 'refreshStaffNotes', function(count) { + const cfs = this.model.get('user_custom_fields') || {}; + cfs.staff_notes_count = count; + this.model.set('user_custom_fields', cfs); + }); const UserController = container.lookupFactory('controller:user'); UserController.reopen({ @@ -43,19 +48,9 @@ export default { } }); - const StaffNotesController = container.lookupFactory('controller:staff-notes'); - const noteCount = StaffNotesController.noteCount; - api.decorateWidget('poster-name:after', dec => { const cfs = dec.attrs.userCustomFields || {}; - - // If we know the count, use it - let c = noteCount[dec.attrs.user_id]; - if (c === undefined && cfs.staff_notes_count) { - c = cfs.staff_notes_count; - } - - if (c > 0) { + if (cfs.staff_notes_count > 0) { return dec.attach('staff-notes-icon'); } });