Commit ff7419b3 authored by Clement Ho's avatar Clement Ho

[skip ci] remove unnecessary ajax request

parent ea048763
...@@ -255,7 +255,8 @@ GitLabDropdown = (function() { ...@@ -255,7 +255,8 @@ GitLabDropdown = (function() {
} }
}; };
// Remote data // Remote data
})(this) })(this),
instance: this,
}); });
} }
} }
...@@ -269,6 +270,7 @@ GitLabDropdown = (function() { ...@@ -269,6 +270,7 @@ GitLabDropdown = (function() {
remote: this.options.filterRemote, remote: this.options.filterRemote,
query: this.options.data, query: this.options.data,
keys: searchFields, keys: searchFields,
instance: this,
elements: (function(_this) { elements: (function(_this) {
return function() { return function() {
selector = '.dropdown-content li:not(' + NON_SELECTABLE_CLASSES + ')'; selector = '.dropdown-content li:not(' + NON_SELECTABLE_CLASSES + ')';
......
...@@ -131,6 +131,11 @@ ...@@ -131,6 +131,11 @@
var isAuthorFilter; var isAuthorFilter;
isAuthorFilter = $('.js-author-search'); isAuthorFilter = $('.js-author-search');
return _this.users(term, options, function(users) { return _this.users(term, options, function(users) {
const glDropdown = this.instance || this.options.instance;
glDropdown.options.processData(term, users, callback);
}.bind(this));
},
processData: function(term, users, callback) {
var anyUser, index, j, len, name, obj, showDivider; var anyUser, index, j, len, name, obj, showDivider;
if (term.length === 0) { if (term.length === 0) {
showDivider = 0; showDivider = 0;
...@@ -171,7 +176,6 @@ ...@@ -171,7 +176,6 @@
users.splice(showDivider, 0, "divider"); users.splice(showDivider, 0, "divider");
} }
if ($dropdown.hasClass('js-multiselect')) { if ($dropdown.hasClass('js-multiselect')) {
const selected = $selectbox const selected = $selectbox
.find('input[name="' + $dropdown.data('field-name') + '"]') .find('input[name="' + $dropdown.data('field-name') + '"]')
...@@ -181,8 +185,6 @@ ...@@ -181,8 +185,6 @@
.get() .get()
.filter((i) => i !== 0); .filter((i) => i !== 0);
// const unassignedSelected = selected.length === 1 && selected[0] === 0;
// && !unassignedSelected
if (selected.length > 0) { if (selected.length > 0) {
const selectedUsers = users const selectedUsers = users
.filter((u) => selected.indexOf(u.id) !== -1) .filter((u) => selected.indexOf(u.id) !== -1)
...@@ -205,7 +207,6 @@ ...@@ -205,7 +207,6 @@
if (showMenuAbove) { if (showMenuAbove) {
$dropdown.data('glDropdown').positionMenuAbove(); $dropdown.data('glDropdown').positionMenuAbove();
} }
});
}, },
filterable: true, filterable: true,
filterRemote: true, filterRemote: true,
...@@ -216,10 +217,16 @@ ...@@ -216,10 +217,16 @@
fieldName: $dropdown.data('field-name'), fieldName: $dropdown.data('field-name'),
toggleLabel: function(selected, el, glDropdown) { toggleLabel: function(selected, el, glDropdown) {
if (this.multiSelect) { if (this.multiSelect) {
// debugger const inputValue = glDropdown.filterInput.val();
const users = glDropdown.fullData.filter((r) => {
return typeof r === 'object' && !Object.prototype.hasOwnProperty.call(r, 'beforeDivider');
});
const callback = glDropdown.parseData.bind(glDropdown);
// Update the data model // Update the data model
// debugger this.processData(inputValue, users, callback);
this.data(glDropdown.filterInput.val(), glDropdown.parseData.bind(glDropdown));
} }
if (selected && 'id' in selected && $(el).hasClass('is-active')) { if (selected && 'id' in selected && $(el).hasClass('is-active')) {
...@@ -309,7 +316,7 @@ ...@@ -309,7 +316,7 @@
} }
updateIssueBoardsIssue(); updateIssueBoardsIssue();
} else { } else if (!$dropdown.hasClass('js-multiselect')) {
selected = $dropdown.closest('.selectbox').find("input[name='" + ($dropdown.data('field-name')) + "']").val(); selected = $dropdown.closest('.selectbox').find("input[name='" + ($dropdown.data('field-name')) + "']").val();
return assignTo(selected); return assignTo(selected);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment