Clean up a lot of ugly stuff

This commit is contained in:
Robin Ward 2016-03-11 15:32:38 -05:00
parent 69661ae6b1
commit 4d95ffde63
2 changed files with 8 additions and 23 deletions

View File

@ -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;

View File

@ -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');
}
});