Commit b9a36cb87f29e726e58deaca30cc170177cbbb59
1 parent
43cd5d45
Exists in
master
redmine #4583 exibição assinaturas por versões; criação de histórico de alteraçã…
…o de processo para assinaturas de documentos;
Showing
1 changed file
with
127 additions
and
0 deletions
Show diff stats
cit-ecm-web/src/main/webapp/assets/js/angular/custom/controller/AssinarDocumentoController.js
0 → 100644
... | ... | @@ -0,0 +1,127 @@ |
1 | +'use strict'; | |
2 | + | |
3 | + | |
4 | +citApp.controller('AssinarDocumentoController', [ '$scope', '$translate', 'GerenciarProcessoRepository', 'DocumentoGedRepository', 'HistoricoAlteracaoProcessoRepository', 'PessoaRepository', '$q', 'AssinaturaRepository', | |
5 | + function AssinarDocumentoController($scope, $translate, GerenciarProcessoRepository, DocumentoGedRepository, HistoricoAlteracaoProcessoRepository, PessoaRepository, $q, AssinaturaRepository) { | |
6 | + | |
7 | + /* | |
8 | + * Abre panel assinar documento | |
9 | + */ | |
10 | + $scope.abrirAssinarDocumento = function(documento) { | |
11 | + $scope.documentoSelecionado = null; | |
12 | + $scope.exibirDocJaAssinado = false; | |
13 | + DocumentoGedRepository.get(documento.id).then(function(result) { | |
14 | + $scope.documentoSelecionado = result.originalElement; | |
15 | + if(documento.formaCriacao.codigo === 1){ | |
16 | + __abrirAssinarDocOnline(documento); | |
17 | + } else if(documento.formaCriacao.codigo === 2){ | |
18 | + __abrirAssinarDocAnexo(documento); | |
19 | + } | |
20 | + }); | |
21 | + }; | |
22 | + | |
23 | + function __abrirAssinarDocOnline(documento){ | |
24 | + _obterAssinaturasDocumento(documento).then(function(documentosSelecionados){ | |
25 | + $scope.documentosSelecionados = documentosSelecionados; | |
26 | + _exibirNenhumaAssinatura(); | |
27 | + _validarAssinaturaPorUsuario(documento.id).then(function(exibirIncluirAssinatura){ | |
28 | + $scope.exibirIncluirAssinatura = !(exibirIncluirAssinatura == true); | |
29 | + //_obterPermissaoAssinaturaDocumentoExterno(); | |
30 | + }); | |
31 | + }); | |
32 | + } | |
33 | + | |
34 | + function __abrirAssinarDocAnexo(documento){ | |
35 | + _obterAssinaturasDocumento(documento).then(function(documentosSelecionados){ | |
36 | + $scope.documentosSelecionados = documentosSelecionados; | |
37 | + _exibirNenhumaAssinatura(); | |
38 | + _validarAssinaturaPorUsuario(documento.id).then(function(exibirIncluirAssinatura){ | |
39 | + $scope.exibirIncluirAssinatura = !(exibirIncluirAssinatura == true); | |
40 | + $scope.exibirDocJaAssinado = !$scope.exibirIncluirAssinatura; | |
41 | + //_obterPermissaoAssinaturaDocumentoExterno(); | |
42 | + }); | |
43 | + }); | |
44 | + }; | |
45 | + | |
46 | + function _validarAssinaturaPorUsuario(idDocumento){ | |
47 | + var deferred = $q.defer(); | |
48 | + AssinaturaRepository.validarAssinaturaPorUsuario(idDocumento).then(function(result){ | |
49 | + deferred.resolve(result); | |
50 | + }); | |
51 | + return deferred.promise; | |
52 | + } | |
53 | + | |
54 | + function _obterAssinaturasDocumento(documento) { | |
55 | + var deferred = $q.defer(); | |
56 | + var idRaiz = documento.idRaiz; | |
57 | + if ( !idRaiz ) | |
58 | + idRaiz = documento.id; | |
59 | + DocumentoGedRepository.findByIdDocumentoTodasVersoes(idRaiz).then(function(result) { | |
60 | + var results = []; | |
61 | + if(result.length>0){ | |
62 | + result.forEach(function(item){ | |
63 | + results.push(item.originalElement); | |
64 | + }); | |
65 | + } | |
66 | + deferred.resolve(results); | |
67 | + }); | |
68 | + return deferred.promise; | |
69 | + } | |
70 | + | |
71 | + $scope.assinar = function() { | |
72 | + if(!$scope.autenticacao){ | |
73 | + $scope.showAlert("error", $translate.instant('ECM.VALIDACAO.SENHA_ASSINATURA')); | |
74 | + return; | |
75 | + } | |
76 | + | |
77 | + AssinaturaRepository.saveAssinaturaInterna(_getAssinatura()).then(function(result){ | |
78 | + if($scope.documentoSelecionado.assinaturas) | |
79 | + $scope.documentoSelecionado.assinaturas.push(result.originalElement); | |
80 | + $scope.autenticacao = null; | |
81 | + $scope.exibirIncluirAssinatura = false; | |
82 | + $scope.nenhumaAssinatura = false; | |
83 | + $scope.documentosSelecionados.forEach(function(doc){ | |
84 | + if(doc.id == $scope.documentoSelecionado.id) | |
85 | + doc.assinaturas = $scope.documentoSelecionado.assinaturas; | |
86 | + }); | |
87 | + $scope.showAlert("success", $translate.instant('ECM.ASSINADO_SUCESSO')); | |
88 | + }); | |
89 | + }; | |
90 | + | |
91 | + function _getAssinatura(){ | |
92 | + return {documentoGed : { id : $scope.documentoSelecionado.id }, funcao : {id : _getFuncaoChecked()}, idTask : $scope.$parent.task.id }; | |
93 | + }; | |
94 | + | |
95 | + function _getFuncaoChecked(){ | |
96 | + for(var pos = 0; pos < $scope.funcoes.length; pos++){ | |
97 | + if($scope.funcoes[pos].isServidor) | |
98 | + return $scope.funcoes[pos].id; | |
99 | + } | |
100 | + }; | |
101 | + | |
102 | + /* | |
103 | + * Abre panel visualizar assinaturas | |
104 | + */ | |
105 | + $scope.visualizarAssinaturasDocumento = function(documento){ | |
106 | + $scope.documentoSelecionado = documento; | |
107 | + $scope.exibirIncluirAssinatura = false; | |
108 | + $scope.exibirDocJaAssinado = false; | |
109 | + _obterAssinaturasDocumento(documento).then(function(documentosSelecionados){ | |
110 | + $scope.documentosSelecionados = documentosSelecionados; | |
111 | + $scope.documentosSelecionados.forEach(function(doc){ | |
112 | + if(doc.id == $scope.documentoSelecionado.id) | |
113 | + $scope.documentoSelecionado = doc; | |
114 | + }); | |
115 | + _exibirNenhumaAssinatura(); | |
116 | + if($scope.documentoSelecionado.assinaturas && $scope.documentoSelecionado.assinaturas.length == 0) | |
117 | + $scope.showAlert("warning", $translate.instant('ECM.MSG.DOCUMENTO_SEM_ASSINATURAS')); | |
118 | + }); | |
119 | + }; | |
120 | + | |
121 | + function _exibirNenhumaAssinatura(){ | |
122 | + $scope.nenhumaAssinatura = $scope.documentosSelecionados.some(function(doc){ | |
123 | + return doc.assinaturas.length > 0; | |
124 | + }); | |
125 | + }; | |
126 | + | |
127 | +}] ); | |
0 | 128 | \ No newline at end of file | ... | ... |