Skip to content

Commit

Permalink
Update to new Connector API
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltrout committed Dec 12, 2016
1 parent 4203097 commit 8996279
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
@@ -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));
}
}
};
18 changes: 18 additions & 0 deletions assets/javascripts/discourse-staff-notes/lib/staff-notes.js.es6
@@ -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 showModal from 'discourse/lib/show-modal';
import loadScript from 'discourse/lib/load-script';
import { iconNode } from 'discourse/helpers/fa-icon-node';
import { showStaffNotes } from 'discourse/plugins/staff-notes/discourse-staff-notes/lib/staff-notes';

export default {
name: 'enable-staff-notes',
Expand All @@ -11,26 +10,9 @@ export default {
if (!siteSettings.staff_notes_enabled || !currentUser || !currentUser.staff) { return; }

const store = container.lookup('store:main');

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() {
showStaffNotes(this.attrs.user_id, count => {
showStaffNotes(store, this.attrs.user_id, count => {
this.sendWidgetAction('refreshStaffNotes', count);
});
}
Expand All @@ -52,12 +34,11 @@ export default {
actions: {
showStaffNotes() {
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 loc = mobileView ? 'before' : 'after';
api.decorateWidget(`poster-name:${loc}`, dec => {
Expand Down
5 changes: 2 additions & 3 deletions assets/javascripts/discourse/templates/modal/staff-notes.hbs
@@ -1,5 +1,4 @@
<div class="modal-body staff-notes-modal">

{{#d-modal-body class="staff-notes-modal"}}
{{#each model as |n|}}
<div class='staff-note'>
<div class='posted-by'>
Expand Down Expand Up @@ -34,4 +33,4 @@

{{textarea value=newNote}}
{{d-button action="attachNote" label="staff_notes.attach" class="btn-primary" disabled=attachDisabled}}
</div>
{{/d-modal-body}}

0 comments on commit 8996279

Please sign in to comment.