Commit c4a826fa483731c7688a940dc1f8301fa4f42168
1 parent
299f288f1d
Exists in
master
and in
2 other branches
Modal Cancelar
Showing
1 changed file
with
31 additions
and
19 deletions
Show diff stats
src/js/controller.js
| ... | ... | @@ -120,19 +120,21 @@ angular.module('focaAbmChofer') |
| 120 | 120 | $timeout(function() { |
| 121 | 121 | focaBotoneraLateralService.showSalir(false); |
| 122 | 122 | focaBotoneraLateralService.showPausar(true); |
| 123 | - focaBotoneraLateralService.showCancelar(true); | |
| 123 | + focaBotoneraLateralService.showCancelar(false); | |
| 124 | 124 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 125 | + focaBotoneraLateralService.addCustomButton('Cancelar', cancelar); | |
| 126 | + | |
| 125 | 127 | }); |
| 126 | 128 | |
| 127 | 129 | $timeout(function() {getLSChofer();}); |
| 128 | - | |
| 130 | + | |
| 129 | 131 | if ($scope.nuevo) { |
| 130 | 132 | focaAbmChoferService |
| 131 | 133 | .getTransportistaPorId($routeParams.idTransportista) |
| 132 | - .then(function(res) { | |
| 133 | - var codigo = ('00000' + res.data.COD).slice(-5); | |
| 134 | - $scope.chofer.idTransportista = res.data.COD; | |
| 135 | - $scope.chofer.transportista = res.data; | |
| 134 | + .then(function(res) { | |
| 135 | + var codigo = ('00000' + res.data.COD).slice(-5); | |
| 136 | + $scope.chofer.idTransportista = res.data.COD; | |
| 137 | + $scope.chofer.transportista = res.data; | |
| 136 | 138 | $scope.$broadcast('addCabecera', { |
| 137 | 139 | label: 'Transportista:', |
| 138 | 140 | valor: codigo + ' - ' + res.data.NOM |
| ... | ... | @@ -147,7 +149,7 @@ angular.module('focaAbmChofer') |
| 147 | 149 | $scope.$broadcast('addCabecera', { |
| 148 | 150 | label: 'Transportista:', |
| 149 | 151 | valor: codigo + ' - ' + res.data.transportista.NOM |
| 150 | - }); | |
| 152 | + }); | |
| 151 | 153 | } |
| 152 | 154 | }); |
| 153 | 155 | |
| ... | ... | @@ -163,7 +165,7 @@ angular.module('focaAbmChofer') |
| 163 | 165 | }); |
| 164 | 166 | } |
| 165 | 167 | function getLSChofer() { |
| 166 | - var chofer = JSON.parse($localStorage.chofer || null); | |
| 168 | + var chofer = JSON.parse($localStorage.chofer || null); | |
| 167 | 169 | |
| 168 | 170 | if (chofer) { |
| 169 | 171 | setearChofer(chofer); |
| ... | ... | @@ -171,15 +173,11 @@ angular.module('focaAbmChofer') |
| 171 | 173 | } |
| 172 | 174 | } |
| 173 | 175 | |
| 174 | - $scope.cancelar = function() { | |
| 175 | - $location.path('/chofer'); | |
| 176 | - }; | |
| 177 | - | |
| 178 | - $scope.pausar = function() { | |
| 179 | - focaBotoneraLateralService.pausar(); | |
| 176 | + $scope.cancelar = function() { | |
| 177 | + $location.path('/chofer'); | |
| 180 | 178 | }; |
| 181 | 179 | |
| 182 | - $scope.guardar = function(key) { | |
| 180 | + $scope.guardar = function(key) { | |
| 183 | 181 | |
| 184 | 182 | if (!$scope.chofer.nombre) { |
| 185 | 183 | focaModalService.alert('Ingrese nombre'); |
| ... | ... | @@ -206,7 +204,7 @@ angular.module('focaAbmChofer') |
| 206 | 204 | } |
| 207 | 205 | }; |
| 208 | 206 | |
| 209 | - $scope.$watch('chofer', function(newValue) { | |
| 207 | + $scope.$watch('chofer', function(newValue) { | |
| 210 | 208 | focaBotoneraLateralService.setPausarData({ |
| 211 | 209 | label: 'chofer', |
| 212 | 210 | val: { |
| ... | ... | @@ -217,18 +215,32 @@ angular.module('focaAbmChofer') |
| 217 | 215 | idTipoDocumento: newValue.idTipoDocumento, |
| 218 | 216 | id: newValue.id |
| 219 | 217 | } |
| 220 | - }); | |
| 218 | + }); | |
| 221 | 219 | }, true); |
| 222 | 220 | |
| 221 | + function cancelar() { | |
| 222 | + if ($scope.formChofer.$pristine == false) { | |
| 223 | + focaModalService.confirm( | |
| 224 | + '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | |
| 225 | + ).then(function(data) { | |
| 226 | + if (data) { | |
| 227 | + $location.path('/chofer'); | |
| 228 | + } | |
| 229 | + }); | |
| 230 | + } else { | |
| 231 | + $location.path('/chofer'); | |
| 232 | + } | |
| 233 | + } | |
| 234 | + | |
| 223 | 235 | function validaDni() { |
| 224 | 236 | return new Promise(function(resolve, reject) { |
| 225 | 237 | focaAbmChoferService |
| 226 | 238 | .getChoferPorDni($scope.chofer.dni) |
| 227 | 239 | .then(function(res) { |
| 228 | - if(res.data.id && | |
| 240 | + if (res.data.id && | |
| 229 | 241 | $scope.chofer.id !== res.data.id) { |
| 230 | 242 | reject(res.data); |
| 231 | - }else { | |
| 243 | + } else { | |
| 232 | 244 | resolve(); |
| 233 | 245 | } |
| 234 | 246 | }); |