diff --git a/cit-contratos-api/src/main/java/br/com/centralit/api/model/Contrato.java b/cit-contratos-api/src/main/java/br/com/centralit/api/model/Contrato.java index 0273ff8..56bad89 100644 --- a/cit-contratos-api/src/main/java/br/com/centralit/api/model/Contrato.java +++ b/cit-contratos-api/src/main/java/br/com/centralit/api/model/Contrato.java @@ -367,6 +367,10 @@ public class Contrato extends PersistentObjectAuditOrganizacao { @JsonView({ ViewsContrato.ContratoEditView.class, ViewsContrato.ContratoAutoCompleteView.class }) private TermoReferencia termoReferencia; + @Transient + @JsonView({ ViewsContrato.ContratoEditView.class }) + private Long rascunho; + /** * Retorna o valor do atributo id * @@ -1143,4 +1147,11 @@ public class Contrato extends PersistentObjectAuditOrganizacao { this.termoReferencia = termoReferencia; } + public Long getRascunho() { + return rascunho; + } + + public void setRascunho(Long rascunho) { + this.rascunho = rascunho; + } } diff --git a/cit-contratos-api/src/main/java/br/com/centralit/api/model/EstudoTecnico.java b/cit-contratos-api/src/main/java/br/com/centralit/api/model/EstudoTecnico.java index 81a5549..dd33ff4 100644 --- a/cit-contratos-api/src/main/java/br/com/centralit/api/model/EstudoTecnico.java +++ b/cit-contratos-api/src/main/java/br/com/centralit/api/model/EstudoTecnico.java @@ -16,6 +16,7 @@ import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import javax.persistence.Transient; import br.com.centralit.api.viewHelper.ViewsContrato; import br.com.centralit.framework.json.JsonCalendarSimpleDateDeserializer; @@ -167,6 +168,10 @@ public class EstudoTecnico extends PersistentObjectAuditOrganizacao { @JsonView({ ViewsContrato.EstudoTecnicoEditView.class }) private Collection documentos; + @Transient + @JsonView({ ViewsContrato.EstudoTecnicoEditView.class }) + private Long rascunho; + public RegistroSequencial getRegistroSequencial() { return registroSequencial; @@ -623,4 +628,11 @@ public class EstudoTecnico extends PersistentObjectAuditOrganizacao { this.documentos = documentos; } + public Long getRascunho() { + return rascunho; + } + + public void setRascunho(Long rascunho) { + this.rascunho = rascunho; + } } diff --git a/cit-contratos-api/src/main/java/br/com/centralit/api/model/TermoReferencia.java b/cit-contratos-api/src/main/java/br/com/centralit/api/model/TermoReferencia.java index 77c1098..5bd64aa 100644 --- a/cit-contratos-api/src/main/java/br/com/centralit/api/model/TermoReferencia.java +++ b/cit-contratos-api/src/main/java/br/com/centralit/api/model/TermoReferencia.java @@ -16,6 +16,7 @@ import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import javax.persistence.Transient; import org.hibernate.annotations.Type; @@ -151,6 +152,10 @@ public class TermoReferencia extends PersistentObjectAuditOrganizacao { @JsonView({ ViewsContrato.TermoReferenciaEditView.class }) private Collection documentos; + @Transient + @JsonView({ ViewsContrato.TermoReferenciaEditView.class }) + private Long rascunho; + /** * Retorna o valor do atributo id * @@ -663,4 +668,11 @@ public class TermoReferencia extends PersistentObjectAuditOrganizacao { this.dataTermoGerado = dataTermoGerado; } + public Long getRascunho() { + return rascunho; + } + + public void setRascunho(Long rascunho) { + this.rascunho = rascunho; + } } diff --git a/cit-contratos-api/src/main/java/br/com/centralit/api/service/impl/ContratoServiceImpl.java b/cit-contratos-api/src/main/java/br/com/centralit/api/service/impl/ContratoServiceImpl.java index 2ab36bf..d6a79c6 100644 --- a/cit-contratos-api/src/main/java/br/com/centralit/api/service/impl/ContratoServiceImpl.java +++ b/cit-contratos-api/src/main/java/br/com/centralit/api/service/impl/ContratoServiceImpl.java @@ -40,6 +40,7 @@ import br.com.centralit.api.service.EventoAditivoService; import br.com.centralit.api.service.FornecedorService; import br.com.centralit.api.service.InternacionalizacaoService; import br.com.centralit.api.service.ParceiroService; +import br.com.centralit.api.service.RascunhoService; import br.com.centralit.api.service.UsuarioService; import br.com.centralit.framework.exception.CodigoErro; import br.com.centralit.framework.model.Dominio; @@ -102,7 +103,7 @@ public class ContratoServiceImpl extends GenericServiceImpl impl @Autowired private ConfiguracaoParametroSistemaService configuracaoParametroSistemaService; - /** Atributo colaboradorService. */ + @Autowired private EstudoTecnicoService estudoTecnicoService; @@ -115,6 +116,9 @@ public class ContratoServiceImpl extends GenericServiceImpl impl @Autowired private EventoAditivoService aditivoService; + @Autowired + private RascunhoService rascunhoService; + /** * Responsável pela criação de novas instâncias desta classe. * @param contratoDao @@ -156,6 +160,8 @@ public class ContratoServiceImpl extends GenericServiceImpl impl validarPapeisEnvolvidos(contrato); + rascunhoService.removeById(contrato.getRascunho()); + return super.save(contrato); } diff --git a/cit-contratos-api/src/main/java/br/com/centralit/api/service/impl/EstudoTecnicoServiceImpl.java b/cit-contratos-api/src/main/java/br/com/centralit/api/service/impl/EstudoTecnicoServiceImpl.java index 696d796..3459710 100644 --- a/cit-contratos-api/src/main/java/br/com/centralit/api/service/impl/EstudoTecnicoServiceImpl.java +++ b/cit-contratos-api/src/main/java/br/com/centralit/api/service/impl/EstudoTecnicoServiceImpl.java @@ -39,6 +39,7 @@ import br.com.centralit.api.service.EstudoTecnicoService; import br.com.centralit.api.service.FuncaoService; import br.com.centralit.api.service.ObjetivoEstrategicoNecessidadeService; import br.com.centralit.api.service.ParceiroService; +import br.com.centralit.api.service.RascunhoService; import br.com.centralit.api.service.TermoReferenciaService; import br.com.centralit.api.service.UsuarioService; import br.com.centralit.framework.exception.CodigoErro; @@ -114,6 +115,9 @@ public class EstudoTecnicoServiceImpl extends GenericServiceImpl @@ -122,8 +124,10 @@ public class TermoReferenciaServiceImpl extends GenericServiceImpl= 1 && $scope.permitidoAvancar) { - $scope.termoReferenciaForm.justificativaContratacaoForm.$submitted = true; - } - break; - case 2 : - //especificacoesTecnicasForm - if (isFormValid($scope.termoReferenciaForm.especificacoesTecnicasForm) && $scope.permitidoAvancar) { - $scope.termoReferenciaForm.especificacoesTecnicasForm.$submitted = true; - } - break; - case 3 : - //modeloGestaoForm - if (isFormValid($scope.termoReferenciaForm.modeloGestaoForm) && $scope.permitidoAvancar) { - $scope.termoReferenciaForm.modeloGestaoForm.$submitted = true; - } - break; - case 4 : - //sancoesForm - if (($scope.termoReferencia.sancoes.length >= 1 || $scope.termoReferencia.penalidades.length >= 1) && $scope.permitidoAvancar) { - $scope.termoReferenciaForm.sancoesForm.$submitted = true; - } - break; - case 5 : - //criteriosSelecaoForm - if (isFormValid($scope.termoReferenciaForm.criteriosSelecaoForm) && $scope.permitidoAvancar) { - $scope.termoReferenciaForm.criteriosSelecaoForm.$submitted = true; - } - break; - case 6 : - //anexosObservacoesForm - $scope.termoReferenciaForm.anexosObservacoesForm.$submitted = true; - break; - } - - if (!$scope.permitidoAvancar && !$scope.stepValid) { - //Mensagem de erro de campos obrigatorios nao preenchidos - $scope.showAlert('error', $translate.instant('VALIDACAO.ALERTA_OBRIGATORIOS'), " ", false); - } - }; - - //Evita erros verificando se determinadas propriedades existem no form. - function isFormValid (form) { - $scope.stepValid = true; - if (form && form.$invalid) { - $scope.stepValid = false; - } - return $scope.stepValid; - }; - //Evita erros verificando se determinadas propriedades existem no form. - function isFormSubmited (form){ - var submitted = false; - if(form && form.$submitted){ - submitted = true; - } - return submitted; - } - - - $scope.getClassEdit = function (step){ - - switch (step) { - case 0 : - //equipeContratacaoForm - return {'active': $scope.isCurrentStep(step), - 'complete' : ($scope.step >= step && isFormValid($scope.termoReferenciaForm.equipeContratacaoForm)), - 'invalid' : (isFormSubmited($scope.termoReferenciaForm.equipeContratacaoForm)|| $scope.step > step) && (!isFormValid($scope.termoReferenciaForm.equipeContratacaoForm))}; - break; - case 1 : - //justificativaContratacaoForm - return {'active': $scope.isCurrentStep(step), - 'complete' : ($scope.step > step && isFormValid($scope.termoReferenciaForm.justificativaContratacaoForm) && $scope.termoReferencia.detalhamentosSolucoes.length >= 1 ), - 'invalid' : (isFormSubmited($scope.termoReferenciaForm.justificativaContratacaoForm) || $scope.step > step) && (!isFormValid($scope.termoReferenciaForm.justificativaContratacaoForm) || $scope.termoReferencia.detalhamentosSolucoes.length < 1)}; - break; - case 2 : - //especificacoesTecnicasForm - return {'active': $scope.isCurrentStep(step), - 'complete' : ($scope.step > step && isFormValid($scope.termoReferenciaForm.especificacoesTecnicasForm)), - 'invalid' : (isFormSubmited($scope.termoReferenciaForm.especificacoesTecnicasForm) || $scope.step > step) && !isFormValid($scope.termoReferenciaForm.especificacoesTecnicasForm)}; - break; - case 3 : - //modeloGestaoForm - return {'active': $scope.isCurrentStep(step), - 'complete' : ($scope.step > step || ($scope.step > step && isFormSubmited($scope.termoReferenciaForm.modeloGestaoForm)))}; - break; - case 4 : - //sancoesForm - return {'active': $scope.isCurrentStep(step), - 'complete' : ($scope.step > step && isFormValid($scope.termoReferenciaForm.sancoesForm) && ($scope.termoReferencia.sancoes.length >= 1 && $scope.termoReferencia.penalidades.length >= 1)), - 'invalid' : ($scope.step > step && ($scope.termoReferencia.sancoes.length < 1 || $scope.termoReferencia.penalidades.length < 1))}; - break; - case 5 : - //criteriosSelecaoForm - return {'active': $scope.isCurrentStep(step), - 'complete' : ($scope.step > step && isFormValid($scope.termoReferenciaForm.criteriosSelecaoForm)), - 'invalid' : ((isFormSubmited($scope.termoReferenciaForm.criteriosSelecaoForm) || $scope.step > step) && !isFormValid($scope.termoReferenciaForm.criteriosSelecaoForm))}; - break; - case 6 : - //anexosObservacoesForm - return {'active': $scope.isCurrentStep(step) || isFormSubmited($scope.termoReferenciaForm.anexosObservacoesForm), - 'complete' : ($scope.isCurrentStep(step) || ($scope.step > step && isFormSubmited($scope.termoReferenciaForm.anexosObservacoesForm)))}; - break; - }; - }; - - $scope.getClassList = function (){ - return {'active': false, 'complete' : true, 'invalid' : false}; - }; + }; + + // ADICIONAR Penalidade + $scope.addSancao = function(formSancao, continuarEditando) { + + var sans = $scope.sancao; + + formSancao.$submitted = true; + + //verifica se o formulario esta valido para salvar + if (formSancao.$invalid) { + //Mensagem de erro de campos obrigatorios nao preenchidos + $scope.showAlert('error', $translate.instant('VALIDACAO.ALERTA_OBRIGATORIOS'), " ", false); + return; + } + + $scope.setLoadingSalva(true); + + if (sans.$index != undefined && sans.$index != null) { + $scope.termoReferencia.sancoes[sans.$index] = sans; + } else { + $scope.termoReferencia.sancoes.push(sans); + } + + $scope.setLoadingSalva(false); + + if(continuarEditando){ + formSancao.$submitted = false; + formSancao.$setPristine(); + $scope.sancao = {}; + } else { + $scope.$modalInstance.dismiss('cancel'); + } + }; + + //Watch para calcular total + $scope.$watch('termoReferenciaDetalhamentoSolucao.valor', function() { + $timeout(function() { + if ($scope.termoReferenciaDetalhamentoSolucao && ($scope.termoReferenciaDetalhamentoSolucao.valor && $scope.termoReferenciaDetalhamentoSolucao.quantidade)) { + $scope.termoReferenciaDetalhamentoSolucao.total = $scope.termoReferenciaDetalhamentoSolucao.valor * $scope.termoReferenciaDetalhamentoSolucao.quantidade; + } else { + if ($scope.termoReferenciaDetalhamentoSolucao) { + $scope.termoReferenciaDetalhamentoSolucao.total = null; + } + } + }); + }); + + //Watch para calcular total + $scope.$watch('termoReferenciaDetalhamentoSolucao.quantidade', function() { + $timeout(function() { + if ($scope.termoReferenciaDetalhamentoSolucao && ($scope.termoReferenciaDetalhamentoSolucao.valor && $scope.termoReferenciaDetalhamentoSolucao.quantidade)) { + $scope.termoReferenciaDetalhamentoSolucao.total = $scope.termoReferenciaDetalhamentoSolucao.valor * $scope.termoReferenciaDetalhamentoSolucao.quantidade; + } else { + if ($scope.termoReferenciaDetalhamentoSolucao) { + $scope.termoReferenciaDetalhamentoSolucao.total = null; + } + } + }); + }); + + $scope.getConfiguracoesTemplate = function () { + ConfiguracaoRepository.getConfiguracao($scope.usuarioLogado.organizacao.id).then(function (result) { + var configTemp = result.originalElement; + var parametro; + for (var i = 0; i < configTemp.parametros.length; i++){ + parametro = configTemp.parametros[i]; + switch (parametro.chave) { + case "DEVERES_RESPONSABILIDADES_CONTRATANTE" : + $scope.termoReferencia.deveresContratante = parametro.valor; + break; + case "DEVERES_RESPONSABILIDADES_CONTRATADA" : + $scope.termoReferencia.deveresContratada = parametro.valor; + break; + case "DEVERES_RESPONSABILIDADES_ORGAO" : + $scope.termoReferencia.deveresOrgaoRegistroPreco = parametro.valor; + break; + case "MECANISMOS_FORMAIS_COMUNICACAO" : + $scope.termoReferencia.mecanismoComunicacao = parametro.valor; + break; + }; + }; + }); + }; + + // marca DetalhamentoSolucao + $scope.checkDetalhamentoSolucao = function(index) { + $timeout(function() { + for (var i = 0; i < $scope.termoReferencia.detalhamentosSolucoes.length; i++) { + if (i == index) { + $scope.termoReferencia.detalhamentosSolucoes[i].$checked = true; + } else { + $scope.termoReferencia.detalhamentosSolucoes[i].$checked = false; + } + } + $scope.atualizarListaSizeSelect(); + }); + }; + + // recupera DetalhamentoSolucao selecionada + $scope.getDetalhamentoSolucaoChecked = function() { + var detalhamentoSolucaoChecked = undefined; + $scope.termoReferenciaDetalhamentoSolucao = {}; + $scope.termoReferencia.detalhamentosSolucoes.forEach(function(detalhe) { + if (detalhe.$checked) { + detalhamentoSolucaoChecked = detalhe; + } + }); + + return detalhamentoSolucaoChecked; + }; + + // marca Penalidade + $scope.checkPenalidade = function(index) { + $timeout(function() { + for (var i = 0; i < $scope.termoReferencia.penalidades.length; i++) { + if (i == index) { + $scope.termoReferencia.penalidades[i].$checked = true; + } else { + $scope.termoReferencia.penalidades[i].$checked = false; + } + } + $scope.atualizarListaSizeSelectPenalidade(); + }); + }; + + // recupera Penalidade selecionada + $scope.getPenalidadeChecked = function() { + var penalidadeChecked = undefined; + $scope.termoReferenciaPenalidade = {}; + $scope.termoReferencia.penalidades.forEach(function(penalidade) { + if (penalidade.$checked) { + penalidadeChecked = penalidade; + } + }); + + return penalidadeChecked; + }; + + // marca Sancao + $scope.checkSancao = function(index) { + $timeout(function() { + for (var i = 0; i < $scope.termoReferencia.sancoes.length; i++) { + if (i == index) { + $scope.termoReferencia.sancoes[i].$checked = true; + } else { + $scope.termoReferencia.sancoes[i].$checked = false; + } + } + $scope.atualizarListaSizeSelectSancao(); + }); + }; + + // recupera Sancao selecionada + $scope.getSancaoChecked = function() { + var sancaoChecked = undefined; + $scope.termoReferenciaSancao = {}; + $scope.termoReferencia.sancoes.forEach(function(sancao) { + if (sancao.$checked) { + sancaoChecked = sancao; + } + }); + + return sancaoChecked; + }; + + $scope.preenchePapeis = function(){ + DominioRepository.findAllDominio('tipoPapelEquipeContratos').then(function(result) { + $scope.dominioPapeis = result; + + angular.forEach($scope.dominioPapeis, function(value, key){ + $scope.papeis+= value.descricao + '\n'; + }); + + }); + + }; + + $scope.carregarValoresPadrao = function() { + DominioRepository.findAllDominioByCodigo('tipoEmpreitada', 2).then(function(result) { + $scope.termoReferencia.empreitada = result.originalElement; + }); + + DominioRepository.findAllDominioByCodigo('tipoAdjudicacaoObjeto', 2).then(function(result) { + $scope.termoReferencia.adjudicacaoObjeto = result.originalElement; + }); + + if($scope.dominioTiposSancaoList){ + angular.forEach($scope.dominioTiposSancaoList, function(sancaoDominio) { + var sans = {sancao : sancaoDominio.descricao, dominioTipoSancao : sancaoDominio.originalElement, descricao : $translate.instant('LABEL.DESCREVER_SANCAO')}; + $scope.termoReferencia.sancoes.push(sans); + }); + } + }; + + //###################### METODOS DA BARRA DE ACOES DO FORMULARIO #################################### + + function setFormsTermoReferenciaSubmitted(valor){ + $scope.termoReferenciaForm.$submitted = valor; + $scope.termoReferenciaForm.equipeContratacaoForm.$submitted = valor; + $scope.termoReferenciaForm.justificativaContratacaoForm.$submitted = valor; + $scope.termoReferenciaForm.especificacoesTecnicasForm.$submitted = valor; + $scope.termoReferenciaForm.modeloGestaoForm.$submitted = valor; + $scope.termoReferenciaForm.sancoesForm.$submitted = valor; + $scope.termoReferenciaForm.criteriosSelecaoForm.$submitted = valor; + $scope.termoReferenciaForm.anexosObservacoesForm.$submitted = valor; + } + // SALVA O TERMO + $scope.saveOrUpdate = function(){ + + setFormsTermoReferenciaSubmitted(true); + + //Vefifica se o termoReferenciaForm esta invalido, caso esteja envia um alerta para o usuario + if($scope.termoReferenciaForm.$invalid){ + $scope.showAlert('error', $translate.instant('MSG.MN001')); + } else { + var termoTemp = { + documentos: [] + }; + + // preencher lista de documentos temporarios para verificacao dos anexos. verificar qual anexo e de qual documento pelo numero do documento + angular.forEach($scope.termoReferencia.documentos, function(documento, key) { + if (documento.uploadsDocumento) { + termoTemp.documentos.push({ + uploadsDocumento: clone(documento.uploadsDocumento), + numero: clone(documento.numero) + }); + // deleta esse atributo por causa de um erro de ciclo no json + delete documento.uploadsDocumento; + } + }); + + $scope.setLoadingSalva(true); + + $scope.termoReferencia.rascunho = $scope.workspace.rascunho.id; + TermoReferenciaRepository.save($scope.termoReferencia).then(function(result) { + + $scope.termoReferencia = result.originalElement; + $scope.atualizaListaBeneficiosEsperados($scope.termoReferencia.estudoTecnico); + $scope.atualizaListaJustificativasContratacao($scope.termoReferencia.estudoTecnico); + $scope.atualizaInformacoesIntegrantesEstudoTecnico($scope.termoReferencia.estudoTecnico); + + $scope.setLoading(false); + $scope.showAlert("success", $translate.instant('MSG.SUCESSO_SALVAR_TERMO_REFERENCIA')); + // depois de salvar o termo ja tendo uma referencia do id do termo, esse metodo ira salvar os documentos se houver + salvarListaDocumentos(termoTemp); + setFormsTermoReferenciaSubmitted(false); + }); + }; + }; + + $scope.editar = function () { + if ($scope.termoReferencia.dataTermoGerado){ + $scope.showAlert('warning', $translate.instant('MSG.TERMO_REFERENCIA_JA_GERADO')); + $scope.setLoadingGet(false); + } else { + $scope.edit = true; + $scope.pgEdit = true; + } + }; + + // Consulta entidade e mostra no formulario + $scope.getTermo = function(idTermo, edit) { + $scope.resetForm(); + $scope.setLoadingGet(true); + + TermoReferenciaRepository.get(idTermo).then(function(result) { + + $scope.termoReferencia = result.originalElement; + $scope.edit = edit; + $scope.atualizaListaBeneficiosEsperados($scope.termoReferencia.estudoTecnico); + $scope.atualizaListaJustificativasContratacao($scope.termoReferencia.estudoTecnico); + $scope.atualizaInformacoesIntegrantesEstudoTecnico($scope.termoReferencia.estudoTecnico); + $scope.setLoading(false); + }); + }; + + // MODAL QUE CONFIRMA REMOVER TERMO + $scope.remover = function(termo){ + $scope.$openModalConfirm({ + message: $translate.instant('MSG.CONFIRMA_EXCLUIR_TERMO_REFERENCIA'), + callback: function () { + TermoReferenciaRepository.remove(termo).then(function() { + $scope.termoReferencia = {}; + + $scope.showAlert("success", $translate.instant('MSG.SUCESSO_EXCLUSAO_TERMO_REFERENCIA')); + angular.element('#searchTermoReferencia').scope().fetchResult(); + + }); + + $scope.$modalConfirmInstance.dismiss('cancel'); + $scope.resetForm(); + } + }); + }; + + $scope.abrirDetalhamentoSolucao = function(edit) { + + $scope.termoReferenciaDetalhamentoSolucao = clone($scope.getDetalhamentoSolucaoChecked()); + + $scope.editDetalhamento = edit; + + if(!edit && !$scope.termoReferenciaDetalhamentoSolucao) {//DetalhamentoSolucao + $scope.showAlert('warning', $translate.instant('MSG.SELECIONE_UM_ITEM_PARA_VISUALIZACAO')); + return; + } + + if(edit && !$scope.termoReferenciaDetalhamentoSolucao) { + $scope.showAlert('warning', $translate.instant('MSG.SELECIONE_UM_ITEM_PARA_EDICAO')); + return; + } + + if ($scope.termoReferenciaDetalhamentoSolucao.prazoEntrega){ + + $scope.termoReferenciaDetalhamentoSolucao.prazoEntrega = $filter('date')( $scope.termoReferenciaDetalhamentoSolucao.prazoEntrega, "dd/MM/yyyy"); + } + + $timeout(function() { + $scope.$openModal('modal-detalhamento-solucao.html', 'lg'); + }); + }; + + $scope.abrirPenalidade = function(edit) { + + $scope.penalidade = clone($scope.getPenalidadeChecked()); + + $scope.editPenalidade = edit; + + if(!edit && !$scope.penalidade) { + $scope.showAlert('warning', $translate.instant('MSG.SELECIONE_UM_ITEM_PARA_VISUALIZACAO')); + return; + } + + if(edit && !$scope.penalidade) { + $scope.showAlert('warning', $translate.instant('MSG.SELECIONE_UM_ITEM_PARA_EDICAO')); + return; + } + + $timeout(function() { + $scope.$openModal('modal-penalidade.html', 'lg'); + }); + }; + + $scope.abrirSancao = function(edit) { + + $scope.sancao = clone($scope.getSancaoChecked()); + + $scope.editSancao = edit; + + if(!edit && !$scope.sancao) { + $scope.showAlert('warning', $translate.instant('MSG.SELECIONE_UM_ITEM_PARA_VISUALIZACAO')); + return; + } + + if(edit && !$scope.sancao) { + $scope.showAlert('warning', $translate.instant('MSG.SELECIONE_UM_ITEM_PARA_EDICAO')); + return; + } + + $timeout(function() { + $scope.$openModal('modal-sancao.html', 'lg'); + }); + }; + + $scope.removerPenalidade = function() { + $scope.penalidade = $scope.getPenalidadeChecked(); + + if ($scope.penalidade) { + $scope.$openModalConfirm({ + message: $translate.instant('MSG.CONFIRMA_EXCLUSAO'), + callback: function() { + var index = 0; + + $scope.termoReferencia.penalidades.forEach(function(penalidade, key) { + if (penalidade.$checked) { + index = key; + } + }); + + $scope.termoReferencia.penalidades.splice(index, 1); + $scope.atualizarListaSizeSelectPenalidade(); + $scope.$modalConfirmInstance.dismiss('cancel'); + } + }); + } else { + $scope.showAlert('warning', $translate.instant('MSG.SELECIONE_UM_ITEM_PARA_SER_REMOVIDO')); + } + }; + + $scope.removerSancao = function() { + $scope.sancao = $scope.getSancaoChecked(); + + if ($scope.sancao) { + EventoRegistroNaoConformidadeRepository.existeVinculoSancoesComNaoConformidade($scope.sancao.id).then(function(result) { + if(result){ + $scope.showAlert('warning', $translate.instant('CONTRATOS.MSG.SANCAO_VINCULADA_NAO_CONFORMIDADE')); + }else{ + $scope.$openModalConfirm({ + message: $translate.instant('MSG.CONFIRMA_EXCLUSAO'), + callback: function() { + var index = 0; + + $scope.termoReferencia.sancoes.forEach(function(sancao, key) { + if (sancao.$checked) { + index = key; + } + }); + + + $scope.termoReferencia.sancoes.splice(index, 1); + $scope.atualizarListaSizeSelectSancao(); + $scope.$modalConfirmInstance.dismiss('cancel'); + } + }); + } + }); + } else { + $scope.showAlert('warning', $translate.instant('MSG.SELECIONE_UM_ITEM_PARA_SER_REMOVIDO')); + } + }; + + $scope.removerDetalhamentoSolucao = function() { + $scope.termoReferenciaDetalhamentoSolucao = $scope.getDetalhamentoSolucaoChecked(); + + if ($scope.termoReferenciaDetalhamentoSolucao) { + $scope.$openModalConfirm({ + message: $translate.instant('MSG.CONFIRMA_EXCLUSAO'), + callback: function() { + var index = 0; + + $scope.termoReferencia.detalhamentosSolucoes.forEach(function(detalhamento, key) { + if (detalhamento.$checked) { + index = key; + } + }); + + $scope.termoReferencia.detalhamentosSolucoes.splice(index, 1); + $scope.atualizarListaSizeSelect(); + $scope.$modalConfirmInstance.dismiss('cancel'); + } + }); + } else { + $scope.showAlert('warning', $translate.instant('MSG.SELECIONE_UM_ITEM_PARA_SER_REMOVIDO')); + } + }; + + + + /*################################## + * # METODOS RELACIONADOS AO WIZARD # + * ##################################*/ + + function createTemplates(){ + $scope.templates = [{ name: 'termoReferenciaPg1.html', url: '/cit-contratos-web/html/termoReferencia/termoReferenciaPg1.html', show: true }, + { name: 'termoReferenciaPg2.html', url: '/cit-contratos-web/html/termoReferencia/termoReferenciaPg2.html', show: false}, + { name: 'termoReferenciaPg3.html', url: '/cit-contratos-web/html/termoReferencia/termoReferenciaPg3.html', show: false}, + { name: 'termoReferenciaPg4.html', url: '/cit-contratos-web/html/termoReferencia/termoReferenciaPg4.html', show: false}, + { name: 'termoReferenciaPg5.html', url: '/cit-contratos-web/html/termoReferencia/termoReferenciaPg5.html', show: false}, + { name: 'termoReferenciaPg6.html', url: '/cit-contratos-web/html/termoReferencia/termoReferenciaPg6.html', show: false}, + { name: 'termoReferenciaPg7.html', url: '/cit-contratos-web/html/termoReferencia/termoReferenciaPg7.html', show: false}]; + }; + + createTemplates(); + + $scope.step = 0; + + // Verifica se o passo e o primeiro passo do wizard + $scope.isFirstStep = function () { + return $scope.step === 0; + }; + + // Verifica é o ultimo passo do wizard + $scope.isLastStep = function () { + return $scope.step === ($scope.templates.length - 1); + }; + + // Verifica se o passo e o passo atual do wizard + $scope.isCurrentStep = function (step) { + return $scope.step === step; + }; + + // Recupera o label do botao de comando + $scope.getNextLabel = function () { + return ($scope.isLastStep()) ? $translate.instant("LABEL.SALVAR") : $translate.instant("LABEL.PROXIMO"); + }; + + // Utilizado pelo wizard para mudar para o passo desejado + $scope.setCurrentStep = function (step) { + + $scope.setLoadingGet(true); + + if (step <= ($scope.step - 1)) { + $scope.templates[$scope.step].show = false; + $scope.step = step; + $scope.templates[step].show = true; + } else { + if (!$scope.edit) { + $scope.permitidoAvancar = true; + } else { + permiteAvancoFluxo(); + } + + if ($scope.permitidoAvancar) { + $scope.templates[$scope.step].show = false; + $scope.step = step; + $scope.templates[step].show = true; + } + } + $scope.setLoading(false); + }; + + // Faz com o que o wizard retroceda um passo + $scope.handlePrevious = function () { + + $scope.setLoadingGet(true); + + $scope.templates[$scope.step].show = false; + $scope.step -= ($scope.isFirstStep()) ? 0 : 1; + $scope.templates[$scope.step].show = true; + + $scope.setLoading(false); + + }; + + // Faz com o que o wizard avance um passo + $scope.handleNext = function () { + + if ($scope.isLastStep()) { + $scope.saveOrUpdate(); + } else { + $scope.setLoadingGet(true); + + if (!$scope.edit) { + $scope.permitidoAvancar = true; + } else { + permiteAvancoFluxo(); + } + + if ($scope.permitidoAvancar) { + $scope.templates[$scope.step].show = false; + $scope.step += 1; + $scope.templates[$scope.step].show = true; + } + $scope.setLoading(false); + } + }; + + +// Controla se o usuario pode avancar o fluxo no wizard, validando os itens obrigatorios + function permiteAvancoFluxo() { + + $scope.permitidoAvancar = true; + + switch ($scope.step) { + case 0 : + //equipeContratacaoForm + if (isFormValid($scope.termoReferenciaForm.equipeContratacaoForm) && $scope.permitidoAvancar) { + $scope.termoReferenciaForm.equipeContratacaoForm.$submitted = true; + } + break; + case 1 : + //justificativaContratacaoForm + if (isFormValid($scope.termoReferenciaForm.justificativaContratacaoForm) && $scope.termoReferencia.detalhamentosSolucoes.length >= 1 && $scope.permitidoAvancar) { + $scope.termoReferenciaForm.justificativaContratacaoForm.$submitted = true; + } + break; + case 2 : + //especificacoesTecnicasForm + if (isFormValid($scope.termoReferenciaForm.especificacoesTecnicasForm) && $scope.permitidoAvancar) { + $scope.termoReferenciaForm.especificacoesTecnicasForm.$submitted = true; + } + break; + case 3 : + //modeloGestaoForm + if (isFormValid($scope.termoReferenciaForm.modeloGestaoForm) && $scope.permitidoAvancar) { + $scope.termoReferenciaForm.modeloGestaoForm.$submitted = true; + } + break; + case 4 : + //sancoesForm + if (($scope.termoReferencia.sancoes.length >= 1 || $scope.termoReferencia.penalidades.length >= 1) && $scope.permitidoAvancar) { + $scope.termoReferenciaForm.sancoesForm.$submitted = true; + } + break; + case 5 : + //criteriosSelecaoForm + if (isFormValid($scope.termoReferenciaForm.criteriosSelecaoForm) && $scope.permitidoAvancar) { + $scope.termoReferenciaForm.criteriosSelecaoForm.$submitted = true; + } + break; + case 6 : + //anexosObservacoesForm + $scope.termoReferenciaForm.anexosObservacoesForm.$submitted = true; + break; + } + + if (!$scope.permitidoAvancar && !$scope.stepValid) { + //Mensagem de erro de campos obrigatorios nao preenchidos + $scope.showAlert('error', $translate.instant('VALIDACAO.ALERTA_OBRIGATORIOS'), " ", false); + } + }; + + //Evita erros verificando se determinadas propriedades existem no form. + function isFormValid (form) { + $scope.stepValid = true; + if (form && form.$invalid) { + $scope.stepValid = false; + } + return $scope.stepValid; + }; + //Evita erros verificando se determinadas propriedades existem no form. + function isFormSubmited (form){ + var submitted = false; + if(form && form.$submitted){ + submitted = true; + } + return submitted; + } + + + $scope.getClassEdit = function (step){ + + switch (step) { + case 0 : + //equipeContratacaoForm + return {'active': $scope.isCurrentStep(step), + 'complete' : ($scope.step >= step && isFormValid($scope.termoReferenciaForm.equipeContratacaoForm)), + 'invalid' : (isFormSubmited($scope.termoReferenciaForm.equipeContratacaoForm)|| $scope.step > step) && (!isFormValid($scope.termoReferenciaForm.equipeContratacaoForm))}; + break; + case 1 : + //justificativaContratacaoForm + return {'active': $scope.isCurrentStep(step), + 'complete' : ($scope.step > step && isFormValid($scope.termoReferenciaForm.justificativaContratacaoForm) && $scope.termoReferencia.detalhamentosSolucoes.length >= 1 ), + 'invalid' : (isFormSubmited($scope.termoReferenciaForm.justificativaContratacaoForm) || $scope.step > step) && (!isFormValid($scope.termoReferenciaForm.justificativaContratacaoForm) || $scope.termoReferencia.detalhamentosSolucoes.length < 1)}; + break; + case 2 : + //especificacoesTecnicasForm + return {'active': $scope.isCurrentStep(step), + 'complete' : ($scope.step > step && isFormValid($scope.termoReferenciaForm.especificacoesTecnicasForm)), + 'invalid' : (isFormSubmited($scope.termoReferenciaForm.especificacoesTecnicasForm) || $scope.step > step) && !isFormValid($scope.termoReferenciaForm.especificacoesTecnicasForm)}; + break; + case 3 : + //modeloGestaoForm + return {'active': $scope.isCurrentStep(step), + 'complete' : ($scope.step > step || ($scope.step > step && isFormSubmited($scope.termoReferenciaForm.modeloGestaoForm)))}; + break; + case 4 : + //sancoesForm + return {'active': $scope.isCurrentStep(step), + 'complete' : ($scope.step > step && isFormValid($scope.termoReferenciaForm.sancoesForm) && ($scope.termoReferencia.sancoes.length >= 1 && $scope.termoReferencia.penalidades.length >= 1)), + 'invalid' : ($scope.step > step && ($scope.termoReferencia.sancoes.length < 1 || $scope.termoReferencia.penalidades.length < 1))}; + break; + case 5 : + //criteriosSelecaoForm + return {'active': $scope.isCurrentStep(step), + 'complete' : ($scope.step > step && isFormValid($scope.termoReferenciaForm.criteriosSelecaoForm)), + 'invalid' : ((isFormSubmited($scope.termoReferenciaForm.criteriosSelecaoForm) || $scope.step > step) && !isFormValid($scope.termoReferenciaForm.criteriosSelecaoForm))}; + break; + case 6 : + //anexosObservacoesForm + return {'active': $scope.isCurrentStep(step) || isFormSubmited($scope.termoReferenciaForm.anexosObservacoesForm), + 'complete' : ($scope.isCurrentStep(step) || ($scope.step > step && isFormSubmited($scope.termoReferenciaForm.anexosObservacoesForm)))}; + break; + }; + }; + + $scope.getClassList = function (){ + return {'active': false, 'complete' : true, 'invalid' : false}; + }; $scope.atualizarListaSizeSelect = function() { $timeout(function(){ diff --git a/cit-contratos-web/src/main/webapp/html/estudoTecnico/estudoTecnicoList.html b/cit-contratos-web/src/main/webapp/html/estudoTecnico/estudoTecnicoList.html index 518a05c..af8acd1 100644 --- a/cit-contratos-web/src/main/webapp/html/estudoTecnico/estudoTecnicoList.html +++ b/cit-contratos-web/src/main/webapp/html/estudoTecnico/estudoTecnicoList.html @@ -26,7 +26,11 @@ - + + + - + + +