Last active
August 29, 2015 14:05
-
-
Save EderRoger/2881316f916d087c4bca to your computer and use it in GitHub Desktop.
Angular Promise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
}); | |
}); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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