Commit 46fd86bb204059e34459e93cfb14a45bb216fb08
1 parent
7965aabb27
Exists in
master
Boton Pausar
Showing
1 changed file
with
47 additions
and
16 deletions
Show diff stats
src/js/controller.js
1 | 1 | angular.module('focaAbmPreciosCondiciones') |
2 | 2 | .controller('focaAbmPreciosCondicionesController', [ |
3 | 3 | '$scope', 'focaAbmPreciosCondicionesService', '$location', |
4 | - 'focaModalService', 'focaBotoneraLateralService', '$timeout', | |
4 | + 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage', | |
5 | 5 | function($scope, focaAbmPreciosCondicionesService, $location, |
6 | - focaModalService, focaBotoneraLateralService, $timeout) { | |
6 | + focaModalService, focaBotoneraLateralService, $timeout, $localStorage) { | |
7 | 7 | |
8 | 8 | $timeout(function() { |
9 | 9 | focaBotoneraLateralService.showSalir(true); |
... | ... | @@ -11,6 +11,7 @@ angular.module('focaAbmPreciosCondiciones') |
11 | 11 | focaBotoneraLateralService.showCancelar(false); |
12 | 12 | focaBotoneraLateralService.showGuardar(false); |
13 | 13 | }); |
14 | + | |
14 | 15 | $scope.filters = ''; |
15 | 16 | $scope.now = new Date(); |
16 | 17 | $scope.editar = function(id) { |
... | ... | @@ -45,15 +46,20 @@ angular.module('focaAbmPreciosCondiciones') |
45 | 46 | }); |
46 | 47 | } |
47 | 48 | }; |
49 | + | |
50 | + if ($localStorage.precioCondicion) { | |
51 | + var precioCondicion = JSON.parse($localStorage.precioCondicion); | |
52 | + if (!precioCondicion.id) { precioCondicion.id = 0; } | |
53 | + $location.path('/precio-condicion/' + precioCondicion.id); | |
54 | + } | |
48 | 55 | } |
49 | 56 | ]) |
50 | 57 | .controller('focaAbmPrecioCondicionController', [ |
51 | 58 | '$scope', 'focaAbmPreciosCondicionesService', 'focaBotoneraLateralService', |
52 | - '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window', | |
59 | + '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window', '$localStorage', '$filter', | |
53 | 60 | function( |
54 | 61 | $scope, focaAbmPreciosCondicionesService, focaBotoneraLateralService, |
55 | - $routeParams, $location, focaModalService, $timeout, $uibModal, $window | |
56 | - ) { | |
62 | + $routeParams, $location, focaModalService, $timeout, $uibModal, $window, $localStorage, $filter) { | |
57 | 63 | $scope.focused = 1; |
58 | 64 | $scope.plazosAEliminar = []; |
59 | 65 | $scope.mostrarPlazos = $routeParams.id > 0; |
... | ... | @@ -69,7 +75,7 @@ angular.module('focaAbmPreciosCondiciones') |
69 | 75 | idListaPrecio: 0, |
70 | 76 | vigencia: new Date() |
71 | 77 | }; |
72 | - if(datos.data.id) { | |
78 | + if (datos.data.id) { | |
73 | 79 | $scope.precioCondicion = datos.data; |
74 | 80 | $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() + |
75 | 81 | ' - ' + datos.data.listaPrecio.DES; |
... | ... | @@ -91,6 +97,8 @@ angular.module('focaAbmPreciosCondiciones') |
91 | 97 | } |
92 | 98 | }); |
93 | 99 | |
100 | + $timeout(function() {getLSPrecioC();}); | |
101 | + | |
94 | 102 | $timeout(function() { |
95 | 103 | focaBotoneraLateralService.showSalir(false); |
96 | 104 | focaBotoneraLateralService.showPausar(true); |
... | ... | @@ -103,8 +111,6 @@ angular.module('focaAbmPreciosCondiciones') |
103 | 111 | }; |
104 | 112 | $scope.guardar = function() { |
105 | 113 | |
106 | - console.log($scope.precioCondicion); | |
107 | - | |
108 | 114 | if (!$scope.precioCondicion.nombre) { |
109 | 115 | focaModalService.alert('Ingrese nombre'); |
110 | 116 | return; |
... | ... | @@ -120,7 +126,7 @@ angular.module('focaAbmPreciosCondiciones') |
120 | 126 | var precioCondicion = $scope.precioCondicion; |
121 | 127 | precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID; |
122 | 128 | delete precioCondicion.listaPrecio; |
123 | - if($scope.mostrarPlazos) { | |
129 | + if ($scope.mostrarPlazos) { | |
124 | 130 | promises.push( |
125 | 131 | focaAbmPreciosCondicionesService |
126 | 132 | .guardarPlazosPago($scope.precioCondicion.plazos) |
... | ... | @@ -147,15 +153,15 @@ angular.module('focaAbmPreciosCondiciones') |
147 | 153 | }; |
148 | 154 | |
149 | 155 | $scope.agregarPlazo = function(key) { |
150 | - if(key === 13) { | |
151 | - if(!$scope.plazoACargar.dias && $scope.plazoACargar.dias !== 0) { | |
156 | + if (key === 13) { | |
157 | + if (!$scope.plazoACargar.dias && $scope.plazoACargar.dias !== 0) { | |
152 | 158 | focaModalService.alert('Ingrese cantidad de días'); |
153 | 159 | return; |
154 | 160 | } |
155 | 161 | var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) { |
156 | 162 | return a.dias === $scope.plazoACargar.dias; |
157 | 163 | }); |
158 | - if(tieneEseDia.length > 0) { | |
164 | + if (tieneEseDia.length > 0) { | |
159 | 165 | focaModalService.alert('Ya ha ingresado un plazo con esos días'); |
160 | 166 | return; |
161 | 167 | } |
... | ... | @@ -169,7 +175,7 @@ angular.module('focaAbmPreciosCondiciones') |
169 | 175 | } |
170 | 176 | }; |
171 | 177 | $scope.quitarPlazo = function(key) { |
172 | - if($scope.precioCondicion.plazos[key].id) | |
178 | + if ($scope.precioCondicion.plazos[key].id) | |
173 | 179 | $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id); |
174 | 180 | |
175 | 181 | $scope.precioCondicion.plazos.splice(key, 1); |
... | ... | @@ -193,7 +199,7 @@ angular.module('focaAbmPreciosCondiciones') |
193 | 199 | }; |
194 | 200 | |
195 | 201 | $scope.seleccionarListaPrecio = function(key) { |
196 | - if(key === 13){ | |
202 | + if (key === 13){ | |
197 | 203 | var modalInstance = $uibModal.open( |
198 | 204 | { |
199 | 205 | ariaLabelledBy: 'Busqueda de Listas de precio', |
... | ... | @@ -203,7 +209,7 @@ angular.module('focaAbmPreciosCondiciones') |
203 | 209 | } |
204 | 210 | ); |
205 | 211 | modalInstance.result.then(function(listaPrecio) { |
206 | - $scope.precioCondicion.idListaPrecio = listaPrecio.ID; | |
212 | + $scope.precioCondicion.idListaPrecio = listaPrecio.ID; | |
207 | 213 | $scope.precioCondicion.listaPrecio = listaPrecio; |
208 | 214 | $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES; |
209 | 215 | $scope.focused = 4; |
... | ... | @@ -231,7 +237,32 @@ angular.module('focaAbmPreciosCondiciones') |
231 | 237 | }; |
232 | 238 | |
233 | 239 | $scope.next = function(key) { |
234 | - if(key === 13) $scope.focused++; | |
240 | + if (key === 13) $scope.focused++; | |
235 | 241 | }; |
242 | + | |
243 | + //watch | |
244 | + $scope.$watch('precioCondicion', function(newValue) { | |
245 | + focaBotoneraLateralService.setPausarData({ | |
246 | + label: 'precioCondicion', | |
247 | + val: newValue | |
248 | + }); | |
249 | + }, true); | |
250 | + | |
251 | + function setearPrecioCondicion(precioCondicion) { | |
252 | + $scope.precioCondicion = precioCondicion; | |
253 | + $scope.$broadcast('addCabecera', { | |
254 | + label: 'Precio y Condicion:', | |
255 | + valor: $filter('rellenarDigitos')(precioCondicion.id) | |
256 | + }); | |
257 | + } | |
258 | + | |
259 | + function getLSPrecioC() { | |
260 | + var precioCondicion = JSON.parse($localStorage.precioCondicion || null); | |
261 | + | |
262 | + if (precioCondicion) { | |
263 | + setearPrecioCondicion(precioCondicion); | |
264 | + delete $localStorage.precioCondicion; | |
265 | + } | |
266 | + } | |
236 | 267 | } |
237 | 268 | ]); |