angular.module('focaBotoneraFacturador') .controller('focaBotoneraTarjetasController', [ '$scope', '$window', 'APP', function ($scope, $window, APP) { this.$onInit = function () { $scope.botones = $scope.$ctrl.botones; //TODO: controlar que no se estiren los botones if (APP) return; var max = ($scope.$ctrl.max) ? $scope.$ctrl.max : 12; if ($window.innerWidth > 576) { while (($scope.botones.length % max) !== 0) { $scope.botones.push(''); } } else { while (($scope.botones.length % 4) !== 0) { $scope.botones.push(''); } } }; function nombreFuncion(string) { var texto = 'seleccionar'; var arr = string.split(' '); arr.forEach(function (palabra) { palabra = palabra.charAt(0).toUpperCase() + palabra.slice(1); texto += palabra; }); return texto; } $scope.ejecutarFuncion = function (boton) { $scope.$parent[nombreFuncion(boton.label)](boton); }; $scope.activarBoton = function (boton) { $scope.botones.forEach(function (boton) { boton.active = false; }); boton.active = true; }; }]);