ffffng/admin/js/views/taskActionButton.js

43 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2016-06-04 14:58:11 +02:00
'use strict';
angular.module('ffffngAdmin')
.directive('faTaskActionButton', function (Restangular, $state, notification) {
2016-06-04 14:58:11 +02:00
var link = function (scope) {
scope.label = scope.label || 'ACTION';
scope.icon = scope.icon || 'play';
scope.button = scope.button || 'default';
2016-06-04 14:58:11 +02:00
scope.perform = function () {
var task = scope.task();
Restangular
.one('tasks/' + scope.action, task.values.id).put()
2016-06-04 14:58:11 +02:00
.then(function () { $state.reload() })
.then(function () { notification.log('Done', { addnCls: 'humane-flatty-success' }); })
.catch(function (e) {
notification.log('Error: ' + e.data, { addnCls: 'humane-flatty-error' });
console.error(e)
});
};
};
return {
'link': link,
'restrict': 'E',
'scope': {
'action': '@',
'icon': '@',
'task': '&',
'size': '@',
'label': '@',
'button': '@',
'disabled': '='
2016-06-04 14:58:11 +02:00
},
'template':
'<button class="btn btn-{{ button }}" ng-disabled="disabled" ng-class="size ? \'btn-\' + size : \'\'" ng-click="perform()">' +
'<span class="fa fa-{{ icon }}" aria-hidden="true"></span>&nbsp;<span class="hidden-xs">{{ label }}</span>' +
'</button>'
2016-06-04 14:58:11 +02:00
};
});