Skip to content

Instantly share code, notes, and snippets.

@EderRoger
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EderRoger/2881316f916d087c4bca to your computer and use it in GitHub Desktop.
Save EderRoger/2881316f916d087c4bca to your computer and use it in GitHub Desktop.
Angular Promise
function associaTarefaAoUsuario(){
$http({ method: 'PUT', url: context +'/bonita/humanTask/assign/' + $rootScope.idBonitasoft + '/' + $scope.tarefa.id})
.success(function (response) {
//obtem a tarefa associada e chama o form para realizar a tarefa
$http({ method: 'GET', url: context +'/bonita/humanTaskById/'+ $scope.tarefa.id})
.success(function (tarefaJsonResponse) {
$scope.tarefa = tarefaJsonResponse;
var tarefaUsuario = {
idProcessoBonitasoft : $scope.tarefa.processId.id,
idTarefaBonitasoft : $scope.tarefa.id,
situacao: situacao,
dhEvento: new Date()
}
$http({ method: 'POST', url: context + '/tarefa-bonita', data: tarefaUsuario })
.success(function (response, status, headers) {
$scope.$emit('loaderHide');
});
});
});
}
var deferred = $q.defer();
//associa a tarefa ao usuario
associaTarefaAoUsuario(deferred).then(function(resultTarefaAssociada){
//obtem a tarefa atravez do id
getTarefaById(deferred).then(function(resultTarefa){
//se nao estiver associada ele associa
atualizaStatusDaTarefaBonitaUsuario(SituacaoProcesso.INICIADO, deferred).then(function(result){
console.log('resolve');
$location.path("/bonita/processos/"+$scope.tarefa.processId.name+"/"+$scope.tarefa.processId.version+"/"+$scope.tarefa.id+"/"+$scope.tarefa.name);
}, function(error){
console.log("Ocorreu um erro ao atualizar o status da tarefa" + error);
});
}, function(error){
console.log("Erro ao obter a tarefa : " + error);
});
}, function(error){
console.log("Erro ao assoaciar a tarefa ao usuario " + error);
});
function associaTarefaAoUsuario(deferred){
$http({ method: 'PUT', url: context +'/bonita/humanTask/assign/' + $rootScope.idBonitasoft + '/' + $scope.tarefa.id})
.success(function (response) {
deferred.resolve();
});
return deferred.promise;
}
function getTarefaById(deferred){
//obtem a tarefa associada e chama o form para realizar a tarefa
$http({ method: 'GET', url: context +'/bonita/humanTaskById/'+ $scope.tarefa.id})
.success(function (tarefaJsonResponse) {
$scope.tarefa = tarefaJsonResponse;
deferred.resolve();
});
return deferred.promise;
}
function atualizaStatusDaTarefaBonitaUsuario(situacao, deferred){
//atualizando os dados para analise de status
var tarefaUsuario = {
idProcessoBonitasoft : $scope.tarefa.processId.id,
idTarefaBonitasoft : $scope.tarefa.id,
situacao: situacao,
dhEvento: new Date()
}
$http({ method: 'POST', url: context + '/tarefa-bonita', data: tarefaUsuario })
.success(function (response, status, headers) {
deferred.resolve();
$scope.$emit('loaderHide');
});
return deferred.promise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment