Workflow engine to ocs api

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-04-25 07:47:16 +02:00
parent d53193fd8e
commit 8c845be11c
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
1 changed files with 341 additions and 337 deletions

View File

@ -20,7 +20,7 @@
(function() { (function() {
Handlebars.registerHelper('selectItem', function(currentValue, itemValue) { Handlebars.registerHelper('selectItem', function(currentValue, itemValue) {
if(currentValue === itemValue) { if (currentValue === itemValue) {
return 'selected="selected"'; return 'selected="selected"';
} }
@ -153,7 +153,7 @@
initialize: function() { initialize: function() {
// this creates a new copy of the object to definitely have a new reference and being able to reset the model // 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)); this.originalModel = JSON.parse(JSON.stringify(this.model));
this.model.on('change', function(){ this.model.on('change', function() {
console.log('model changed'); console.log('model changed');
this.hasChanged = true; this.hasChanged = true;
this.render(); this.render();
@ -164,21 +164,23 @@
} }
var self = this; var self = this;
$.ajax({ $.ajax({
url: OC.generateUrl('settings/users/groups'), url: OC.linkToOCS('cloud/groups', 2) + 'details',
dataType: 'json', dataType: 'json',
quietMillis: 100, quietMillis: 100,
}).success(function(response) { }).success(function(response) {
// add admin groups if (data.ocs.data.groups && data.ocs.data.groups.length > 0) {
$.each(response.data.adminGroups, function(id, group) {
self.groups.push({ id: group.id, displayname: group.name }); data.ocs.data.groups.forEach(function(group) {
}); self.groups.push({ id: group.id, displayname: group.displayname });
// add groups })
$.each(response.data.groups, function(id, group) {
self.groups.push({ id: group.id, displayname: group.name });
});
self.render(); self.render();
} else {
OC.Notification.error(t('workflowengine', 'Group list is empty'), { type: 'error' });
console.log(data);
}
}).error(function(data) { }).error(function(data) {
OC.Notification.error(t('workflowengine', 'Unable to retrieve the group list'), {type: 'error'}); OC.Notification.error(t('workflowengine', 'Unable to retrieve the group list'), { type: 'error' });
console.log(data); console.log(data);
}); });
}, },
@ -194,7 +196,7 @@
reset: function() { reset: function() {
this.hasChanged = false; this.hasChanged = false;
// silent is need to not trigger the change event which resets the hasChanged attribute // silent is need to not trigger the change event which resets the hasChanged attribute
this.model.set(this.originalModel, {silent: true}); this.model.set(this.originalModel, { silent: true });
this.render(); this.render();
}, },
save: function() { save: function() {
@ -222,7 +224,7 @@
this.hasChanged = false; this.hasChanged = false;
this.saving = true; this.saving = true;
this.render(); this.render();
this.model.save(null, {success: success, error: error, context: this}); this.model.save(null, { success: success, error: error, context: this });
}, },
add: function() { add: function() {
var checks = _.clone(this.model.get('checks')), var checks = _.clone(this.model.get('checks')),
@ -234,7 +236,7 @@
'operator': operators[0]['operator'], 'operator': operators[0]['operator'],
'value': '' 'value': ''
}); });
this.model.set({'checks': checks}); this.model.set({ 'checks': checks });
}, },
checkChanged: function(event) { checkChanged: function(event) {
var value = event.target.value, var value = event.target.value,
@ -271,7 +273,7 @@
} }
} }
// model change will trigger render // model change will trigger render
this.model.set({'checks': checks}); this.model.set({ 'checks': checks });
}, },
deleteCheck: function(event) { deleteCheck: function(event) {
console.log(arguments); console.log(arguments);
@ -281,7 +283,7 @@
// splice removes 1 element at index `id` // splice removes 1 element at index `id`
checks.splice(id, 1); checks.splice(id, 1);
// model change will trigger render // model change will trigger render
this.model.set({'checks': checks}); this.model.set({ 'checks': checks });
}, },
operationChanged: function(event) { operationChanged: function(event) {
var value = event.target.value, var value = event.target.value,
@ -319,7 +321,7 @@
})); }));
var checks = this.model.get('checks'); var checks = this.model.get('checks');
_.each(this.$el.find('.check'), function(element){ _.each(this.$el.find('.check'), function(element) {
var $element = $(element), var $element = $(element),
id = $element.data('id'), id = $element.data('id'),
check = checks[id], check = checks[id],
@ -335,7 +337,7 @@
if (this.message !== '') { if (this.message !== '') {
// hide success messages after some time // hide success messages after some time
_.delay(function(elements){ _.delay(function(elements) {
$(elements).css('opacity', 0); $(elements).css('opacity', 0);
}, 7000, this.$el.find('.msg.success')); }, 7000, this.$el.find('.msg.success'));
this.message = ''; this.message = '';
@ -368,16 +370,18 @@
}); });
} }
this.collection.fetch({data: { this.collection.fetch({
data: {
'class': classname 'class': classname
}}); }
});
this.collection.once('sync', this.render, this); this.collection.once('sync', this.render, this);
}, },
add: function() { add: function() {
var operation = this.collection.create(); var operation = this.collection.create();
this.renderOperation(operation); this.renderOperation(operation);
}, },
renderOperation: function(subView){ renderOperation: function(subView) {
var operationsElement = this.$el.find('.operations'); var operationsElement = this.$el.find('.operations');
operationsElement.append(subView.$el); operationsElement.append(subView.$el);
subView.render(); subView.render();