Refresh the icon in the post stream when added/removed
This commit is contained in:
parent
9e040cabc9
commit
840be343e9
|
@ -1,7 +1,7 @@
|
|||
import { default as computed, on } from 'ember-addons/ember-computed-decorators';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
const StaffNotesController = Ember.Controller.extend({
|
||||
newNote: null,
|
||||
saving: false,
|
||||
|
||||
|
@ -18,15 +18,30 @@ export default Ember.Controller.extend({
|
|||
actions: {
|
||||
attachNote() {
|
||||
const note = this.store.createRecord('staff-note');
|
||||
const userId = parseInt(this.get('userId'));
|
||||
|
||||
this.set('saving', true);
|
||||
note.save({ raw: this.get('newNote'), user_id: this.get('userId') }).then(() => {
|
||||
note.save({ raw: this.get('newNote'), user_id: userId }).then(() => {
|
||||
this.set('newNote', '');
|
||||
this.get('model').pushObject(note);
|
||||
StaffNotesController.noteCount[userId] = (StaffNotesController.noteCount[userId] || 0) + 1;
|
||||
this.appEvents.trigger('post-stream:refresh', { force: true });
|
||||
}).catch(popupAjaxError).finally(() => this.set('saving', false));
|
||||
},
|
||||
|
||||
removeNote(note) {
|
||||
note.destroyRecord().then(() => this.get('model').removeObject(note));
|
||||
note.destroyRecord().then(() => {
|
||||
const notes = this.get('model');
|
||||
notes.removeObject(note);
|
||||
StaffNotesController.noteCount[parseInt(note.get('user_id'))] = notes.get('length');
|
||||
this.appEvents.trigger('post-stream:refresh', { force: true });
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
StaffNotesController.reopenClass({
|
||||
noteCount: {}
|
||||
});
|
||||
|
||||
export default StaffNotesController;
|
||||
|
|
|
@ -17,9 +17,19 @@ 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 (cfs.has_staff_notes) {
|
||||
|
||||
// If we know the count, use it
|
||||
const c = noteCount[dec.attrs.user_id];
|
||||
if (c !== undefined) {
|
||||
if (c > 0) {
|
||||
return dec.attach('staff-notes-icon');
|
||||
}
|
||||
} else if (cfs.has_staff_notes) {
|
||||
return dec.attach('staff-notes-icon');
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue