|
@@ -7,6 +7,9 @@ angular.module('luticateUtils')
|
7
|
7
|
function(dialogs, luticateDialogErrorHelper) {
|
8
|
8
|
return {
|
9
|
9
|
restrict: 'E',
|
|
10
|
+ scope: {
|
|
11
|
+ options: '&'
|
|
12
|
+ },
|
10
|
13
|
templateUrl: "/luticate/lutable.html",
|
11
|
14
|
link: function ($scope, element, attrs) {
|
12
|
15
|
$scope.page = 0;
|
|
@@ -15,6 +18,8 @@ angular.module('luticateUtils')
|
15
|
18
|
$scope.pages = [];
|
16
|
19
|
$scope.selectedItems = [];
|
17
|
20
|
|
|
21
|
+ $scope.tableOptions = $scope.options();
|
|
22
|
+
|
18
|
23
|
var promiseLoadItems = {
|
19
|
24
|
id: "promiseLoadItems",
|
20
|
25
|
groups: ['itemList']
|
|
@@ -25,7 +30,7 @@ angular.module('luticateUtils')
|
25
|
30
|
};
|
26
|
31
|
|
27
|
32
|
$scope.loadPage = function (page) {
|
28
|
|
- $scope.getLoadPagePromise(page, $scope.perPage, promiseLoadItems)
|
|
33
|
+ $scope.tableOptions.getLoadPagePromise(page, $scope.perPage, promiseLoadItems)
|
29
|
34
|
.then(function (items) {
|
30
|
35
|
$scope.page = page;
|
31
|
36
|
$scope.items = items;
|
|
@@ -40,7 +45,7 @@ angular.module('luticateUtils')
|
40
|
45
|
};
|
41
|
46
|
|
42
|
47
|
$scope.displayItem = function (item) {
|
43
|
|
- var ctrl = $scope.getEditController();
|
|
48
|
+ var ctrl = $scope.tableOptions.getEditController();
|
44
|
49
|
dialogs.create('views/modals/' + ctrl.toLowerCase() + '.html', ctrl + 'Controller', item)
|
45
|
50
|
.result.then(function (data) {
|
46
|
51
|
$scope.loadPage($scope.page);
|
|
@@ -52,7 +57,7 @@ angular.module('luticateUtils')
|
52
|
57
|
$scope.loadPage($scope.page);
|
53
|
58
|
return;
|
54
|
59
|
}
|
55
|
|
- $scope.getDelPromise($scope.selectedItems[0], promiseDelItems)
|
|
60
|
+ $scope.tableOptions.getDelPromise($scope.selectedItems[0], promiseDelItems)
|
56
|
61
|
.then(function (data) {
|
57
|
62
|
$scope.selectedItems.splice(0, 1);
|
58
|
63
|
$scope.removeItems();
|
|
@@ -66,7 +71,7 @@ angular.module('luticateUtils')
|
66
|
71
|
};
|
67
|
72
|
|
68
|
73
|
$scope.addItem = function () {
|
69
|
|
- var ctrl = $scope.getEditController();
|
|
74
|
+ var ctrl = $scope.tableOptions.getEditController();
|
70
|
75
|
dialogs.create('views/modals/' + ctrl.toLowerCase() + '.html', ctrl + 'Controller', null)
|
71
|
76
|
.result.then(function (data) {
|
72
|
77
|
$scope.loadPage($scope.page);
|
|
@@ -74,7 +79,7 @@ angular.module('luticateUtils')
|
74
|
79
|
};
|
75
|
80
|
|
76
|
81
|
$scope.toggleSelectedItem = function (item) {
|
77
|
|
- var id = $scope.getItemId(item);
|
|
82
|
+ var id = $scope.tableOptions.getItemId(item);
|
78
|
83
|
var idx = $scope.selectedItems.indexOf(id);
|
79
|
84
|
if (idx > -1) {
|
80
|
85
|
$scope.selectedItems.splice(idx, 1);
|
|
@@ -91,18 +96,18 @@ angular.module('luticateUtils')
|
91
|
96
|
else {
|
92
|
97
|
$scope.selectedItems = [];
|
93
|
98
|
for (var i = 0; i < $scope.items.Data.length; ++i) {
|
94
|
|
- $scope.selectedItems.push($scope.getItemId($scope.items.Data[i]));
|
|
99
|
+ $scope.selectedItems.push($scope.tableOptions.getItemId($scope.items.Data[i]));
|
95
|
100
|
}
|
96
|
101
|
}
|
97
|
102
|
};
|
98
|
103
|
|
99
|
104
|
$scope.isItemChecked = function(item)
|
100
|
105
|
{
|
101
|
|
- return $scope.selectedItems.indexOf($scope.getItemId(item)) > -1;
|
|
106
|
+ return $scope.selectedItems.indexOf($scope.tableOptions.getItemId(item)) > -1;
|
102
|
107
|
};
|
103
|
108
|
|
104
|
|
- if (!$scope.getItemId) {
|
105
|
|
- $scope.getItemId = function(item)
|
|
109
|
+ if (!$scope.tableOptions.getItemId) {
|
|
110
|
+ $scope.tableOptions.getItemId = function(item)
|
106
|
111
|
{
|
107
|
112
|
return item.Id;
|
108
|
113
|
};
|
|
@@ -120,20 +125,20 @@ angular.module('luticateUtils').run(['$templateCache', function($templateCache)
|
120
|
125
|
' <table class="col-sm-12 table table-hover">' +
|
121
|
126
|
' <thead>' +
|
122
|
127
|
' <tr>' +
|
123
|
|
-' <th>' +
|
|
128
|
+' <th lu-show-permission="{{ tableOptions.permissions.del }}">' +
|
124
|
129
|
' <input type="checkbox" ng-click="toggleSelectAll()"' +
|
125
|
130
|
' ng-checked="selectedItems.length == items.Data.length && items.Data.length != 0">' +
|
126
|
131
|
' </th>' +
|
127
|
|
-' <th class="col-sm-{{ col.width }}" ng-repeat="col in columns">{{ col.name }}</th>' +
|
|
132
|
+' <th class="col-sm-{{ col.width }}" ng-repeat="col in tableOptions.columns">{{ col.name }}</th>' +
|
128
|
133
|
'</tr>' +
|
129
|
134
|
'</thead>' +
|
130
|
135
|
'<tbody>' +
|
131
|
136
|
'<tr ng-repeat="item in items.Data" style="cursor: pointer" ng-click="displayItem(item)">' +
|
132
|
|
-' <td>' +
|
|
137
|
+' <td lu-show-permission="{{ tableOptions.permissions.del }}">' +
|
133
|
138
|
' <input name="selectedItems[]" type="checkbox" ng-checked="isItemChecked(item)"' +
|
134
|
139
|
' ng-click="$event.stopPropagation();toggleSelectedItem(item)" >' +
|
135
|
140
|
' </td>' +
|
136
|
|
-' <td ng-repeat="col in columns">{{ col.getValue(item) }}</td>' +
|
|
141
|
+' <td ng-repeat="col in tableOptions.columns">{{ col.getValue(item) }}</td>' +
|
137
|
142
|
'</tr>' +
|
138
|
143
|
'</tbody>' +
|
139
|
144
|
'</table>' +
|
|
@@ -143,10 +148,11 @@ angular.module('luticateUtils').run(['$templateCache', function($templateCache)
|
143
|
148
|
'</div>' +
|
144
|
149
|
|
145
|
150
|
'<div class="col-sm-12">' +
|
146
|
|
-' <button class="btn btn-default" type="button" ng-click="removeItems()" ng-disabled="selectedItems.length == 0">' +
|
|
151
|
+' <button class="btn btn-default" type="button" ng-click="removeItems()"' +
|
|
152
|
+'ng-disabled="selectedItems.length == 0" lu-show-permission="{{ tableOptions.permissions.del }}">' +
|
147
|
153
|
' <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Remove' +
|
148
|
154
|
' </button>' +
|
149
|
|
-' <button class="btn btn-default" type="button" ng-click="addItem()">' +
|
|
155
|
+' <button class="btn btn-default" type="button" ng-click="addItem()" lu-show-permission="{{ tableOptions.permissions.add }}">' +
|
150
|
156
|
' <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add' +
|
151
|
157
|
' </button>' +
|
152
|
158
|
' </div>' +
|