Merge pull request #16051 from nextcloud/backport/16033/stable16
[stable16] fix LDAP Wizard forgetting groups on select with search
This commit is contained in:
commit
a4e03408ad
|
@ -21,7 +21,6 @@ OCA = OCA || {};
|
||||||
init: function($select, $textInput) {
|
init: function($select, $textInput) {
|
||||||
this.$select = $select;
|
this.$select = $select;
|
||||||
this.$textInput = $textInput;
|
this.$textInput = $textInput;
|
||||||
this.updateOptions();
|
|
||||||
this.lastSearch = '';
|
this.lastSearch = '';
|
||||||
|
|
||||||
var fity = this;
|
var fity = this;
|
||||||
|
@ -35,22 +34,6 @@ OCA = OCA || {};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* the options will be read in again. Should be called after a
|
|
||||||
* configuration switch.
|
|
||||||
*/
|
|
||||||
updateOptions: function() {
|
|
||||||
var options = [];
|
|
||||||
this.$select.find('option').each(function() {
|
|
||||||
options.push({
|
|
||||||
value: $(this).val(),
|
|
||||||
normalized: $(this).val().toLowerCase()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
this._options = options;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the actual search or filter method
|
* the actual search or filter method
|
||||||
*
|
*
|
||||||
|
@ -62,10 +45,12 @@ OCA = OCA || {};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fity.lastSearch = filterVal;
|
fity.lastSearch = filterVal;
|
||||||
fity.$select.empty();
|
|
||||||
$.each(fity._options, function() {
|
fity.$select.find('option').each(function() {
|
||||||
if(!filterVal || this.normalized.indexOf(filterVal) > -1) {
|
if(!filterVal || $(this).val().toLowerCase().indexOf(filterVal) > -1) {
|
||||||
fity.$select.append($('<option>').val(this.value).text(this.value));
|
$(this).removeAttr('hidden')
|
||||||
|
} else {
|
||||||
|
$(this).attr('hidden', 'hidden');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
delete(fity.runID);
|
delete(fity.runID);
|
||||||
|
|
|
@ -170,7 +170,7 @@ OCA = OCA || {};
|
||||||
} else {
|
} else {
|
||||||
var $element = $(this.tabID).find('.ldapGroupListSelected');
|
var $element = $(this.tabID).find('.ldapGroupListSelected');
|
||||||
this.equipMultiSelect($element, groups);
|
this.equipMultiSelect($element, groups);
|
||||||
this.updateFilterOnType('selected');
|
this.updateFilterOnType();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -212,10 +212,8 @@ OCA = OCA || {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* updates (creates, if necessary) filterOnType instances
|
* updates (creates, if necessary) filterOnType instances
|
||||||
*
|
|
||||||
* @param {string} [only] - if only one search index should be updated
|
|
||||||
*/
|
*/
|
||||||
updateFilterOnType: function(only) {
|
updateFilterOnType: function() {
|
||||||
if(_.isUndefined(this.filterOnType)) {
|
if(_.isUndefined(this.filterOnType)) {
|
||||||
this.filterOnType = [];
|
this.filterOnType = [];
|
||||||
|
|
||||||
|
@ -227,13 +225,6 @@ OCA = OCA || {};
|
||||||
this.filterOnType.push(this.foTFactory.get(
|
this.filterOnType.push(this.foTFactory.get(
|
||||||
$selectedGroups, $(this.tabID).find('.ldapManyGroupsSearch')
|
$selectedGroups, $(this.tabID).find('.ldapManyGroupsSearch')
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
if(_.isUndefined(only) || only.toLowerCase() === 'available') {
|
|
||||||
this.filterOnType[0].updateOptions();
|
|
||||||
}
|
|
||||||
if(_.isUndefined(only) || only.toLowerCase() === 'selected') {
|
|
||||||
this.filterOnType[1].updateOptions();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -282,7 +273,7 @@ OCA = OCA || {};
|
||||||
// we reimplement it here to update the filter index
|
// we reimplement it here to update the filter index
|
||||||
// for groups. Maybe we can isolate it?
|
// for groups. Maybe we can isolate it?
|
||||||
if(methodName === 'setGroups') {
|
if(methodName === 'setGroups') {
|
||||||
view.updateFilterOnType('selected');
|
view.updateFilterOnType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,7 +303,6 @@ OCA = OCA || {};
|
||||||
var selected = view.configModel.configuration[view.getGroupsItem().keyName];
|
var selected = view.configModel.configuration[view.getGroupsItem().keyName];
|
||||||
var available = $(payload.data).not(selected).get();
|
var available = $(payload.data).not(selected).get();
|
||||||
view.equipMultiSelect($element, available);
|
view.equipMultiSelect($element, available);
|
||||||
view.updateFilterOnType('available');
|
|
||||||
$(view.tabID).find(".ldapManyGroupsSupport").removeClass('hidden');
|
$(view.tabID).find(".ldapManyGroupsSupport").removeClass('hidden');
|
||||||
view.getGroupsItem().$element.multiselect({classes: view.multiSelectPluginClass + ' forceHidden'});
|
view.getGroupsItem().$element.multiselect({classes: view.multiSelectPluginClass + ' forceHidden'});
|
||||||
view.isComplexGroupChooser = true;
|
view.isComplexGroupChooser = true;
|
||||||
|
@ -356,12 +346,22 @@ OCA = OCA || {};
|
||||||
*/
|
*/
|
||||||
onSelectGroup: function() {
|
onSelectGroup: function() {
|
||||||
var $available = $(this.tabID).find('.ldapGroupListAvailable');
|
var $available = $(this.tabID).find('.ldapGroupListAvailable');
|
||||||
|
if(!$available.val()) {
|
||||||
|
return; // no selection – nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
var $selected = $(this.tabID).find('.ldapGroupListSelected');
|
var $selected = $(this.tabID).find('.ldapGroupListSelected');
|
||||||
var selected = $.map($selected.find('option'), function(e) { return e.value; });
|
var selected = $.map($selected.find('option'), function(e) { return e.value; });
|
||||||
|
|
||||||
this._saveGroups(selected.concat($available.val()));
|
let selectedGroups = [];
|
||||||
$available.find('option:selected').prependTo($selected);
|
$available.find('option:selected:visible').each(function() {
|
||||||
this.updateFilterOnType('available'); // selected groups are not updated yet
|
selectedGroups.push($(this).val());
|
||||||
|
});
|
||||||
|
|
||||||
|
this._saveGroups(selected.concat(selectedGroups));
|
||||||
|
$available.find('option:selected:visible').prependTo($selected);
|
||||||
|
this.updateFilterOnType(); // selected groups are not updated yet
|
||||||
|
$available.find('option:selected').prop("selected", false);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -370,11 +370,12 @@ OCA = OCA || {};
|
||||||
onDeselectGroup: function() {
|
onDeselectGroup: function() {
|
||||||
var $available = $(this.tabID).find('.ldapGroupListAvailable');
|
var $available = $(this.tabID).find('.ldapGroupListAvailable');
|
||||||
var $selected = $(this.tabID).find('.ldapGroupListSelected');
|
var $selected = $(this.tabID).find('.ldapGroupListSelected');
|
||||||
var selected = $.map($selected.find('option:not(:selected)'), function(e) { return e.value; });
|
var selected = $.map($selected.find('option:not(:selected:visible)'), function(e) { return e.value; });
|
||||||
|
|
||||||
this._saveGroups(selected);
|
this._saveGroups(selected);
|
||||||
$selected.find('option:selected').appendTo($available);
|
$selected.find('option:selected:visible').appendTo($available);
|
||||||
this.updateFilterOnType('available'); // selected groups are not updated yet
|
this.updateFilterOnType(); // selected groups are not updated yet
|
||||||
|
$selected.find('option:selected').prop("selected", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -228,10 +228,12 @@ OCA = OCA || {};
|
||||||
* @param {Array} options
|
* @param {Array} options
|
||||||
*/
|
*/
|
||||||
equipMultiSelect: function($element, options) {
|
equipMultiSelect: function($element, options) {
|
||||||
$element.empty();
|
if($element.find('option').length === 0) {
|
||||||
for (var i in options) {
|
$element.empty();
|
||||||
var name = options[i];
|
for (var i in options) {
|
||||||
$element.append($('<option>').val(name).text(name).attr('title', name));
|
var name = options[i];
|
||||||
|
$element.append($('<option>').val(name).text(name).attr('title', name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(!$element.hasClass('ldapGroupList')) {
|
if(!$element.hasClass('ldapGroupList')) {
|
||||||
$element.multiselect('refresh');
|
$element.multiselect('refresh');
|
||||||
|
|
Loading…
Reference in New Issue