Fixed sharing groups select and fixed search
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
parent
51ec928623
commit
6e0044b668
|
@ -167,7 +167,7 @@
|
||||||
url: OC.generateUrl('settings/users/groups'),
|
url: OC.generateUrl('settings/users/groups'),
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
quietMillis: 100,
|
quietMillis: 100,
|
||||||
}).done(function(response) {
|
}).success(function(response) {
|
||||||
// add admin groups
|
// add admin groups
|
||||||
$.each(response.data.adminGroups, function(id, group) {
|
$.each(response.data.adminGroups, function(id, group) {
|
||||||
self.groups.push({ id: group.id, displayname: group.name });
|
self.groups.push({ id: group.id, displayname: group.name });
|
||||||
|
@ -177,8 +177,9 @@
|
||||||
self.groups.push({ id: group.id, displayname: group.name });
|
self.groups.push({ id: group.id, displayname: group.name });
|
||||||
});
|
});
|
||||||
self.render();
|
self.render();
|
||||||
}).fail(function(response) {
|
}).error(function(data) {
|
||||||
console.error('Failure happened', response);
|
OC.Notification.error(t('workflowengine', 'Unable to retrieve the group list'), {type: 'error'});
|
||||||
|
console.log(data);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
delete: function() {
|
delete: function() {
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
$(element).css('width', '400px');
|
$(element).css('width', '400px');
|
||||||
|
|
||||||
$(element).select2({
|
$(element).select2({
|
||||||
data: groups,
|
data: { results: groups, text: 'displayname' },
|
||||||
initSelection: function (element, callback) {
|
initSelection: function (element, callback) {
|
||||||
var groupId = element.val();
|
var groupId = element.val();
|
||||||
if (groupId && groups.length > 0) {
|
if (groupId && groups.length > 0) {
|
||||||
|
|
|
@ -24,29 +24,9 @@ OC.Settings = _.extend(OC.Settings, {
|
||||||
var self = this;
|
var self = this;
|
||||||
options = options || {};
|
options = options || {};
|
||||||
if ($elements.length > 0) {
|
if ($elements.length > 0) {
|
||||||
// note: settings are saved through a "change" event registered
|
// Let's load the data and THEN init our select
|
||||||
// on all input fields
|
|
||||||
$elements.select2(_.extend({
|
|
||||||
placeholder: t('core', 'Groups'),
|
|
||||||
allowClear: true,
|
|
||||||
multiple: true,
|
|
||||||
toggleSelect: true,
|
|
||||||
separator: '|',
|
|
||||||
query: _.debounce(function(query) {
|
|
||||||
var queryData = {};
|
|
||||||
if (self._cachedGroups && query.term === '') {
|
|
||||||
query.callback({results: self._cachedGroups});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (query.term !== '') {
|
|
||||||
queryData = {
|
|
||||||
pattern: query.term,
|
|
||||||
filterGroups: 1
|
|
||||||
};
|
|
||||||
}
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: OC.generateUrl('/settings/users/groups'),
|
url: OC.generateUrl('/settings/users/groups'),
|
||||||
data: queryData,
|
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
var results = [];
|
var results = [];
|
||||||
|
@ -60,25 +40,35 @@ OC.Settings = _.extend(OC.Settings, {
|
||||||
$.each(data.data.groups, function(i, group) {
|
$.each(data.data.groups, function(i, group) {
|
||||||
results.push({id:group.id, displayname:group.name});
|
results.push({id:group.id, displayname:group.name});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (query.term === '') {
|
|
||||||
// cache full list
|
|
||||||
self._cachedGroups = results;
|
|
||||||
}
|
|
||||||
query.callback({results: results});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 100, true),
|
|
||||||
id: function(element) {
|
|
||||||
return element.id;
|
|
||||||
},
|
},
|
||||||
|
always: function() {
|
||||||
|
// note: settings are saved through a "change" event registered
|
||||||
|
// on all input fields
|
||||||
|
$elements.select2(_.extend({
|
||||||
|
placeholder: t('core', 'Groups'),
|
||||||
|
allowClear: true,
|
||||||
|
multiple: true,
|
||||||
|
toggleSelect: true,
|
||||||
|
separator: '|',
|
||||||
|
data: { results: results, text: 'displayname' },
|
||||||
initSelection: function(element, callback) {
|
initSelection: function(element, callback) {
|
||||||
var selection = _.map(($(element).val() || []).split('|').sort(), function(groupId) {
|
var groups = $(element).val();
|
||||||
|
var selection;
|
||||||
|
if (groups && results.length > 0) {
|
||||||
|
selection = _.map((groups || []).split('|').sort(), function(groupId) {
|
||||||
return {
|
return {
|
||||||
id: groupId,
|
id: groupId,
|
||||||
displayname: groupId + 'FIXME' // FIXME
|
displayname: results.find(group =>group.id === groupId).displayname
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
} else if (groups) {
|
||||||
|
selection = _.map((groups || []).split('|').sort(), function(groupId) {
|
||||||
|
return {
|
||||||
|
id: groupId,
|
||||||
|
displayname: groupId
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
callback(selection);
|
callback(selection);
|
||||||
},
|
},
|
||||||
formatResult: function (element) {
|
formatResult: function (element) {
|
||||||
|
@ -92,7 +82,12 @@ OC.Settings = _.extend(OC.Settings, {
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
}, extraOptions || {}));
|
}, extraOptions || {}));
|
||||||
|
},
|
||||||
|
error : function(data) {
|
||||||
|
OC.Notification.show(t('settings', 'Unable to retrieve the group list'), {type: 'error'});
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue