-
Notifications
You must be signed in to change notification settings - Fork 2
/
table_column_toggler.directive.js
73 lines (70 loc) · 2.93 KB
/
table_column_toggler.directive.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(function($){
angular.module('cmoro.tableColumnToggler', [])
.controller('tableColumnController', function($scope){
$scope.tableTRefresh = function(){
angular.forEach($scope.tableTHeadsElements, function(elem,index){
var headObj = $scope.tableTHeads[index];
if(headObj && headObj.hide){
$(elem).addClass('ng-hide');
}else{
$(elem).removeClass('ng-hide');
}
});
var trs = $scope.tableTTable.find('tr');
angular.forEach(trs, function(tr, index){
var tds = $(tr).find('td');
angular.forEach(tds, function(item, index){
var headObj = $scope.tableTHeads[index];
if(headObj && headObj.hide){
$(item).addClass('ng-hide');
}else{
$(item).removeClass('ng-hide');
}
});
});
}
})
.directive('tableColumnTogglerTable', function () {
return {
restrict: "A",
link: function ($scope, element, attrs) {
$scope.tableTTable = $(element);
$scope.tableTHeads =[];
$scope.tableTHeadsElements = $scope.tableTTable.find('th');
angular.forEach($scope.tableTHeadsElements, function(elem,index){
var ignore = $(elem).attr('ignore')=="";
var hide = false;
if($(elem).attr('hide')==""){
hide = true;
$(elem).addClass('ng-hide');
}
$scope.tableTHeads.push({'label':$(elem).text(), 'hide':hide, 'ignore': ignore});
});
}
};
}).directive('tableColumnTogglerRepeat', function () {
return {
restrict: "A",
link: function ($scope, element, attrs) {
var tds = element.find('td');
angular.forEach(tds, function(item, index){
var headObj = $scope.tableTHeads[index];
if(headObj && headObj.hide) $(item).addClass('ng-hide');
});
}
};
}).directive('tableColumnTogglerControl', ['$compile', function ($compile) {
return {
restrict: 'E',
controller: 'tableColumnController',
link: function ($scope, element, attrs) {
var wt = $scope.$watch('tableHeads', function(newValue, oldValue) {
var tpl = '<div class="dropdown table-column-toggler-control"><button class="btn btn-group" data-toggle="dropdown">Editar Campos <span class="caret"></span></button> <ul class="dropdown-menu"><div ng-repeat="hd in tableTHeads" ng-hide="hd.ignore"><input type="checkbox" ng-click="tableTRefresh()" ng-model="hd.hide" ng-true-value="false" ng-false-value="true">{{hd.label}}</div><ul></div>';
var compHtml = $compile(tpl)($scope);
$(element).html(compHtml);
wt();
}, true);
}
};
}]);
})(jQuery);