Skip to content

Commit

Permalink
Fixed select2 workflow
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Mar 2, 2018
1 parent e8df148 commit a76d28e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 40 deletions.
22 changes: 21 additions & 1 deletion apps/workflowengine/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down
48 changes: 9 additions & 39 deletions apps/workflowengine/js/usergroupmembershipplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,56 +34,26 @@
]
};
},
render: function(element, check) {
render: function(element, check, groups) {
if (check['class'] !== 'OCA\\WorkflowEngine\\Check\\UserGroupMembership') {
return;
}

$(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: groups.find(group =>group.id === groupId).displayname
});
} else if (groupId) {
callback({
id: groupId,
displayname: groupId + 'FIXME' // FIXME
displayname: groupId
});
} else {
callback();
Expand Down

0 comments on commit a76d28e

Please sign in to comment.