Fix: apply excludes for user aliases in user selection view
- fixes a missing reassignment to the new named variable causing the selection of group aliases to fail in the user selector view of private messages - apply the list of excludes when a user selects a group alias to prevent double selection of users already in the list and selection of oneself
This commit is contained in:
parent
11f031c8f9
commit
1e609aac77
|
@ -89,7 +89,7 @@ $.fn.autocomplete = function(options) {
|
||||||
if (options.transformComplete) { transformedItem = options.transformComplete(transformedItem); }
|
if (options.transformComplete) { transformedItem = options.transformComplete(transformedItem); }
|
||||||
// dump what we have in single mode, just in case
|
// dump what we have in single mode, just in case
|
||||||
if (options.single) { inputSelectedItems = []; }
|
if (options.single) { inputSelectedItems = []; }
|
||||||
if (!_.isArray(transformedItem)) { transformed = [transformedItem || item]; }
|
transformed = _.isArray(transformedItem) ? transformedItem : [transformedItem || item];
|
||||||
|
|
||||||
var divs = transformed.map(function(itm) {
|
var divs = transformed.map(function(itm) {
|
||||||
var d = $("<div class='item'><span>" + itm + "<a class='remove' href='#'><i class='fa fa-times'></i></a></span></div>");
|
var d = $("<div class='item'><span>" + itm + "<a class='remove' href='#'><i class='fa fa-times'></i></a></span></div>");
|
||||||
|
|
|
@ -4,6 +4,14 @@ Discourse.UserSelector = Discourse.TextField.extend({
|
||||||
var userSelectorView = this,
|
var userSelectorView = this,
|
||||||
selected = [];
|
selected = [];
|
||||||
|
|
||||||
|
function excludedUsernames() {
|
||||||
|
var exclude = selected;
|
||||||
|
if (userSelectorView.get('excludeCurrentUser')) {
|
||||||
|
exclude = exclude.concat([Discourse.User.currentProp('username')]);
|
||||||
|
}
|
||||||
|
return exclude;
|
||||||
|
}
|
||||||
|
|
||||||
$(this.get('element')).val(this.get('usernames')).autocomplete({
|
$(this.get('element')).val(this.get('usernames')).autocomplete({
|
||||||
template: Discourse.UserSelector.templateFunction(),
|
template: Discourse.UserSelector.templateFunction(),
|
||||||
|
|
||||||
|
@ -12,14 +20,10 @@ Discourse.UserSelector = Discourse.TextField.extend({
|
||||||
allowAny: this.get('allowAny'),
|
allowAny: this.get('allowAny'),
|
||||||
|
|
||||||
dataSource: function(term) {
|
dataSource: function(term) {
|
||||||
var exclude = selected;
|
|
||||||
if (userSelectorView.get('excludeCurrentUser')) {
|
|
||||||
exclude = exclude.concat([Discourse.User.currentProp('username')]);
|
|
||||||
}
|
|
||||||
return Discourse.UserSearch.search({
|
return Discourse.UserSearch.search({
|
||||||
term: term,
|
term: term,
|
||||||
topicId: userSelectorView.get('topicId'),
|
topicId: userSelectorView.get('topicId'),
|
||||||
exclude: exclude,
|
exclude: excludedUsernames(),
|
||||||
include_groups: userSelectorView.get('include_groups')
|
include_groups: userSelectorView.get('include_groups')
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -28,7 +32,11 @@ Discourse.UserSelector = Discourse.TextField.extend({
|
||||||
if (v.username) {
|
if (v.username) {
|
||||||
return v.username;
|
return v.username;
|
||||||
} else {
|
} else {
|
||||||
return v.usernames;
|
var excludes = excludedUsernames();
|
||||||
|
return v.usernames.filter(function(item){
|
||||||
|
// include only, those not found in the exclude list
|
||||||
|
return excludes.indexOf(item) === -1;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue