diff --git a/app/assets/javascripts/discourse/components/group-selector.js.es6 b/app/assets/javascripts/discourse/components/group-selector.js.es6 index 8fe798f48..e88505ca9 100644 --- a/app/assets/javascripts/discourse/components/group-selector.js.es6 +++ b/app/assets/javascripts/discourse/components/group-selector.js.es6 @@ -1,29 +1,13 @@ -var compiled; - -function templateFunction() { - compiled = compiled || Handlebars.compile( - "
" + - "" + - "
" - ); - return compiled; -} - -export default Em.Component.extend({ +export default Ember.Component.extend({ placeholder: function(){ return I18n.t(this.get("placeholderKey")); }.property("placeholderKey"), - didInsertElement: function() { + _initializeAutocomplete: function() { var self = this; var selectedGroups; + var template = this.container.lookup('template:group-selector-autocomplete.raw'); self.$('input').autocomplete({ allowAny: false, onChangeItems: function(items){ @@ -45,7 +29,7 @@ export default Em.Component.extend({ }); }); }, - template: templateFunction() + template: template }); - } + }.on('didInsertElement') }); diff --git a/app/assets/javascripts/discourse/components/user-selector.js.es6 b/app/assets/javascripts/discourse/components/user-selector.js.es6 new file mode 100644 index 000000000..19c12841b --- /dev/null +++ b/app/assets/javascripts/discourse/components/user-selector.js.es6 @@ -0,0 +1,62 @@ +import TextField from 'discourse/components/text-field'; +import userSearch from 'discourse/lib/user-search'; + +export default TextField.extend({ + + _initializeAutocomplete: function() { + var self = this, + selected = [], + currentUser = this.currentUser, + includeGroups = this.get('includeGroups') === 'true'; + + function excludedUsernames() { + if (currentUser && self.get('excludeCurrentUser')) { + return selected.concat([currentUser.get('username')]); + } + return selected; + } + + var template = this.container.lookup('template:user-selector-autocomplete.raw'); + $(this.get('element')).val(this.get('usernames')).autocomplete({ + template: template, + + disabled: this.get('disabled'), + single: this.get('single'), + allowAny: this.get('allowAny'), + + dataSource: function(term) { + return userSearch({ + term: term, + topicId: self.get('topicId'), + exclude: excludedUsernames(), + includeGroups: includeGroups + }); + }, + + transformComplete: function(v) { + if (v.username) { + return v.username; + } else { + var excludes = excludedUsernames(); + return v.usernames.filter(function(item){ + return excludes.indexOf(item) === -1; + }); + } + }, + + onChangeItems: function(items) { + items = items.map(function(i) { + return i.username ? i.username : i; + }); + self.set('usernames', items.join(",")); + selected = items; + }, + + reverseTransform: function(i) { + return { username: i }; + } + + }); + }.on('didInsertElement') + +}); diff --git a/app/assets/javascripts/discourse/helpers/max-usernames.js.es6 b/app/assets/javascripts/discourse/helpers/max-usernames.js.es6 new file mode 100644 index 000000000..4eb136e2a --- /dev/null +++ b/app/assets/javascripts/discourse/helpers/max-usernames.js.es6 @@ -0,0 +1,10 @@ +import registerUnbound from 'discourse/helpers/register-unbound'; + +registerUnbound('max-usernames', function(usernames, params) { + var maxLength = parseInt(params.max) || 3; + if (usernames.length > maxLength){ + return usernames.slice(0, maxLength).join(", ") + ", +" + (usernames.length - maxLength); + } else { + return usernames.join(", "); + } +}); diff --git a/app/assets/javascripts/discourse/initializers/deprecations.js.es6 b/app/assets/javascripts/discourse/initializers/deprecations.js.es6 deleted file mode 100644 index 06d85c5e1..000000000 --- a/app/assets/javascripts/discourse/initializers/deprecations.js.es6 +++ /dev/null @@ -1,43 +0,0 @@ -var deprecatedViewHelpers = { - inputTip: 'input-tip', - pagedown: 'pagedown-editor', - textField: 'text-field', - userSelector: 'user-selector', - combobox: 'combo-box', - categoryChooser: 'category-chooser', - chooseTopic: 'choose-topic', - 'discourse-activity-filter': 'activity-filter' -}; - -var renamedHelpers = { - icon: "fa-icon", - date: "format-date", - age: "format-age" -}; - -export default { - name: 'deprecations', - initialize: function(container) { - Ember.keys(deprecatedViewHelpers).forEach(function(old) { - var newName = deprecatedViewHelpers[old]; - Ember.Handlebars.registerHelper(old, function(options) { - Em.warn("The `" + old +"` helper is deprecated. Use `" + newName + "` instead."); - var helper = container.lookupFactory('view:' + newName) || container.lookupFactory('component:' + newName); - var hash = options.hash, - types = options.hashTypes; - - Discourse.Utilities.normalizeHash(hash, types); - return Ember.Handlebars.helpers.view.call(this, helper, options); - }); - }); - - Ember.keys(renamedHelpers).forEach(function(old) { - var newName = renamedHelpers[old]; - Ember.Handlebars.registerHelper(old, function() { - Em.warn("The `" + old +"` helper is deprecated. Use `" + newName + "` instead."); - var newHelper = container.lookupFactory('helper:' + newName); - return newHelper.apply(this, Array.prototype.slice.call(arguments)); - }); - }); - } -}; diff --git a/app/assets/javascripts/discourse/initializers/inject-objects.js.es6 b/app/assets/javascripts/discourse/initializers/inject-objects.js.es6 index ab5578971..31933358d 100644 --- a/app/assets/javascripts/discourse/initializers/inject-objects.js.es6 +++ b/app/assets/javascripts/discourse/initializers/inject-objects.js.es6 @@ -39,5 +39,9 @@ export default { application.inject('route', 'session', 'session:main'); application.inject('view', 'session', 'session:main'); application.inject('model', 'session', 'session:main'); + + // Inject currentUser. Components only for now to prevent any breakage + application.register('current-user:main', Discourse.User.current(), { instantiate: false }); + application.inject('component', 'currentUser', 'current-user:main'); } }; diff --git a/app/assets/javascripts/discourse/initializers/view-helpers.js.es6 b/app/assets/javascripts/discourse/initializers/view-helpers.js.es6 index 1d4fb2fcf..08bc7a681 100644 --- a/app/assets/javascripts/discourse/initializers/view-helpers.js.es6 +++ b/app/assets/javascripts/discourse/initializers/view-helpers.js.es6 @@ -1,6 +1,5 @@ var helpers = ['input-tip', 'pagedown-editor', - 'user-selector', 'category-chooser', 'combo-box', 'choose-topic', diff --git a/app/assets/javascripts/discourse/lib/user-search.js.es6 b/app/assets/javascripts/discourse/lib/user-search.js.es6 index 2739524e8..3311f518d 100644 --- a/app/assets/javascripts/discourse/lib/user-search.js.es6 +++ b/app/assets/javascripts/discourse/lib/user-search.js.es6 @@ -74,7 +74,7 @@ function organizeResults(r, options) { export default function userSearch(options) { var term = options.term || "", - includeGroups = !!options.include_groups, + includeGroups = options.includeGroups, topicId = options.topicId; diff --git a/app/assets/javascripts/discourse/templates/composer.hbs b/app/assets/javascripts/discourse/templates/composer.hbs index 9d068ec8d..c4a89ffb5 100644 --- a/app/assets/javascripts/discourse/templates/composer.hbs +++ b/app/assets/javascripts/discourse/templates/composer.hbs @@ -8,7 +8,7 @@ {{render "composer-messages"}}
- + {{#if model.viewOpen}}
@@ -33,7 +33,7 @@ {{user-selector topicId=controller.controllers.topic.model.id excludeCurrentUser="true" id="private-message-users" - include_groups="true" + includeGroups="true" class="span8" placeholderKey="composer.users_placeholder" tabindex="1" diff --git a/app/assets/javascripts/discourse/templates/group-selector-autocomplete.raw.hbs b/app/assets/javascripts/discourse/templates/group-selector-autocomplete.raw.hbs new file mode 100644 index 000000000..a396c2d7f --- /dev/null +++ b/app/assets/javascripts/discourse/templates/group-selector-autocomplete.raw.hbs @@ -0,0 +1,7 @@ +
+ +
diff --git a/app/assets/javascripts/discourse/templates/modal/change_owner.hbs b/app/assets/javascripts/discourse/templates/modal/change_owner.hbs index 0e8831367..1330351a6 100644 --- a/app/assets/javascripts/discourse/templates/modal/change_owner.hbs +++ b/app/assets/javascripts/discourse/templates/modal/change_owner.hbs @@ -6,7 +6,7 @@
- {{user-selector single=true usernames=new_user include_groups="false" placeholderKey="topic.change_owner.placeholder"}} + {{user-selector single="true" usernames=new_user placeholderKey="topic.change_owner.placeholder"}}
diff --git a/app/assets/javascripts/discourse/templates/modal/invite.hbs b/app/assets/javascripts/discourse/templates/modal/invite.hbs index dd7689add..743fc6d2f 100644 --- a/app/assets/javascripts/discourse/templates/modal/invite.hbs +++ b/app/assets/javascripts/discourse/templates/modal/invite.hbs @@ -15,7 +15,7 @@ {{#if isAdmin}} - {{group-selector includeAuto=false groupFinder=groupFinder groupNames=groupNames placeholderKey="topic.invite_private.group_name"}} + {{group-selector groupFinder=groupFinder groupNames=groupNames placeholderKey="topic.invite_private.group_name"}} {{/if}} {{/if}}
diff --git a/app/assets/javascripts/discourse/templates/modal/invite_private.hbs b/app/assets/javascripts/discourse/templates/modal/invite_private.hbs index 47e8cd267..0284697ce 100644 --- a/app/assets/javascripts/discourse/templates/modal/invite_private.hbs +++ b/app/assets/javascripts/discourse/templates/modal/invite_private.hbs @@ -10,7 +10,7 @@ {{i18n 'topic.invite_private.success'}} {{else}} - {{user-selector single=true allowAny=true usernames=emailOrUsername include_groups="true" placeholderKey="topic.invite_private.email_or_username_placeholder"}} + {{user-selector single="true" allowAny=true usernames=emailOrUsername includeGroups="true" placeholderKey="topic.invite_private.email_or_username_placeholder"}} {{/if}}