Commit 89aafe6a28f94ea42f6cd0d7a733a198d911b4b2

Authored by Jose Pinto
1 parent e8a154788e
Exists in master and in 1 other branch develop

calcula extra

1 angular.module('focaBotoneraFacturador', []) 1 angular.module('focaBotoneraFacturador', [])
2 .component('focaBotoneraFacturador', { 2 .component('focaBotoneraFacturador', {
3 templateUrl: 'src/views/botonera-facturador.html', 3 templateUrl: 'src/views/botonera-facturador.html',
4 controller: 'focaBotoneraFacturadorController', 4 controller: 'focaBotoneraFacturadorController',
5 bindings: { 5 bindings: {
6 botones: '<', 6 botones: '<'
7 extra: '<'
8 } 7 }
9 }); 8 });
10 9
src/js/controller.js
1 angular.module('focaBotoneraFacturador') 1 angular.module('focaBotoneraFacturador')
2 .controller('focaBotoneraFacturadorController', [ 2 .controller('focaBotoneraFacturadorController', [
3 '$scope', 3 '$scope',
4 function($scope) { 4 '$window',
5 function($scope, $window) {
5 this.$onInit = function() { 6 this.$onInit = function() {
6 $scope.botones = $scope.$ctrl.botones; 7 $scope.botones = $scope.$ctrl.botones;
7 8
8 for(var i = 0; i < $scope.$ctrl.extra; i++) { 9 if($window.innerWidth > 576) {
9 $scope.botones.push(''); 10 while(($scope.botones.length % 12) !== 0) {
11 $scope.botones.push('');
12 }
13 }else {
14 while(($scope.botones.length % 3) !== 0) {
15 $scope.botones.push('');
16 }
10 } 17 }
11 }; 18 };
12 19
13 function nombreFuncion(string) { 20 function nombreFuncion(string) {
14 var texto = 'seleccionar'; 21 var texto = 'seleccionar';
15 var arr = string.split(' '); 22 var arr = string.split(' ');
16 arr.forEach(function(palabra) { 23 arr.forEach(function(palabra) {
17 palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); 24 palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1);
18 texto += palabra; 25 texto += palabra;
19 }); 26 });
20 return texto; 27 return texto;
21 } 28 }
22 29
23 $scope.ejecutarFuncion = function(nombre) { 30 $scope.ejecutarFuncion = function(nombre) {
24 $scope.$parent[nombreFuncion(nombre)](); 31 $scope.$parent[nombreFuncion(nombre)]();
25 }; 32 };
26 }]); 33 }]);
27 34
src/views/botonera-facturador.html
1 <div 1 <div
2 class="col-4 col-sm-2 px-1 py-1 m-auto m-md-0" 2 class="col-4 col-sm-2 px-1 py-1 m-auto m-md-0"
3 ng-repeat="boton in botones track by $index" 3 ng-repeat="boton in botones track by $index"
4 ng-class="{'d-none d-md-grid': boton == ''}"> 4 ng-class="{'d-md-grid': boton == ''}">
5 <button 5 <button
6 type="button" 6 type="button"
7 class="btn btn-default btn-block btn-xs text-center py-1 rounded border border-light" 7 class="btn btn-default btn-block btn-xs text-center py-1 rounded border border-light"
8 ng-click="(boton != '') ? ejecutarFuncion(boton.label) : null" 8 ng-click="(boton != '') ? ejecutarFuncion(boton.label) : null"
9 ng-class="{'d-sm-block h-100': boton == ''}" 9 ng-class="{'d-sm-block h-100': boton == ''}"
10 > 10 >
11 <img ng-src="../img/{{boton.image}}" alt=""> 11 <img ng-src="../img/{{boton.image}}" alt="">
12 <span>{{boton.label}}</span> 12 <span>{{boton.label}}</span>
13 </button> 13 </button>
14 </div> 14 </div>
15 15