controller.js
1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
angular.module('focaBotoneraFacturador')
.controller('focaBotoneraFacturadorController', [
'$scope',
'$window',
'APP',
function($scope, $window, APP) {
this.$onInit = function() {
ordenarBotones();
};
this.$onChanges = function() {
ordenarBotones();
};
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(nombre) {
$scope.$parent[nombreFuncion(nombre)]();
};
$scope.ejecutarFuncionDelete = function(variable) {
$scope.$parent['clean' + variable]();
};
$scope.existeFuncionDelete = function(variable) {
if ($scope.$parent['clean' + variable]) return true;
return false;
};
function ordenarBotones() {
$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('');
}
}
}
}]);