2016-06-04 14:58:11 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('ffffngAdmin')
|
|
|
|
.directive('faTaskActionButton', function (Restangular, $state, notification) {
|
|
|
|
var link = function (scope) {
|
|
|
|
scope.label = scope.label || 'ACTION';
|
|
|
|
scope.icon = scope.icon || 'play';
|
2016-06-05 12:18:37 +02:00
|
|
|
scope.button = scope.button || 'default';
|
2016-06-04 14:58:11 +02:00
|
|
|
|
|
|
|
scope.perform = function () {
|
|
|
|
var task = scope.task();
|
|
|
|
|
|
|
|
Restangular
|
|
|
|
.one('/internal/api/tasks/' + scope.action, task.values.id).put()
|
|
|
|
.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': '@',
|
2016-06-05 12:18:37 +02:00
|
|
|
'label': '@',
|
|
|
|
'button': '@',
|
|
|
|
'disabled': '='
|
2016-06-04 14:58:11 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'template':
|
2016-06-05 12:18:37 +02:00
|
|
|
'<button class="btn btn-{{ button }}" ng-disabled="disabled" ng-class="size ? \'btn-\' + size : \'\'" ng-click="perform()">' +
|
2016-06-07 10:50:15 +02:00
|
|
|
'<span class="fa fa-{{ icon }}" aria-hidden="true"></span> <span class="hidden-xs">{{ label }}</span>' +
|
2016-06-05 12:18:37 +02:00
|
|
|
'</button>'
|
2016-06-04 14:58:11 +02:00
|
|
|
};
|
|
|
|
});
|