From 7f2e42362f3cd5ab697e4fb4d9853b7c2603209e Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 22 Nov 2017 10:42:33 +0100 Subject: [PATCH] FIX: support for select-kit (#10) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moves select-kit support into its own initializer, support for older implementations doesn’t seem needed at this point, but could be added if needed. --- .../initializers/extend-for-assigns.js.es6 | 76 ++++++++----------- 1 file changed, 32 insertions(+), 44 deletions(-) diff --git a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 index 1aa805e..1d136f2 100644 --- a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 +++ b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 @@ -6,8 +6,38 @@ import showModal from 'discourse/lib/show-modal'; import { iconNode } from 'discourse-common/lib/icon-library'; import { h } from 'virtual-dom'; -function initialize(api) { +function modifySelectKit(api) { + api.modifySelectKit("topic-footer-mobile-dropdown") + .modifyContent((context, existingContent) => { + if (context.get('currentUser.staff')) { + existingContent.push({ + id: 'assign', + icon: 'user-plus', + name: I18n.t('discourse_assign.assign.title') + }); + } + return existingContent; + }) + .onSelect((context, value) => { + if (!context.get('currentUser.staff')) { + return; + } + const topic = context.get('topic'); + + if (value === 'assign') { + showModal("assign-user", { + model: { + topic, + username: topic.get('assigned_to_user.username') + } + }); + context.set('value', null); + } + }); +} + +function initialize(api) { // You can't act on flags claimed by another user api.modifyClass('component:flagged-post', { @computed('flaggedPost.topic.assigned_to_user_id', 'filter') @@ -39,49 +69,6 @@ function initialize(api) { } }, { ignoreMissing: true }); - // doing this mess while we come up with a better API - api.modifyClass('component:topic-footer-mobile-dropdown', { - @computed("value") - content() { - const content = this._super(); - - if (!this.get('currentUser.staff') || !this.siteSettings.assign_enabled) { - return; - } - - content.pushObject({ - id: 'assign', - icon: 'user-plus', - name: I18n.t('discourse_assign.assign.title') - }); - - return content; - }, - - actions: { - onSelect(value) { - this._super(value); - - if (!this.get('currentUser.staff')) { - return; - } - - const topic = this.get('topic'); - - if (value === 'assign') { - - showModal("assign-user", { - model: { - topic: topic, - username: topic.get('assigned_to_user.username') - } - }); - this.set('value', null); - } - } - } - }); - api.modifyClass('model:topic', { @computed('assigned_to_user') assignedToUserPath(assignedToUser) { @@ -185,5 +172,6 @@ export default { name: 'extend-for-assign', initialize(container) { withPluginApi('0.8.11', api => initialize(api, container)); + withPluginApi('0.8.13', api => modifySelectKit(api, container)); } };