diff options
author | Joas Schilling <coding@schilljs.com> | 2016-07-26 17:34:05 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-07-27 10:21:26 +0200 |
commit | 7588f648a14bd6ec3c2573ede5327b0277ecccf0 (patch) | |
tree | e81d03269e71ac0dae9d8a718e97a2dcee9cd4c9 /apps/workflowengine | |
parent | 318d68a9a95cc710aa30c24a84d78da280327aef (diff) | |
download | nextcloud-server-7588f648a14bd6ec3c2573ede5327b0277ecccf0.tar.gz nextcloud-server-7588f648a14bd6ec3c2573ede5327b0277ecccf0.zip |
Generate the checks list in JS
Diffstat (limited to 'apps/workflowengine')
-rw-r--r-- | apps/workflowengine/js/admin.js | 74 | ||||
-rw-r--r-- | apps/workflowengine/js/usergroupmembershipplugin.js | 10 | ||||
-rw-r--r-- | apps/workflowengine/templates/admin.php | 2 |
3 files changed, 50 insertions, 36 deletions
diff --git a/apps/workflowengine/js/admin.js b/apps/workflowengine/js/admin.js index f51352c45e4..590274b8770 100644 --- a/apps/workflowengine/js/admin.js +++ b/apps/workflowengine/js/admin.js @@ -28,11 +28,27 @@ }); Handlebars.registerHelper('getOperators', function(classname) { - return OCA.WorkflowEngine.availableChecks - .getOperatorsByClassName(classname); + var check = OCA.WorkflowEngine.getCheckByClass(classname); + if (!_.isUndefined(check)) { + return check['operators']; + } + return []; }); - OCA.WorkflowEngine = OCA.WorkflowEngine || {}; + OCA.WorkflowEngine = OCA.WorkflowEngine || { + availablePlugins: [], + availableChecks: [], + + getCheckByClass: function(className) { + var length = OCA.WorkflowEngine.availableChecks.length; + for (var i = 0; i < length; i++) { + if (OCA.WorkflowEngine.availableChecks[i]['class'] === className) { + return OCA.WorkflowEngine.availableChecks[i]; + } + } + return undefined; + } + }; /** * 888b d888 888 888 @@ -87,22 +103,6 @@ }); /** - * @class OCA.WorkflowEngine.AvailableChecksCollection - * - * collection for all available checks - */ - OCA.WorkflowEngine.AvailableChecksCollection = - OC.Backbone.Collection.extend({ - model: OCA.WorkflowEngine.AvailableCheck, - url: OC.generateUrl('apps/workflowengine/checks'), - getOperatorsByClassName: function(classname) { - return OCA.WorkflowEngine.availableChecks - .findWhere({'class': classname}) - .get('operators'); - } - }); - - /** * 888 888 d8b * 888 888 Y8P * 888 888 @@ -154,7 +154,6 @@ message: '', errorMessage: '', saving: false, - plugins: [], 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)); @@ -167,13 +166,6 @@ if (this.model.get('id') === undefined) { this.hasChanged = true; } - - this.plugins = OC.Plugins.getPlugins('OCA.WorkflowEngine.CheckPlugins'); - _.each(this.plugins, function(plugin) { - if (_.isFunction(plugin.initialize)) { - plugin.initialize(); - } - }); }, delete: function() { this.model.destroy(); @@ -209,9 +201,8 @@ }, add: function() { var checks = _.clone(this.model.get('checks')), - classname = OCA.WorkflowEngine.availableChecks.at(0).get('class'), - operators = OCA.WorkflowEngine.availableChecks - .getOperatorsByClassName(classname); + classname = OCA.WorkflowEngine.availableChecks[0]['class'], + operators = OCA.WorkflowEngine.availableChecks[0]['operators']; checks.push({ 'class': classname, @@ -249,9 +240,10 @@ // if the class is changed most likely also the operators have changed // with this we set the operator to the first possible operator if (key === 'class') { - var operators = OCA.WorkflowEngine.availableChecks - .getOperatorsByClassName(value); - checks[id]['operator'] = operators[0]; + var check = OCA.WorkflowEngine.getCheckByClass(value); + if (!_.isUndefined(check)) { + checks[id]['operator'] = check['operators'][0]; + } } // model change will trigger render this.model.set({'checks': checks}); @@ -294,7 +286,7 @@ render: function() { this.$el.html(this.template({ operation: this.model.toJSON(), - classes: OCA.WorkflowEngine.availableChecks.toJSON(), + classes: OCA.WorkflowEngine.availableChecks, hasChanged: this.hasChanged, message: this.message, errorMessage: this.errorMessage, @@ -308,7 +300,7 @@ check = checks[id], valueElement = $element.find('.check-value').first(); - _.each(this.plugins, function(plugin) { + _.each(OCA.WorkflowEngine.availablePlugins, function(plugin) { if (_.isFunction(plugin.render)) { plugin.render(valueElement, check['class'], check['value']); } @@ -334,6 +326,8 @@ OCA.WorkflowEngine.OperationsView = OCA.WorkflowEngine.TemplateView.extend({ templateId: '#operations-template', + collection: null, + $el: null, events: { 'click .button-add-operation': 'add' }, @@ -341,6 +335,16 @@ this._initialize('OCA\\WorkflowEngine\\Operation'); }, _initialize: function(classname) { + OCA.WorkflowEngine.availablePlugins = OC.Plugins.getPlugins('OCA.WorkflowEngine.CheckPlugins'); + _.each(OCA.WorkflowEngine.availablePlugins, function(plugin) { + if (_.isFunction(plugin.initialize)) { + plugin.initialize(); + } + if (_.isFunction(plugin.getCheck)) { + OCA.WorkflowEngine.availableChecks.push(plugin.getCheck()); + } + }); + this.collection.fetch({data: { 'class': classname }}); diff --git a/apps/workflowengine/js/usergroupmembershipplugin.js b/apps/workflowengine/js/usergroupmembershipplugin.js index 2a6068cda90..528a7bd3e3d 100644 --- a/apps/workflowengine/js/usergroupmembershipplugin.js +++ b/apps/workflowengine/js/usergroupmembershipplugin.js @@ -24,6 +24,16 @@ OCA.WorkflowEngine.Plugins = OCA.WorkflowEngine.Plugins || {}; OCA.WorkflowEngine.Plugins.UserGroupMembershipPlugin = { + getCheck: function() { + return { + 'class': 'OCA\\WorkflowEngine\\Check\\UserGroupMembership', + 'name': t('workflowengine', 'User group membership'), + 'operators': [ + {'operator': 'is', 'name': t('workflowengine', 'is member of')}, + {'operator': '!is', 'name': t('workflowengine', 'is not member of')} + ] + }; + }, render: function(element, classname, value) { if (classname !== 'OCA\\WorkflowEngine\\Check\\UserGroupMembership') { return; diff --git a/apps/workflowengine/templates/admin.php b/apps/workflowengine/templates/admin.php index 86ecfe08556..cb6895f80c1 100644 --- a/apps/workflowengine/templates/admin.php +++ b/apps/workflowengine/templates/admin.php @@ -48,7 +48,7 @@ </select> <select class="check-operator"> {{#each (getOperators class)}} - <option value="{{this}}" {{selectItem this ../operator}}>{{this}}</option> + <option value="{{operator}}" {{selectItem this.operator ../operator}}>{{name}}</option> {{/each}} </select> <input type="text" class="check-value" value="{{value}}"> |