Update to new Connector API
This commit is contained in:
parent
4203097376
commit
89962793d0
|
@ -0,0 +1,22 @@
|
||||||
|
import { showStaffNotes } from 'discourse/plugins/staff-notes/discourse-staff-notes/lib/staff-notes';
|
||||||
|
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
shouldRender(args, component) {
|
||||||
|
const { siteSettings, currentUser } = component;
|
||||||
|
return siteSettings.staff_notes_enabled && currentUser && currentUser.staff;
|
||||||
|
},
|
||||||
|
|
||||||
|
setupComponent(args, component) {
|
||||||
|
const { model } = args;
|
||||||
|
component.set('staffNotesCount', model.get('custom_fields.staff_notes_count') || 0);
|
||||||
|
},
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
showStaffNotes() {
|
||||||
|
const store = getOwner(this).lookup('store:main');
|
||||||
|
const user = this.get('args.model');
|
||||||
|
showStaffNotes(store, user.get('id'), count => this.set('staffNotesCount', count));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,18 @@
|
||||||
|
import showModal from 'discourse/lib/show-modal';
|
||||||
|
import loadScript from 'discourse/lib/load-script';
|
||||||
|
|
||||||
|
export function showStaffNotes(store, userId, callback) {
|
||||||
|
return loadScript('defer/html-sanitizer-bundle').then(() => {
|
||||||
|
return store.find('staff-note', { user_id: userId }).then(model => {
|
||||||
|
const controller = showModal('staff-notes', {
|
||||||
|
model,
|
||||||
|
title: 'staff_notes.title',
|
||||||
|
addModalBodyView: true
|
||||||
|
});
|
||||||
|
controller.reset();
|
||||||
|
controller.set('userId', userId);
|
||||||
|
controller.set('callback', callback);
|
||||||
|
return controller;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
import { withPluginApi } from 'discourse/lib/plugin-api';
|
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||||
import showModal from 'discourse/lib/show-modal';
|
|
||||||
import loadScript from 'discourse/lib/load-script';
|
|
||||||
import { iconNode } from 'discourse/helpers/fa-icon-node';
|
import { iconNode } from 'discourse/helpers/fa-icon-node';
|
||||||
|
import { showStaffNotes } from 'discourse/plugins/staff-notes/discourse-staff-notes/lib/staff-notes';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'enable-staff-notes',
|
name: 'enable-staff-notes',
|
||||||
|
@ -11,26 +10,9 @@ export default {
|
||||||
if (!siteSettings.staff_notes_enabled || !currentUser || !currentUser.staff) { return; }
|
if (!siteSettings.staff_notes_enabled || !currentUser || !currentUser.staff) { return; }
|
||||||
|
|
||||||
const store = container.lookup('store:main');
|
const store = container.lookup('store:main');
|
||||||
|
|
||||||
withPluginApi('0.2', api => {
|
withPluginApi('0.2', api => {
|
||||||
function showStaffNotes(userId, callback) {
|
|
||||||
return loadScript('defer/html-sanitizer-bundle').then(() => {
|
|
||||||
return store.find('staff-note', { user_id: userId }).then(model => {
|
|
||||||
const controller = showModal('staff-notes', {
|
|
||||||
model,
|
|
||||||
title: 'staff_notes.title',
|
|
||||||
addModalBodyView: true
|
|
||||||
});
|
|
||||||
controller.reset();
|
|
||||||
controller.set('userId', userId);
|
|
||||||
controller.set('callback', callback);
|
|
||||||
return controller;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function widgetShowStaffNotes() {
|
function widgetShowStaffNotes() {
|
||||||
showStaffNotes(this.attrs.user_id, count => {
|
showStaffNotes(store, this.attrs.user_id, count => {
|
||||||
this.sendWidgetAction('refreshStaffNotes', count);
|
this.sendWidgetAction('refreshStaffNotes', count);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -52,12 +34,11 @@ export default {
|
||||||
actions: {
|
actions: {
|
||||||
showStaffNotes() {
|
showStaffNotes() {
|
||||||
const user = this.get('model');
|
const user = this.get('model');
|
||||||
showStaffNotes(user.get('id'), count => this.set('staffNotesCount', count));
|
showStaffNotes(store, user.get('id'), count => this.set('staffNotesCount', count));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const mobileView = api.container.lookup('site:main').mobileView;
|
const mobileView = api.container.lookup('site:main').mobileView;
|
||||||
const loc = mobileView ? 'before' : 'after';
|
const loc = mobileView ? 'before' : 'after';
|
||||||
api.decorateWidget(`poster-name:${loc}`, dec => {
|
api.decorateWidget(`poster-name:${loc}`, dec => {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<div class="modal-body staff-notes-modal">
|
{{#d-modal-body class="staff-notes-modal"}}
|
||||||
|
|
||||||
{{#each model as |n|}}
|
{{#each model as |n|}}
|
||||||
<div class='staff-note'>
|
<div class='staff-note'>
|
||||||
<div class='posted-by'>
|
<div class='posted-by'>
|
||||||
|
@ -34,4 +33,4 @@
|
||||||
|
|
||||||
{{textarea value=newNote}}
|
{{textarea value=newNote}}
|
||||||
{{d-button action="attachNote" label="staff_notes.attach" class="btn-primary" disabled=attachDisabled}}
|
{{d-button action="attachNote" label="staff_notes.attach" class="btn-primary" disabled=attachDisabled}}
|
||||||
</div>
|
{{/d-modal-body}}
|
||||||
|
|
Loading…
Reference in New Issue