UNPKG

zettapi_client

Version:

Client side CRUD operations in angular to use with zettapi_server rest api to get started quickly in any CMS project

28 lines (26 loc) 1.1 kB
app.service('$task', function($http, blockUI, $route, zapi) { this.toggleState = function(task) { blockUI.start('A executar...'); $http.get(zapi.serverUrl + '/api/task/toggle/' + task._id).then(function(response) { $route.reload(); }).catch(function(response) { swal("Tarefas", 'Ocorreu um erro ao alternar o estado da tarefa. Erro: ' + response.data, 'error'); }).finally(function() { blockUI.stop(); }); }; this.run = function(task) { return $http.get(zapi.serverUrl + '/api/task/run/' + task._id); }; this.getTypes = function(callback) { blockUI.start('A obter dados...'); $http.get(zapi.serverUrl + '/api/task/types').then(function(response) { callback(response.data); }).catch(function(response) { swal("Tarefas", 'Não foi possível atualizar a lista de tarefas neste momento. Tente novamente. Erro: ' + response.data, 'error'); callback([]); }).finally(function() { blockUI.stop(); }); }; });