Commit 0470d753b690bafe03523408b9edff28a91125fa
1 parent
2711adb43a
Exists in
master
and in
1 other branch
Cambio en el boton " Salir "
Showing
1 changed file
with
5 additions
and
3 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('Cancelar', $scope.cancelar); | 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.cancelar = 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 { | ||
70 | $location.path('/vehiculo/'); | ||
69 | } | 71 | } |
70 | }; | 72 | }; |
71 | 73 | ||
72 | $scope.guardar = function() { | 74 | $scope.guardar = function() { |
73 | 75 | ||
74 | if ($scope.formCisterna.$pristine) { | 76 | if ($scope.formCisterna.$pristine) { |
75 | $scope.cancelar(); | 77 | $scope.cancelar(); |
76 | return; | 78 | return; |
77 | } | 79 | } |
78 | 80 | ||
79 | if (!$scope.cisterna.codigo) { | 81 | if (!$scope.cisterna.codigo) { |
80 | focaModalService.alert('Ingrese codigo de cisterna'); | 82 | focaModalService.alert('Ingrese codigo de cisterna'); |
81 | return; | 83 | return; |
82 | } else if (!$scope.cisterna.capacidad) { | 84 | } else if (!$scope.cisterna.capacidad) { |
83 | focaModalService.alert('Ingrese capacidad'); | 85 | focaModalService.alert('Ingrese capacidad'); |
84 | return; | 86 | return; |
85 | } else if (!$scope.cisterna.idUnidadMedida) { | 87 | } else if (!$scope.cisterna.idUnidadMedida) { |
86 | focaModalService.alert('Ingrese unidad de medida'); | 88 | focaModalService.alert('Ingrese unidad de medida'); |
87 | return; | 89 | return; |
88 | } | 90 | } |
89 | 91 | ||
90 | validaCodigo() | 92 | validaCodigo() |
91 | .then(function() { | 93 | .then(function() { |
92 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | 94 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); |
93 | delete $scope.cisterna.vehiculo; | 95 | delete $scope.cisterna.vehiculo; |
94 | 96 | ||
95 | focaAbmVehiculoService | 97 | focaAbmVehiculoService |
96 | .guardarCisterna($scope.cisterna, $routeParams.idx); | 98 | .guardarCisterna($scope.cisterna, $routeParams.idx); |
97 | 99 | ||
98 | $timeout(function() { | 100 | $timeout(function() { |
99 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 101 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
100 | '/' + $scope.transportista); | 102 | '/' + $scope.transportista); |
101 | }, 0); | 103 | }, 0); |
102 | }, function(err) { | 104 | }, function(err) { |
103 | focaModalService.alert(err); | 105 | focaModalService.alert(err); |
104 | }); | 106 | }); |
105 | 107 | ||
106 | }; | 108 | }; |
107 | 109 | ||
108 | $scope.seleccionarUnidadMedida = function() { | 110 | $scope.seleccionarUnidadMedida = function() { |
109 | var modalInstance = $uibModal.open( | 111 | var modalInstance = $uibModal.open( |
110 | { | 112 | { |
111 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 113 | ariaLabelledBy: 'Busqueda de Unidades de medida', |
112 | templateUrl: 'modal-unidad-medida.html', | 114 | templateUrl: 'modal-unidad-medida.html', |
113 | controller: 'focaModalUnidadMedidaCtrl', | 115 | controller: 'focaModalUnidadMedidaCtrl', |
114 | size: 'lg' | 116 | size: 'lg' |
115 | } | 117 | } |
116 | ); | 118 | ); |
117 | modalInstance.result.then(function(unidaMedida) { | 119 | modalInstance.result.then(function(unidaMedida) { |
118 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 120 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; |
119 | $scope.cisterna.unidadMedida = unidaMedida; | 121 | $scope.cisterna.unidadMedida = unidaMedida; |
120 | }); | 122 | }); |
121 | }; | 123 | }; |
122 | 124 | ||
123 | function validaCodigo() { | 125 | function validaCodigo() { |
124 | return new Promise(function(resolve, reject) { | 126 | return new Promise(function(resolve, reject) { |
125 | focaAbmVehiculoService | 127 | focaAbmVehiculoService |
126 | .getCisternas($routeParams.idVehiculo) | 128 | .getCisternas($routeParams.idVehiculo) |
127 | .then(function(res) { | 129 | .then(function(res) { |
128 | var cisternas = res; | 130 | var cisternas = res; |
129 | var totalCargado = 0; | 131 | var totalCargado = 0; |
130 | cisternas.forEach(function(cisterna, idx) { | 132 | cisternas.forEach(function(cisterna, idx) { |
131 | //SI EL CODIGO YA EXISTE | 133 | //SI EL CODIGO YA EXISTE |
132 | if (cisterna.codigo === $scope.cisterna.codigo && | 134 | if (cisterna.codigo === $scope.cisterna.codigo && |
133 | idx !== $routeParams.idx && | 135 | idx !== $routeParams.idx && |
134 | !cisterna.desactivado) { | 136 | !cisterna.desactivado) { |
135 | reject('Código de cisterna existente'); | 137 | reject('Código de cisterna existente'); |
136 | } | 138 | } |
137 | if (idx !== $routeParams.idx && | 139 | if (idx !== $routeParams.idx && |
138 | !cisterna.desactivado) { | 140 | !cisterna.desactivado) { |
139 | totalCargado += cisterna.capacidad; | 141 | totalCargado += cisterna.capacidad; |
140 | } | 142 | } |
141 | }); | 143 | }); |
142 | resolve(); | 144 | resolve(); |
143 | }); | 145 | }); |
144 | }); | 146 | }); |
145 | } | 147 | } |
146 | } | 148 | } |
147 | ]); | 149 | ]); |
148 | 150 |