evoapp.controller('SearchController', function($rootScope, $scope, $timeout, $compile, $injector, $filter, globals) { $scope.globals = globals; $scope.searching = {Name: ''};//new globals.dataService.record('Discipline'); //TODO: this one might have a different name!!! $scope.storeResumoTrabalhador = new globals.dataService.store({ model: null, actions: { get: 'getResumoTrabalhador' } }); $scope.storeFichasTrabalhador = new globals.dataService.store(); $scope.dadosTrabalhador = null; $scope.list = function(){ //$scope.storeFichasTrabalhador.items = []; //$scope.storeFichasTrabalhador.loadData($scope.testArray); //$scope.storeFichasTrabalhador.loadData([{data: '12-12-2012', responsavel: 'responsavel 1'}]); }; $scope.edit = function(selected){ //TODO: this is temporary!!! var module = _.where($rootScope.UserSession.tiposFichas, {id: selected.tipo_id}); if(module.length > 0) { var controller = module[0]; $scope.$parent.loadModule({Controller: controller.Controller}, function(className, scope, isNewModule){ scope.descricao = controller.descricao; scope.edit(selected); }); } }; $scope.add = function(selected){ $scope.$parent.loadModule({Controller: selected.Controller}, function(className, scope, isNewModule){ scope.descricao = selected.descricao; //NOTICE: vais receber estrutura com array de fichas + ficha pré-preenchida... var newRecord = { ficha: $scope.dadosTrabalhador }; newRecord.ficha.tipo_ficha_id = selected.id; newRecord.ficha.data_conclusao = null; scope.add(newRecord); }); }; $scope.clear = function(){ $scope.dadosTrabalhador = null; $scope.storeFichasTrabalhador.items = []; $scope.comboEmpresas.setValue(null); $scope.comboEstabelecimentos.clear(); $scope.comboTrabalhadores.clear(); }; $scope.onEmpresaChange = function(selectedValue, selectedRecord){ $scope.comboEstabelecimentos.clear(); $scope.comboTrabalhadores.clear(); $scope.storeFichasTrabalhador.items = []; $scope.dadosTrabalhador = null; if(selectedRecord) { $scope.comboEstabelecimentos.store.extraParams = { empresaID: selectedRecord.id }; $scope.comboEstabelecimentos.loadStore(function(response, status, headers, config, items){ }); } }; $scope.onEstabelecimentoChange = function(selectedValue, selectedRecord){ $scope.comboTrabalhadores.setValue(null); $scope.comboTrabalhadores.clear(); $scope.storeFichasTrabalhador.items = []; $scope.dadosTrabalhador = null; if(selectedRecord) { $scope.comboTrabalhadores.store.extraParams = { estabelecimentoID: selectedRecord.id }; $scope.comboTrabalhadores.loadStore(function(response, status, headers, config, items){ }); } }; $scope.onTrabalhadorChange = function(selectedValue, selectedRecord){ $scope.storeFichasTrabalhador.items = []; $scope.dadosTrabalhador = null; if(selectedRecord) { $scope.storeResumoTrabalhador.extraParams = { trabalhadorID: selectedRecord.id }; $scope.storeResumoTrabalhador.get(function(response, status, headers, config, items){ if(response.data != null) { if(response.data.dadosTrabalhador) { $scope.dadosTrabalhador = response.data.dadosTrabalhador; } var fichas = response.data.fichas; $scope.storeFichasTrabalhador.loadData(fichas); } }); } }; //TODO: this is temporary. This list must come from database. $scope.filterFichasClinicas = function(ficha) { return ficha.id < 200; }; //TODO: this is temporary. This list must come from database. $scope.filterFichasAptidao = function(ficha) { return ficha.id >= 200; }; $scope.openModalDocumentos = function(){ $scope.modalDocumentos.show({ }); $scope.modalDocumentos.viewController.list(); $scope.modalDocumentos.viewController.$on('onAfterEdit', function(event, args) { //$scope.modalDocumentos.hide(); }); }; $scope.openModalAcidentesTrabalho = function(){ $scope.modalAcidentesTrabalho.show({ }); $scope.modalAcidentesTrabalho.viewController.list(); $scope.modalAcidentesTrabalho.viewController.$on('onAfterEdit', function(event, args) { //$scope.modalAcidentesTrabalho.hide(); }); }; //Indica se o tipo de ficha pode emitir Ficha de Aptidão $scope.emiteFichaAptidao = function(ficha){ var emite = false; if(ficha){ var tipo_id = ficha.tipo_id; emite = ( tipo_id != 8 && //Enfermagem tipo_id != 9 //Medicina Curativa ); } return emite; }; $scope.emitirFichaAptidao = function(ficha){ var fichaAdmissao = _.where($scope.UserSession.tiposFichas, {id: ficha.tipo_id}); if(fichaAdmissao.length == 1) { var tipoFicha = fichaAdmissao[0]; $scope.$parent.loadModule({Controller: 'Form5'}, function(className, scope, isNewModule){ scope.descricao = tipoFicha.descricao; var newRecord = { ficha: $scope.dadosTrabalhador }; newRecord.ficha.aptidao = { id: ficha.id }; newRecord.ficha.tipo_ficha_id = tipoFicha.id; newRecord.ficha.data_conclusao = null; scope.add(newRecord); }); } }; $scope.$on('afterrender', function(event, args){ $scope.comboEmpresas.loadStore(function(response, status, headers, config, items){ }); }); });