Commit ad4591d555700d964635ba9e022d43d4ac651d1d

Authored by Eric Fernandez
Exists in master

Merge branch 'develop' into 'master'

Develop

See merge request !17
spec/controllerSpec.js
... ... @@ -25,6 +25,7 @@ describe('Controladores abm precios condiciones', function() {
25 25 focaAbmPreciosCondicionesService: {},
26 26 $location: {},
27 27 focaModalService: {},
  28 + $localStorage: {},
28 29 focaBotoneraLateralService: {},
29 30 $timeout: timeout
30 31 });
... ... @@ -42,6 +43,7 @@ describe('Controladores abm precios condiciones', function() {
42 43 $scope: scope,
43 44 focaAbmPreciosCondicionesService: {},
44 45 $location: $location,
  46 + $localStorage: {},
45 47 focaModalService: {},
46 48 focaBotoneraLateralService: {},
47 49 $timeout: timeout
... ... @@ -67,6 +69,7 @@ describe('Controladores abm precios condiciones', function() {
67 69 $scope: scope,
68 70 focaAbmPreciosCondicionesService: {},
69 71 $location: {},
  72 + $localStorage: {},
70 73 focaModalService: focaModalService,
71 74 focaBotoneraLateralService: {},
72 75 $timeout: timeout
... ... @@ -94,6 +97,7 @@ describe('Controladores abm precios condiciones', function() {
94 97 $scope: scope,
95 98 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
96 99 $location: {},
  100 + $localStorage: {},
97 101 focaModalService: focaModalService,
98 102 focaBotoneraLateralService: {},
99 103 $timeout: timeout
... ... @@ -123,6 +127,7 @@ describe('Controladores abm precios condiciones', function() {
123 127 $scope: scope,
124 128 focaAbmPreciosCondicionesService: focaAbmPreciosCondicionesService,
125 129 $location: {},
  130 + $localStorage: {},
126 131 focaModalService: {},
127 132 focaBotoneraLateralService: {},
128 133 $timeout: timeout
... ... @@ -143,7 +148,9 @@ describe('Controladores abm precios condiciones', function() {
143 148 it('Existe el controlador focaAbmPrecioCondicionController', function() {
144 149 //act
145 150 var controlador = $controller('focaAbmPrecioCondicionController', {
146   - $scope: {},
  151 + $scope: {
  152 + $watch: function(){}
  153 + },
147 154 focaAbmPreciosCondicionesService: {
148 155 obtenerPrecioCondicion: function() {
149 156 return {
... ... @@ -157,6 +164,7 @@ describe('Controladores abm precios condiciones', function() {
157 164 focaModalService: {},
158 165 $timeout: timeout,
159 166 $uibModal: {},
  167 + $localStorage: {},
160 168 $window: {}
161 169 });
162 170  
... ... @@ -167,7 +175,11 @@ describe('Controladores abm precios condiciones', function() {
167 175 it('La funcion $scope.cancelar lleva a la ruta correcta', function() {
168 176 inject(function($location) {
169 177 //arrange
170   - var scope = {};
  178 + var scope = {
  179 + $watch: function() {},
  180 + salir: function() {},
  181 + formPrecioCondicion: ''
  182 + };
171 183 $controller('focaAbmPrecioCondicionController', {
172 184 $scope: scope,
173 185 focaAbmPreciosCondicionesService: {
... ... @@ -180,6 +192,7 @@ describe('Controladores abm precios condiciones', function() {
180 192 focaBotoneraLateralService: {},
181 193 $routeParams: {},
182 194 $location: $location,
  195 + $localStorage: {},
183 196 focaModalService: {},
184 197 $timeout: timeout,
185 198 $uibModal: {},
... ... @@ -187,7 +200,7 @@ describe('Controladores abm precios condiciones', function() {
187 200 });
188 201  
189 202 //act
190   - scope.cancelar();
  203 + scope.salir();
191 204  
192 205 //assert
193 206 expect($location.url()).toEqual('/precio-condicion');
... ... @@ -197,7 +210,9 @@ describe('Controladores abm precios condiciones', function() {
197 210 it('La funcion $scope.guardar llama a servicio.guardarPrecioCondicion', function() {
198 211 inject(function($location) {
199 212 //arrange
200   - var scope = {};
  213 + var scope = {
  214 + $watch: function() { }
  215 + };
201 216 var focaAbmPreciosCondicionesService = {
202 217 obtenerPrecioCondicion: function() {
203 218 return {
... ... @@ -217,13 +232,21 @@ describe('Controladores abm precios condiciones', function() {
217 232 focaBotoneraLateralService: {},
218 233 $routeParams: {},
219 234 $location: $location,
220   - focaModalService: {},
  235 + focaModalService: {
  236 + alert: function() {}
  237 + },
221 238 $timeout: timeout,
222 239 $uibModal: {},
  240 + $localStorage: {},
223 241 $window: window
224 242 });
225 243 var promesaGuardarPrecioCondicion = Promise.resolve(true);
226   - scope.precioCondicion = { listaPrecio: {} };
  244 + scope.precioCondicion = {
  245 + listaPrecio: {},
  246 + nombre: true,
  247 + descripcion: true,
  248 + idListaPrecio: true
  249 + };
227 250  
228 251 //act
229 252 //spyOn(window, 'location').and.returnValue({ assign: function() {} });
... ... @@ -238,7 +261,9 @@ describe('Controladores abm precios condiciones', function() {
238 261  
239 262 it('La funcion $scope.solicitarConfirmacionPlazoPago levanta modal confirm', function() {
240 263 //act
241   - var scope = {};
  264 + var scope = {
  265 + $watch: function() {}
  266 + };
242 267 var focaModalService = {
243 268 confirm: function() { }
244 269 };
... ... @@ -257,6 +282,7 @@ describe('Controladores abm precios condiciones', function() {
257 282 focaModalService: focaModalService,
258 283 $timeout: timeout,
259 284 $uibModal: {},
  285 + $localStorage: {},
260 286 $window: {}
261 287 });
262 288  
... ... @@ -271,7 +297,9 @@ describe('Controladores abm precios condiciones', function() {
271 297  
272 298 it('La funcion $scope.solicitarConfirmacionPlazoPago borra al dar ok', function(done) {
273 299 //act
274   - var scope = {};
  300 + var scope = {
  301 + $watch: function() { }
  302 + };
275 303 var focaModalService = {
276 304 confirm: function() { }
277 305 };
... ... @@ -291,6 +319,7 @@ describe('Controladores abm precios condiciones', function() {
291 319 $location: {},
292 320 focaModalService: focaModalService,
293 321 $timeout: timeout,
  322 + $localStorage: {},
294 323 $uibModal: {},
295 324 $window: {}
296 325 });
... ... @@ -313,7 +342,9 @@ describe('Controladores abm precios condiciones', function() {
313 342  
314 343 it('La funcion $scope.seleccionarListaPrecio levanta modal', function() {
315 344 //arrange
316   - var scope = {};
  345 + var scope = {
  346 + $watch: function() {}
  347 + };
317 348 var uibModal = {
318 349 open: function() { }
319 350 };
... ... @@ -333,6 +364,7 @@ describe('Controladores abm precios condiciones', function() {
333 364 focaModalService: {},
334 365 $timeout: timeout,
335 366 $uibModal: uibModal,
  367 + $localStorage: {},
336 368 $window: {}
337 369 });
338 370  
... ... @@ -346,7 +378,9 @@ describe('Controladores abm precios condiciones', function() {
346 378  
347 379 it('La funcion $scope.verProductosListaPrecio levanta modal', function() {
348 380 //arrange
349   - var scope = {};
  381 + var scope = {
  382 + $watch: function() {}
  383 + };
350 384 var uibModal = {
351 385 open: function() { }
352 386 };
... ... @@ -366,6 +400,7 @@ describe('Controladores abm precios condiciones', function() {
366 400 focaModalService: {},
367 401 $timeout: timeout,
368 402 $uibModal: uibModal,
  403 + $localStorage: {},
369 404 $window: {}
370 405 });
371 406 scope.precioCondicion = {
... ... @@ -381,7 +416,9 @@ describe('Controladores abm precios condiciones', function() {
381 416  
382 417 it('la función next suma uno a $scope.focused', function() {
383 418 //arrange
384   - var scope = {};
  419 + var scope = {
  420 + $watch: function() {}
  421 + };
385 422 var focaAbmPreciosCondicionesService = {
386 423 obtenerPrecioCondicion: function() {
387 424 return {
... ... @@ -398,6 +435,7 @@ describe('Controladores abm precios condiciones', function() {
398 435 focaModalService: {},
399 436 $timeout: timeout,
400 437 $uibModal: {},
  438 + $localStorage: {},
401 439 $window: {}
402 440 });
403 441  
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 + $scope.focusSearch = false;
  9 + $scope.filters = '';
  10 + $scope.now = new Date();
8 11 $timeout(function() {
9 12 focaBotoneraLateralService.showSalir(true);
10 13 focaBotoneraLateralService.showPausar(false);
11 14 focaBotoneraLateralService.showCancelar(false);
12 15 focaBotoneraLateralService.showGuardar(false);
  16 +
  17 + $scope.focusSearch = true;
13 18 });
  19 +
14 20 $scope.filters = '';
15 21 $scope.now = new Date();
16 22 $scope.editar = function(id) {
... ... @@ -45,31 +51,36 @@ angular.module('focaAbmPreciosCondiciones')
45 51 });
46 52 }
47 53 };
  54 +
  55 + if ($localStorage.precioCondicion) {
  56 + var precioCondicion = JSON.parse($localStorage.precioCondicion);
  57 + if (!precioCondicion.id) { precioCondicion.id = 0; }
  58 + $location.path('/precio-condicion/' + precioCondicion.id);
  59 + }
48 60 }
49 61 ])
50 62 .controller('focaAbmPrecioCondicionController', [
51 63 '$scope', 'focaAbmPreciosCondicionesService', 'focaBotoneraLateralService',
52   - '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window',
  64 + '$routeParams', '$location', 'focaModalService', '$timeout', '$uibModal', '$window', '$localStorage', '$filter',
53 65 function(
54 66 $scope, focaAbmPreciosCondicionesService, focaBotoneraLateralService,
55   - $routeParams, $location, focaModalService, $timeout, $uibModal, $window
56   - ) {
  67 + $routeParams, $location, focaModalService, $timeout, $uibModal, $window, $localStorage, $filter) {
57 68 $scope.focused = 1;
58 69 $scope.plazosAEliminar = [];
59 70 $scope.mostrarPlazos = $routeParams.id > 0;
60 71 $scope.now = new Date();
61 72 $scope.listaPrecioLabel = '';
  73 + $scope.precioCondicion = {
  74 + id: 0,
  75 + codigo: '',
  76 + nombre: '',
  77 + descripcion: '',
  78 + idListaPrecio: 0,
  79 + vigencia: new Date()
  80 + };
62 81 focaAbmPreciosCondicionesService.obtenerPrecioCondicion($routeParams.id)
63 82 .then(function(datos) {
64   - $scope.precioCondicion = {
65   - id: 0,
66   - codigo: '',
67   - nombre: '',
68   - descripcion: '',
69   - idListaPrecio: 0,
70   - vigencia: new Date()
71   - };
72   - if(datos.data.id) {
  83 + if (datos.data.id) {
73 84 $scope.precioCondicion = datos.data;
74 85 $scope.listaPrecioLabel = datos.data.listaPrecio.ID.trim() +
75 86 ' - ' + datos.data.listaPrecio.DES;
... ... @@ -91,20 +102,32 @@ angular.module('focaAbmPreciosCondiciones')
91 102 }
92 103 });
93 104  
  105 + $timeout(function() {getLSPrecioC();});
  106 +
94 107 $timeout(function() {
95 108 focaBotoneraLateralService.showSalir(false);
96 109 focaBotoneraLateralService.showPausar(true);
97   - focaBotoneraLateralService.showCancelar(true);
  110 + focaBotoneraLateralService.showCancelar(false);
98 111 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
  112 + focaBotoneraLateralService.addCustomButton('Salir', $scope.salir);
99 113 });
100 114  
101   - $scope.cancelar = function() {
102   - $location.path('/precio-condicion');
  115 + $scope.salir = function() {
  116 +
  117 + if ($scope.formPrecioCondicion.$pristine == false) {
  118 + focaModalService.confirm(
  119 + '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
  120 + ).then(function(data) {
  121 + if (data) {
  122 + $location.path('/precio-condicion');
  123 + }
  124 + });
  125 + } else {
  126 + $location.path('/precio-condicion');
  127 + }
103 128 };
104 129 $scope.guardar = function() {
105 130  
106   - console.log($scope.precioCondicion);
107   -
108 131 if (!$scope.precioCondicion.nombre) {
109 132 focaModalService.alert('Ingrese nombre');
110 133 return;
... ... @@ -120,7 +143,7 @@ angular.module('focaAbmPreciosCondiciones')
120 143 var precioCondicion = $scope.precioCondicion;
121 144 precioCondicion.idListaPrecio = precioCondicion.listaPrecio.ID;
122 145 delete precioCondicion.listaPrecio;
123   - if($scope.mostrarPlazos) {
  146 + if ($scope.mostrarPlazos) {
124 147 promises.push(
125 148 focaAbmPreciosCondicionesService
126 149 .guardarPlazosPago($scope.precioCondicion.plazos)
... ... @@ -147,15 +170,15 @@ angular.module('focaAbmPreciosCondiciones')
147 170 };
148 171  
149 172 $scope.agregarPlazo = function(key) {
150   - if(key === 13) {
151   - if(!$scope.plazoACargar.dias && $scope.plazoACargar.dias !== 0) {
  173 + if (key === 13) {
  174 + if (!$scope.plazoACargar.dias && $scope.plazoACargar.dias !== 0) {
152 175 focaModalService.alert('Ingrese cantidad de días');
153 176 return;
154 177 }
155 178 var tieneEseDia = $scope.precioCondicion.plazos.filter(function(a) {
156 179 return a.dias === $scope.plazoACargar.dias;
157 180 });
158   - if(tieneEseDia.length > 0) {
  181 + if (tieneEseDia.length > 0) {
159 182 focaModalService.alert('Ya ha ingresado un plazo con esos días');
160 183 return;
161 184 }
... ... @@ -169,7 +192,7 @@ angular.module('focaAbmPreciosCondiciones')
169 192 }
170 193 };
171 194 $scope.quitarPlazo = function(key) {
172   - if($scope.precioCondicion.plazos[key].id)
  195 + if ($scope.precioCondicion.plazos[key].id)
173 196 $scope.plazosAEliminar.push($scope.precioCondicion.plazos[key].id);
174 197  
175 198 $scope.precioCondicion.plazos.splice(key, 1);
... ... @@ -193,7 +216,7 @@ angular.module('focaAbmPreciosCondiciones')
193 216 };
194 217  
195 218 $scope.seleccionarListaPrecio = function(key) {
196   - if(key === 13){
  219 + if (key === 13){
197 220 var modalInstance = $uibModal.open(
198 221 {
199 222 ariaLabelledBy: 'Busqueda de Listas de precio',
... ... @@ -203,7 +226,7 @@ angular.module('focaAbmPreciosCondiciones')
203 226 }
204 227 );
205 228 modalInstance.result.then(function(listaPrecio) {
206   - $scope.precioCondicion.idListaPrecio = listaPrecio.ID;
  229 + $scope.precioCondicion.idListaPrecio = listaPrecio.ID;
207 230 $scope.precioCondicion.listaPrecio = listaPrecio;
208 231 $scope.listaPrecioLabel = listaPrecio.ID + ' - ' + listaPrecio.DES;
209 232 $scope.focused = 4;
... ... @@ -231,7 +254,32 @@ angular.module('focaAbmPreciosCondiciones')
231 254 };
232 255  
233 256 $scope.next = function(key) {
234   - if(key === 13) $scope.focused++;
  257 + if (key === 13) $scope.focused++;
235 258 };
  259 +
  260 + //watch
  261 + $scope.$watch('precioCondicion', function(newValue) {
  262 + focaBotoneraLateralService.setPausarData({
  263 + label: 'precioCondicion',
  264 + val: newValue
  265 + });
  266 + }, true);
  267 +
  268 + function setearPrecioCondicion(precioCondicion) {
  269 + $scope.precioCondicion = precioCondicion;
  270 + $scope.$broadcast('addCabecera', {
  271 + label: 'Precio y Condicion:',
  272 + valor: $filter('rellenarDigitos')(precioCondicion.id)
  273 + });
  274 + }
  275 +
  276 + function getLSPrecioC() {
  277 + var precioCondicion = JSON.parse($localStorage.precioCondicion || null);
  278 +
  279 + if (precioCondicion) {
  280 + setearPrecioCondicion(precioCondicion);
  281 + delete $localStorage.precioCondicion;
  282 + }
  283 + }
236 284 }
237 285 ]);
src/views/foca-abm-precios-condiciones-item.html
... ... @@ -6,7 +6,7 @@
6 6 ></foca-cabecera-facturador>
7 7 </div>
8 8 <div class="row">
9   - <form class="col-md-10">
  9 + <form class= "col-md-10" name="formPrecioCondicion">
10 10 <input type="hidden" name="id" ng-model="precioCondicion.id" />
11 11 <div class="row mb-3">
12 12 <label class="col-sm-2 col-form-label">Código</label>
... ... @@ -89,6 +89,7 @@
89 89 foca-focus="focused == 4"
90 90 ng-focus="focused = 4"
91 91 placeholder="Días"
  92 + teclado-virtual
92 93 />
93 94 <div class="input-group-append">
94 95 <button
src/views/foca-abm-precios-condiciones-listado.html
... ... @@ -16,6 +16,7 @@
16 16 teclado-virtual
17 17 ng-keypress="buscar($event.keyCode)"
18 18 ng-model="filters"
  19 + foca-focus="focusSearch"
19 20 />
20 21 <div class="input-group-append">
21 22 <button