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

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