Commit 627479f5e2bf5f7af34a4867ae0706d7257ae411
1 parent
8cb24dc5b7
Exists in
master
and in
1 other branch
Boton Cancelar Vehiculo - Cisterna
Showing
2 changed files
with
130 additions
and
34 deletions
Show diff stats
src/js/controller.js
| 1 | 1 | angular.module('focaAbmVehiculo') |
| 2 | 2 | .controller('focaAbmVehiculosController', [ |
| 3 | 3 | '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', |
| 4 | - '$uibModal', 'focaBotoneraLateralService', '$timeout', | |
| 4 | + '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', | |
| 5 | 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, |
| 6 | - $uibModal, focaBotoneraLateralService, $timeout) { | |
| 6 | + $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { | |
| 7 | 7 | |
| 8 | 8 | $scope.now = new Date(); |
| 9 | 9 | $scope.botonera = [{ |
| ... | ... | @@ -20,7 +20,13 @@ angular.module('focaAbmVehiculo') |
| 20 | 20 | focaBotoneraLateralService.showGuardar(false); |
| 21 | 21 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 22 | 22 | |
| 23 | - if(focaAbmVehiculoService.transportistaSeleccionado.COD) { | |
| 23 | + if ($localStorage.vehiculo) { | |
| 24 | + var vehiculo = JSON.parse($localStorage.vehiculo); | |
| 25 | + if (!vehiculo.idVehiculo) { vehiculo.idVehiculo = 0; } | |
| 26 | + $location.path('/vehiculo/' + vehiculo.idVehiculo + '/' + vehiculo.idTransportista); | |
| 27 | + } | |
| 28 | + | |
| 29 | + if (focaAbmVehiculoService.transportistaSeleccionado.COD) { | |
| 24 | 30 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); |
| 25 | 31 | } |
| 26 | 32 | $scope.editar = function(id) { |
| ... | ... | @@ -93,9 +99,9 @@ angular.module('focaAbmVehiculo') |
| 93 | 99 | ]) |
| 94 | 100 | .controller('focaAbmVehiculoController', [ |
| 95 | 101 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
| 96 | - 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', | |
| 102 | + 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', '$localStorage', '$filter', | |
| 97 | 103 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
| 98 | - focaModalService, $timeout, focaBotoneraLateralService, $window) { | |
| 104 | + focaModalService, $timeout, focaBotoneraLateralService, $window, $localStorage, $filter) { | |
| 99 | 105 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; |
| 100 | 106 | $scope.now = new Date(); |
| 101 | 107 | $scope.focused = 1; |
| ... | ... | @@ -104,13 +110,15 @@ angular.module('focaAbmVehiculo') |
| 104 | 110 | |
| 105 | 111 | $timeout(function() { |
| 106 | 112 | focaBotoneraLateralService.showSalir(false); |
| 107 | - focaBotoneraLateralService.showPausar(false); | |
| 113 | + focaBotoneraLateralService.showPausar(true); | |
| 108 | 114 | focaBotoneraLateralService.showCancelar(false); |
| 109 | 115 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 110 | - focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar); | |
| 116 | + focaBotoneraLateralService.addCustomButton('Cancelar', cancelar); | |
| 111 | 117 | }); |
| 118 | + | |
| 119 | + $timeout(function() {getLSVehiculo();}); | |
| 112 | 120 | |
| 113 | - if($scope.nuevo) { | |
| 121 | + if ($scope.nuevo) { | |
| 114 | 122 | focaAbmVehiculoService |
| 115 | 123 | .getTransportistaPorId($routeParams.idTransportista) |
| 116 | 124 | .then(function(res) { |
| ... | ... | @@ -125,7 +133,7 @@ angular.module('focaAbmVehiculo') |
| 125 | 133 | } |
| 126 | 134 | $scope.vehiculo = {}; |
| 127 | 135 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
| 128 | - if(res.data) { | |
| 136 | + if (res.data) { | |
| 129 | 137 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); |
| 130 | 138 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; |
| 131 | 139 | |
| ... | ... | @@ -150,9 +158,21 @@ angular.module('focaAbmVehiculo') |
| 150 | 158 | $scope.next = function(key) { |
| 151 | 159 | if (key === 13) $scope.focused++; |
| 152 | 160 | }; |
| 153 | - $scope.cancelar = function() { | |
| 154 | - $location.path('/vehiculo'); | |
| 155 | - }; | |
| 161 | + | |
| 162 | + function cancelar() { | |
| 163 | + if ($scope.formVehiculo.$pristine == false) { | |
| 164 | + focaModalService.confirm( | |
| 165 | + '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | |
| 166 | + ).then(function(data) { | |
| 167 | + if (data) { | |
| 168 | + $location.path('/vehiculo'); | |
| 169 | + } | |
| 170 | + }); | |
| 171 | + } else { | |
| 172 | + $location.path('/vehiculo'); | |
| 173 | + } | |
| 174 | + } | |
| 175 | + | |
| 156 | 176 | $scope.editar = function(key) { |
| 157 | 177 | if (key) { |
| 158 | 178 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
| ... | ... | @@ -163,25 +183,24 @@ angular.module('focaAbmVehiculo') |
| 163 | 183 | }; |
| 164 | 184 | $scope.guardar = function(key) { |
| 165 | 185 | |
| 166 | - if (!$scope.vehiculo.codigo) { | |
| 167 | - focaModalService.alert('Ingrese unidad'); | |
| 168 | - return; | |
| 169 | - } else if (!$scope.vehiculo.tractor) { | |
| 170 | - focaModalService.alert('Ingrese dominio tractor'); | |
| 171 | - return; | |
| 172 | - } else if (!$scope.vehiculo.semi) { | |
| 173 | - focaModalService.alert('Ingrese dominio semi'); | |
| 174 | - return; | |
| 175 | - } else if (!$scope.vehiculo.capacidad) { | |
| 176 | - focaModalService.alert('Ingrse capacidad total'); | |
| 177 | - return; | |
| 178 | - } | |
| 179 | - | |
| 180 | - | |
| 181 | 186 | key = (typeof key === 'undefined') ? 13 : key; |
| 187 | + | |
| 182 | 188 | if (key === 13) { |
| 189 | + if (!$scope.vehiculo.codigo) { | |
| 190 | + focaModalService.alert('Ingrese unidad'); | |
| 191 | + return; | |
| 192 | + } else if (!$scope.vehiculo.tractor) { | |
| 193 | + focaModalService.alert('Ingrese dominio tractor'); | |
| 194 | + return; | |
| 195 | + } else if (!$scope.vehiculo.semi) { | |
| 196 | + focaModalService.alert('Ingrese dominio semi'); | |
| 197 | + return; | |
| 198 | + } else if (!$scope.vehiculo.capacidad) { | |
| 199 | + focaModalService.alert('Ingrese capacidad total'); | |
| 200 | + return; | |
| 201 | + } | |
| 183 | 202 | //Valida si existe numero de unidad |
| 184 | - if(!validaTotalCargas() && !$scope.nuevo) { | |
| 203 | + if (!validaTotalCargas() && !$scope.nuevo) { | |
| 185 | 204 | focaModalService.alert('La suma de las capacidades de las cisternas' + |
| 186 | 205 | ' debe ser igual a la capacidad total del vehículo'); |
| 187 | 206 | return; |
| ... | ... | @@ -206,11 +225,42 @@ angular.module('focaAbmVehiculo') |
| 206 | 225 | } |
| 207 | 226 | |
| 208 | 227 | }; |
| 228 | + | |
| 229 | + $scope.$watch('vehiculo', function(newValue) { | |
| 230 | + focaBotoneraLateralService.setPausarData({ | |
| 231 | + label:'vehiculo', | |
| 232 | + val: { | |
| 233 | + codigo: newValue.codigo, | |
| 234 | + tractor: newValue.tractor, | |
| 235 | + semi: newValue.semi, | |
| 236 | + capacidad: newValue.capacidad, | |
| 237 | + idVehiculo: newValue.idVehiculo, | |
| 238 | + idTransportista: newValue.idTransportista | |
| 239 | + } | |
| 240 | + }); | |
| 241 | + }, true); | |
| 242 | + | |
| 243 | + function getLSVehiculo() { | |
| 244 | + var vehiculo = JSON.parse($localStorage.vehiculo|| null); | |
| 245 | + if (vehiculo) { | |
| 246 | + setearVehiculo(vehiculo); | |
| 247 | + delete $localStorage.vehiculo; | |
| 248 | + } | |
| 249 | + } | |
| 250 | + | |
| 251 | + function setearVehiculo(vehiculo) { | |
| 252 | + $scope.vehiculo = vehiculo; | |
| 253 | + $scope.$broadcast('addCabecera', { | |
| 254 | + label: 'Vehiculo:', | |
| 255 | + valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' | |
| 256 | + }); | |
| 257 | + } | |
| 258 | + | |
| 209 | 259 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { |
| 210 | 260 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + |
| 211 | 261 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( |
| 212 | 262 | function(data) { |
| 213 | - if(data) { | |
| 263 | + if (data) { | |
| 214 | 264 | focaAbmVehiculoService.deleteCisterna(idx); |
| 215 | 265 | focaAbmVehiculoService |
| 216 | 266 | .getCisternas($routeParams.idVehiculo) |
src/js/controllerCisterna.js
| 1 | 1 | angular.module('focaAbmVehiculo') |
| 2 | 2 | .controller('focaAbmVehiculoCisternaController', [ |
| 3 | 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
| 4 | - 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window', | |
| 4 | + 'focaModalService', 'focaBotoneraLateralService', '$timeout','$localStorage', '$filter', | |
| 5 | 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
| 6 | - focaModalService, focaBotoneraLateralService, $timeout, $window) { | |
| 6 | + focaModalService, focaBotoneraLateralService, $timeout, $localStorage, $filter) { | |
| 7 | 7 | $scope.nuevo = ($routeParams.idx > -1) ? false : true; |
| 8 | 8 | $scope.editar = false; |
| 9 | 9 | $scope.now = new Date(); |
| ... | ... | @@ -23,11 +23,21 @@ angular.module('focaAbmVehiculo') |
| 23 | 23 | //SETEO BOTONERA LATERAL |
| 24 | 24 | $timeout(function() { |
| 25 | 25 | focaBotoneraLateralService.showSalir(false); |
| 26 | - focaBotoneraLateralService.showPausar(false); | |
| 27 | - focaBotoneraLateralService.showCancelar(true); | |
| 26 | + focaBotoneraLateralService.showPausar(true); | |
| 27 | + focaBotoneraLateralService.showCancelar(false); | |
| 28 | 28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 29 | + focaBotoneraLateralService.addCustomButton('Cancelar', $scope.cancelar); | |
| 29 | 30 | }); |
| 30 | 31 | |
| 32 | + // $timeout(function() {getLSCisterna();}); | |
| 33 | + | |
| 34 | + // if ($localStorage.cisterna) { | |
| 35 | + // var cisterna = JSON.parse($localStorage.cisterna); | |
| 36 | + // console.log('Cisterna datos: ' ,cisterna); | |
| 37 | + // if (!cisterna.codigo) { cisterna.idcisterna = 0; } | |
| 38 | + // $location.path('/vehiculo/' + vehiculo.idVehiculo + '/cisterna/'); | |
| 39 | + // } | |
| 40 | + | |
| 31 | 41 | if ($routeParams.idx != -1) { |
| 32 | 42 | |
| 33 | 43 | $scope.cisterna = [$routeParams.idx]; |
| ... | ... | @@ -56,7 +66,16 @@ angular.module('focaAbmVehiculo') |
| 56 | 66 | }); |
| 57 | 67 | }); |
| 58 | 68 | $scope.cancelar = function() { |
| 59 | - $location.path('/vehiculo/' + $routeParams.idVehiculo); | |
| 69 | + | |
| 70 | + if ($scope.formCisterna.$pristine == false) { | |
| 71 | + focaModalService.confirm( | |
| 72 | + '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | |
| 73 | + ).then(function(data) { | |
| 74 | + if (data) { | |
| 75 | + $location.path('/vehiculo'); | |
| 76 | + } | |
| 77 | + }); | |
| 78 | + } | |
| 60 | 79 | }; |
| 61 | 80 | $scope.guardar = function() { |
| 62 | 81 | |
| ... | ... | @@ -104,6 +123,33 @@ angular.module('focaAbmVehiculo') |
| 104 | 123 | }); |
| 105 | 124 | }; |
| 106 | 125 | |
| 126 | + /*$scope.$watch('cisterna', function(newValue) { | |
| 127 | + focaBotoneraLateralService.setPausarData({ | |
| 128 | + label:'cisterna', | |
| 129 | + val: { | |
| 130 | + codigo: newValue.codigo, | |
| 131 | + capacidad: newValue.capacidad, | |
| 132 | + unidadMedida: newValue.NOM | |
| 133 | + } | |
| 134 | + }); | |
| 135 | + }, true);*/ | |
| 136 | + | |
| 137 | + /*function getLSCisterna() { | |
| 138 | + var cisterna = JSON.parse($localStorage.cisterna|| null); | |
| 139 | + if (cisterna) { | |
| 140 | + setearcisterna(cisterna); | |
| 141 | + delete $localStorage.cisterna; | |
| 142 | + } | |
| 143 | + } | |
| 144 | + | |
| 145 | + function setearcisterna(cisterna) { | |
| 146 | + $scope.cisterna = cisterna; | |
| 147 | + $scope.$broadcast('addCabecera', { | |
| 148 | + label: 'cisterna:', | |
| 149 | + valor: $filter('rellenarDigitos')(cisterna.codigo) + ' - ' | |
| 150 | + }); | |
| 151 | + }*/ | |
| 152 | + | |
| 107 | 153 | function validaCodigo() { |
| 108 | 154 | return new Promise(function(resolve, reject) { |
| 109 | 155 | focaAbmVehiculoService |