Commit 99b6c0ef65e8ad1ff9489785cf898eb2cde8e0d2

Authored by Eric
1 parent 72b46e4e12
Exists in master

secciones en cabecera

Showing 2 changed files with 59 additions and 29 deletions   Show diff stats
src/js/controller.js
... ... @@ -5,26 +5,55 @@ angular.module('focaCabeceraFacturador')
5 5 function($scope, $filter) {
6 6  
7 7 $scope.showCabecera = true;
8   - $scope.cabecera = [];
  8 + $scope.cabeceras = [
  9 + cabecera = {
  10 + cabeceras: []
  11 + }
  12 + ];
9 13  
10 14 $scope.$on('addCabecera', function(event, data) {
11   - var propiedad = $filter('filter')($scope.cabecera, {label: data.label}, true);
12   - if(propiedad.length === 1) {
  15 +
  16 + var seccion = $scope.cabeceras[0];
  17 +
  18 + if (data.seccion) {
  19 + seccion = $filter('filter')($scope.cabeceras, { seccion: data.seccion }, true)[0];
  20 +
  21 + if (!seccion) {
  22 + seccion = {}
  23 + seccion.seccion = data.seccion;
  24 + seccion.cabeceras = [];
  25 + $scope.cabeceras.push(seccion);
  26 + }
  27 + }
  28 +
  29 + var propiedad = $filter('filter')(seccion.cabeceras, { label: data.label }, true);
  30 +
  31 + if (propiedad.length === 1) {
13 32 propiedad[0].valor = data.valor;
14   - }else {
15   - $scope.cabecera.push({label: data.label, valor: data.valor});
  33 + } else {
  34 + seccion.cabeceras.push({label: data.label, valor: data.valor});
16 35 }
17 36 });
18 37  
19 38 $scope.$on('removeCabecera', function(event, data) {
20   - var propiedad = $filter('filter')($scope.cabecera, {label: data}, true);
21   - if(propiedad.length === 1) {
22   - $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1);
  39 +
  40 + var seccion = $scope.cabeceras[0];
  41 + if (data.seccion) {
  42 + seccion = $filter('filter')($scope.cabeceras, { seccion: data.seccion }, true)[0];
  43 + }
  44 + var propiedad = $filter('filter')(seccion.cabeceras, {label: data}, true);
  45 + if (propiedad.length === 1) {
  46 + seccion.cabeceras.splice(seccion.cabeceras.indexOf(propiedad[0]), 1);
23 47 }
24 48 });
25 49  
26   - $scope.$on('cleanCabecera', function() {
27   - $scope.cabecera = [];
  50 + $scope.$on('cleanCabecera', function(event, data) {
  51 + if (!data) {
  52 + $scope.cabeceras = [];
  53 + } else {
  54 + var seccion = $filter('filter')($scope.cabeceras, { seccion: data.seccion }, true)[0];
  55 + $scope.cabeceras.splice($scope.cabeceras.indexOf(seccion), 1)
  56 + }
28 57 });
29 58  
30 59 }]);
src/views/cabecera.html
... ... @@ -52,29 +52,30 @@
52 52 </span>
53 53 </div>
54 54 </div>
55   - <div class="row py-2">
56   - <div class="col-auto" ng-repeat="cab in cabecera" ng-show="showCabecera">
  55 + <div class="row py-2" ng-repeat="seccion in cabeceras" ng-show="showCabecera">
  56 + <strong ng-bind="seccion.seccion"></strong>
  57 + <div class="col-auto" ng-repeat="cab in seccion.cabeceras" ng-show="showCabecera">
57 58 <span class="label" ng-bind="cab.label"></span>
58 59 <span class="valor" ng-bind="cab.valor"></span>
59 60 </div>
60   - <a
61   - class="btn col-12 btn-secondary d-sm-none"
62   - ng-show="cabecera.length > 0"
63   - ng-click="showCabecera = !showCabecera"
64   - >
65   - <i
66   - class="fa fa-chevron-down"
67   - ng-hide="showCabecera"
68   - aria-hidden="true"
69   - >
70   - </i>
71   - <i
72   - class="fa fa-chevron-up"
73   - ng-show="showCabecera"
74   - aria-hidden="true">
75   - </i>
76   - </a>
77 61 </div>
  62 + <a
  63 + class="btn col-12 btn-secondary"
  64 + ng-show="cabeceras.length > 1"
  65 + ng-click="showCabecera = !showCabecera"
  66 + >
  67 + <i
  68 + class="fa fa-chevron-down"
  69 + ng-hide="showCabecera"
  70 + aria-hidden="true"
  71 + >
  72 + </i>
  73 + <i
  74 + class="fa fa-chevron-up"
  75 + ng-show="showCabecera"
  76 + aria-hidden="true">
  77 + </i>
  78 + </a>
78 79 </div>
79 80 </div>
80 81 </div>