Clean up a lot of ugly stuff
This commit is contained in:
parent
69661ae6b1
commit
4d95ffde63
|
@ -1,7 +1,7 @@
|
||||||
import { default as computed, on } from 'ember-addons/ember-computed-decorators';
|
import { default as computed, on } from 'ember-addons/ember-computed-decorators';
|
||||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||||
|
|
||||||
const StaffNotesController = Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
newNote: null,
|
newNote: null,
|
||||||
saving: false,
|
saving: false,
|
||||||
user: null,
|
user: null,
|
||||||
|
@ -28,13 +28,10 @@ const StaffNotesController = Ember.Controller.extend({
|
||||||
const note = this.store.createRecord('staff-note');
|
const note = this.store.createRecord('staff-note');
|
||||||
const userId = parseInt(this.get('userId'));
|
const userId = parseInt(this.get('userId'));
|
||||||
|
|
||||||
const noteCount = StaffNotesController.noteCount;
|
|
||||||
this.set('saving', true);
|
this.set('saving', true);
|
||||||
note.save({ raw: this.get('newNote'), user_id: userId }).then(() => {
|
note.save({ raw: this.get('newNote'), user_id: userId }).then(() => {
|
||||||
this.set('newNote', '');
|
this.set('newNote', '');
|
||||||
this.get('model').pushObject(note);
|
this.get('model').pushObject(note);
|
||||||
noteCount[userId] = this.get('model.length');
|
|
||||||
|
|
||||||
this._refreshCount();
|
this._refreshCount();
|
||||||
}).catch(popupAjaxError).finally(() => this.set('saving', false));
|
}).catch(popupAjaxError).finally(() => this.set('saving', false));
|
||||||
},
|
},
|
||||||
|
@ -43,15 +40,8 @@ const StaffNotesController = Ember.Controller.extend({
|
||||||
note.destroyRecord().then(() => {
|
note.destroyRecord().then(() => {
|
||||||
const notes = this.get('model');
|
const notes = this.get('model');
|
||||||
notes.removeObject(note);
|
notes.removeObject(note);
|
||||||
StaffNotesController.noteCount[parseInt(note.get('user_id'))] = notes.get('length');
|
|
||||||
this._refreshCount();
|
this._refreshCount();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
StaffNotesController.reopenClass({
|
|
||||||
noteCount: {}
|
|
||||||
});
|
|
||||||
|
|
||||||
export default StaffNotesController;
|
|
||||||
|
|
|
@ -22,10 +22,15 @@ export default {
|
||||||
|
|
||||||
function widgetShowStaffNotes() {
|
function widgetShowStaffNotes() {
|
||||||
showStaffNotes(this.attrs.user_id, count => {
|
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');
|
const UserController = container.lookupFactory('controller:user');
|
||||||
UserController.reopen({
|
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 => {
|
api.decorateWidget('poster-name:after', dec => {
|
||||||
const cfs = dec.attrs.userCustomFields || {};
|
const cfs = dec.attrs.userCustomFields || {};
|
||||||
|
if (cfs.staff_notes_count > 0) {
|
||||||
// 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) {
|
|
||||||
return dec.attach('staff-notes-icon');
|
return dec.attach('staff-notes-icon');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue