Fixed select2 workflow

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-03-02 18:02:18 +01:00
parent ddcd37121f
commit e6a7a9f251
No known key found for this signature in database
GPG Key ID: FB5ACEED51955BF8
2 changed files with 30 additions and 40 deletions

View File

@ -149,6 +149,7 @@
message: '',
errorMessage: '',
saving: false,
groups: [],
initialize: function() {
// this creates a new copy of the object to definitely have a new reference and being able to reset the model
this.originalModel = JSON.parse(JSON.stringify(this.model));
@ -161,6 +162,24 @@
if (this.model.get('id') === undefined) {
this.hasChanged = true;
}
var self = this;
$.ajax({
url: OC.generateUrl('settings/users/groups'),
dataType: 'json',
quietMillis: 100,
}).done(function(response) {
// add admin groups
$.each(response.data.adminGroups, function(id, group) {
self.groups.push({ id: group.id, displayname: group.name+'FIXME' });
});
// add groups
$.each(response.data.groups, function(id, group) {
self.groups.push({ id: group.id, displayname: group.name+'FIXME' });
});
self.render();
}).fail(function(response) {
console.error('Failure happened', response);
});
},
delete: function() {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
@ -304,10 +323,11 @@
id = $element.data('id'),
check = checks[id],
valueElement = $element.find('.check-value').first();
var self = this;
_.each(OCA.WorkflowEngine.availablePlugins, function(plugin) {
if (_.isFunction(plugin.render)) {
plugin.render(valueElement, check);
plugin.render(valueElement, check, self.groups);
}
});
}, this);

View File

@ -34,7 +34,7 @@
]
};
},
render: function(element, check) {
render: function(element, check, groups) {
if (check['class'] !== 'OCA\\WorkflowEngine\\Check\\UserGroupMembership') {
return;
}
@ -42,48 +42,18 @@
$(element).css('width', '400px');
$(element).select2({
ajax: {
url: OC.generateUrl('settings/users/groups'),
dataType: 'json',
quietMillis: 100,
data: function (term) {
return {
pattern: term, //search term
filterGroups: true,
sortGroups: 2 // by groupname
};
},
results: function (response) {
// TODO improve error case
if (response.data === undefined) {
console.error('Failure happened', response);
return;
}
var results = [];
// add admin groups
$.each(response.data.adminGroups, function(id, group) {
results.push({ id: group.id, displayname: group.name });
});
// add groups
$.each(response.data.groups, function(id, group) {
results.push({ id: group.id, displayname: group.name });
});
// TODO once limit and offset is implemented for groups we should paginate the search results
return {
results: results,
more: false
};
}
},
data: groups,
initSelection: function (element, callback) {
var groupId = element.val();
if (groupId) {
if (groupId && groups.length > 0) {
callback({
id: groupId,
displayname: groupId + 'FIXME' // FIXME
displayname: groups.find(group =>group.id === groupId).displayname
});
} else if (groupId) {
callback({
id: groupId,
displayname: groupId
});
} else {
callback();