Commit f43eda54e08325df1ee57aa81b6c15ef2a02cd9a
1 parent
0470d753b6
Exists in
master
Arreglo boton salir
Showing
1 changed file
with
2 additions
and
2 deletions
 
Show diff stats
src/js/controllerCisterna.js
| 1 | angular.module('focaAbmVehiculo') | 1 | angular.module('focaAbmVehiculo') | 
| 2 | .controller('focaAbmVehiculoCisternaController', [ | 2 | .controller('focaAbmVehiculoCisternaController', [ | 
| 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 
| 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout','$localStorage', '$filter', | 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout','$localStorage', '$filter', | 
| 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 
| 6 | focaModalService, focaBotoneraLateralService, $timeout, $localStorage, $filter) { | 6 | focaModalService, focaBotoneraLateralService, $timeout, $localStorage, $filter) { | 
| 7 | $scope.nuevo = ($routeParams.idx > -1) ? false : true; | 7 | $scope.nuevo = ($routeParams.idx > -1) ? false : true; | 
| 8 | $scope.editar = false; | 8 | $scope.editar = false; | 
| 9 | $scope.now = new Date(); | 9 | $scope.now = new Date(); | 
| 10 | $scope.cisterna = { | 10 | $scope.cisterna = { | 
| 11 | codigo: '', | 11 | codigo: '', | 
| 12 | capacidad: '', | 12 | capacidad: '', | 
| 13 | unidadMedida: {} | 13 | unidadMedida: {} | 
| 14 | }; | 14 | }; | 
| 15 | 15 | ||
| 16 | $scope.focused = $scope.nuevo ? 1 : 2; | 16 | $scope.focused = $scope.nuevo ? 1 : 2; | 
| 17 | $scope.next = function(key) { | 17 | $scope.next = function(key) { | 
| 18 | if (key === 13) $scope.focused++; | 18 | if (key === 13) $scope.focused++; | 
| 19 | }; | 19 | }; | 
| 20 | $scope.capacidadVechiulo = 0; | 20 | $scope.capacidadVechiulo = 0; | 
| 21 | $scope.transportista = ''; | 21 | $scope.transportista = ''; | 
| 22 | 22 | ||
| 23 | //SETEO BOTONERA LATERAL | 23 | //SETEO BOTONERA LATERAL | 
| 24 | $timeout(function() { | 24 | $timeout(function() { | 
| 25 | focaBotoneraLateralService.showSalir(false); | 25 | focaBotoneraLateralService.showSalir(false); | 
| 26 | focaBotoneraLateralService.showPausar(true); | 26 | focaBotoneraLateralService.showPausar(true); | 
| 27 | focaBotoneraLateralService.showCancelar(false); | 27 | focaBotoneraLateralService.showCancelar(false); | 
| 28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 
| 29 | focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); | 29 | focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); | 
| 30 | }); | 30 | }); | 
| 31 | 31 | ||
| 32 | if ($routeParams.idx !== -1) { | 32 | if ($routeParams.idx !== -1) { | 
| 33 | $scope.cisterna = [$routeParams.idx]; | 33 | $scope.cisterna = [$routeParams.idx]; | 
| 34 | focaAbmVehiculoService | 34 | focaAbmVehiculoService | 
| 35 | .getCisternas($routeParams.idVehiculo) | 35 | .getCisternas($routeParams.idVehiculo) | 
| 36 | .then(function(res) { | 36 | .then(function(res) { | 
| 37 | $scope.cisterna = res[$routeParams.idx]; | 37 | $scope.cisterna = res[$routeParams.idx]; | 
| 38 | }); | 38 | }); | 
| 39 | } | 39 | } | 
| 40 | 40 | ||
| 41 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 41 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 
| 42 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); | 42 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); | 
| 43 | $scope.transportista = res.data.transportista.COD; | 43 | $scope.transportista = res.data.transportista.COD; | 
| 44 | $scope.capacidadVechiulo = res.data.capacidad; | 44 | $scope.capacidadVechiulo = res.data.capacidad; | 
| 45 | $scope.$broadcast('addCabecera', { | 45 | $scope.$broadcast('addCabecera', { | 
| 46 | label: 'Transportista:', | 46 | label: 'Transportista:', | 
| 47 | valor: codigo + ' - ' + res.data.transportista.NOM | 47 | valor: codigo + ' - ' + res.data.transportista.NOM | 
| 48 | }); | 48 | }); | 
| 49 | $scope.$broadcast('addCabecera', { | 49 | $scope.$broadcast('addCabecera', { | 
| 50 | label: 'Unidad:', | 50 | label: 'Unidad:', | 
| 51 | valor: res.data.codigo | 51 | valor: res.data.codigo | 
| 52 | }); | 52 | }); | 
| 53 | $scope.$broadcast('addCabecera', { | 53 | $scope.$broadcast('addCabecera', { | 
| 54 | label: 'Capacidad total vehículo:', | 54 | label: 'Capacidad total vehículo:', | 
| 55 | valor: res.data.capacidad | 55 | valor: res.data.capacidad | 
| 56 | }); | 56 | }); | 
| 57 | }); | 57 | }); | 
| 58 | 58 | ||
| 59 | $scope.salir = function() { | 59 | $scope.salir = function() { | 
| 60 | 60 | ||
| 61 | if (!$scope.formCisterna.$pristine) { | 61 | if (!$scope.formCisterna.$pristine) { | 
| 62 | focaModalService.confirm( | 62 | focaModalService.confirm( | 
| 63 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 63 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 
| 64 | ).then(function(data) { | 64 | ).then(function(data) { | 
| 65 | if (data) { | 65 | if (data) { | 
| 66 | $location.path('/vehiculo/'); | 66 | $location.path('/vehiculo'); | 
| 67 | } | 67 | } | 
| 68 | }); | 68 | }); | 
| 69 | } else { | 69 | } else { | 
| 70 | $location.path('/vehiculo/'); | 70 | $location.path('/vehiculo'); | 
| 71 | } | 71 | } | 
| 72 | }; | 72 | }; | 
| 73 | 73 | ||
| 74 | $scope.guardar = function() { | 74 | $scope.guardar = function() { | 
| 75 | 75 | ||
| 76 | if ($scope.formCisterna.$pristine) { | 76 | if ($scope.formCisterna.$pristine) { | 
| 77 | $scope.cancelar(); | 77 | $scope.cancelar(); | 
| 78 | return; | 78 | return; | 
| 79 | } | 79 | } | 
| 80 | 80 | ||
| 81 | if (!$scope.cisterna.codigo) { | 81 | if (!$scope.cisterna.codigo) { | 
| 82 | focaModalService.alert('Ingrese codigo de cisterna'); | 82 | focaModalService.alert('Ingrese codigo de cisterna'); | 
| 83 | return; | 83 | return; | 
| 84 | } else if (!$scope.cisterna.capacidad) { | 84 | } else if (!$scope.cisterna.capacidad) { | 
| 85 | focaModalService.alert('Ingrese capacidad'); | 85 | focaModalService.alert('Ingrese capacidad'); | 
| 86 | return; | 86 | return; | 
| 87 | } else if (!$scope.cisterna.idUnidadMedida) { | 87 | } else if (!$scope.cisterna.idUnidadMedida) { | 
| 88 | focaModalService.alert('Ingrese unidad de medida'); | 88 | focaModalService.alert('Ingrese unidad de medida'); | 
| 89 | return; | 89 | return; | 
| 90 | } | 90 | } | 
| 91 | 91 | ||
| 92 | validaCodigo() | 92 | validaCodigo() | 
| 93 | .then(function() { | 93 | .then(function() { | 
| 94 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | 94 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | 
| 95 | delete $scope.cisterna.vehiculo; | 95 | delete $scope.cisterna.vehiculo; | 
| 96 | 96 | ||
| 97 | focaAbmVehiculoService | 97 | focaAbmVehiculoService | 
| 98 | .guardarCisterna($scope.cisterna, $routeParams.idx); | 98 | .guardarCisterna($scope.cisterna, $routeParams.idx); | 
| 99 | 99 | ||
| 100 | $timeout(function() { | 100 | $timeout(function() { | 
| 101 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 101 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 
| 102 | '/' + $scope.transportista); | 102 | '/' + $scope.transportista); | 
| 103 | }, 0); | 103 | }, 0); | 
| 104 | }, function(err) { | 104 | }, function(err) { | 
| 105 | focaModalService.alert(err); | 105 | focaModalService.alert(err); | 
| 106 | }); | 106 | }); | 
| 107 | 107 | ||
| 108 | }; | 108 | }; | 
| 109 | 109 | ||
| 110 | $scope.seleccionarUnidadMedida = function() { | 110 | $scope.seleccionarUnidadMedida = function() { | 
| 111 | var modalInstance = $uibModal.open( | 111 | var modalInstance = $uibModal.open( | 
| 112 | { | 112 | { | 
| 113 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 113 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 
| 114 | templateUrl: 'modal-unidad-medida.html', | 114 | templateUrl: 'modal-unidad-medida.html', | 
| 115 | controller: 'focaModalUnidadMedidaCtrl', | 115 | controller: 'focaModalUnidadMedidaCtrl', | 
| 116 | size: 'lg' | 116 | size: 'lg' | 
| 117 | } | 117 | } | 
| 118 | ); | 118 | ); | 
| 119 | modalInstance.result.then(function(unidaMedida) { | 119 | modalInstance.result.then(function(unidaMedida) { | 
| 120 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 120 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 
| 121 | $scope.cisterna.unidadMedida = unidaMedida; | 121 | $scope.cisterna.unidadMedida = unidaMedida; | 
| 122 | }); | 122 | }); | 
| 123 | }; | 123 | }; | 
| 124 | 124 | ||
| 125 | function validaCodigo() { | 125 | function validaCodigo() { | 
| 126 | return new Promise(function(resolve, reject) { | 126 | return new Promise(function(resolve, reject) { | 
| 127 | focaAbmVehiculoService | 127 | focaAbmVehiculoService | 
| 128 | .getCisternas($routeParams.idVehiculo) | 128 | .getCisternas($routeParams.idVehiculo) | 
| 129 | .then(function(res) { | 129 | .then(function(res) { | 
| 130 | var cisternas = res; | 130 | var cisternas = res; | 
| 131 | var totalCargado = 0; | 131 | var totalCargado = 0; | 
| 132 | cisternas.forEach(function(cisterna, idx) { | 132 | cisternas.forEach(function(cisterna, idx) { | 
| 133 | //SI EL CODIGO YA EXISTE | 133 | //SI EL CODIGO YA EXISTE | 
| 134 | if (cisterna.codigo === $scope.cisterna.codigo && | 134 | if (cisterna.codigo === $scope.cisterna.codigo && | 
| 135 | idx !== $routeParams.idx && | 135 | idx !== $routeParams.idx && | 
| 136 | !cisterna.desactivado) { | 136 | !cisterna.desactivado) { | 
| 137 | reject('Código de cisterna existente'); | 137 | reject('Código de cisterna existente'); | 
| 138 | } | 138 | } | 
| 139 | if (idx !== $routeParams.idx && | 139 | if (idx !== $routeParams.idx && | 
| 140 | !cisterna.desactivado) { | 140 | !cisterna.desactivado) { | 
| 141 | totalCargado += cisterna.capacidad; | 141 | totalCargado += cisterna.capacidad; | 
| 142 | } | 142 | } | 
| 143 | }); | 143 | }); | 
| 144 | resolve(); | 144 | resolve(); | 
| 145 | }); | 145 | }); | 
| 146 | }); | 146 | }); | 
| 147 | } | 147 | } | 
| 148 | } | 148 | } | 
| 149 | ]); | 149 | ]); | 
| 150 | 150 |