|
@@ -3,7 +3,7 @@
|
3
|
3
|
*/
|
4
|
4
|
|
5
|
5
|
angular.module('luticateUtils')
|
6
|
|
- .directive('luTable', ['dialogs', 'luticateDialogErrorHelper',
|
|
6
|
+ .directive('luEditTable', ['dialogs', 'luticateDialogErrorHelper',
|
7
|
7
|
function(dialogs, luticateDialogErrorHelper) {
|
8
|
8
|
return {
|
9
|
9
|
restrict: 'E',
|
|
@@ -12,67 +12,61 @@ angular.module('luticateUtils')
|
12
|
12
|
},
|
13
|
13
|
templateUrl: "/luticate/lutable.html",
|
14
|
14
|
link: function ($scope, element, attrs) {
|
15
|
|
- $scope.page = 0;
|
16
|
|
- $scope.perPage = 15;
|
17
|
|
- $scope.items = [];
|
18
|
|
- $scope.pages = [];
|
19
|
|
- $scope.selectedItems = [];
|
20
|
15
|
|
21
|
16
|
$scope.tableOptions = $scope.options();
|
22
|
17
|
|
23
|
|
- var promiseLoadItems = {
|
24
|
|
- id: "promiseLoadItems",
|
25
|
|
- groups: ['itemList']
|
26
|
|
- };
|
27
|
|
- var promiseDelItems = {
|
28
|
|
- id: "promiseDelItems",
|
29
|
|
- loadGroups: ['itemList']
|
30
|
|
- };
|
31
|
|
-
|
32
|
|
- $scope.loadPage = function (page) {
|
33
|
|
- $scope.tableOptions.getLoadPagePromise(page, $scope.perPage, promiseLoadItems)
|
34
|
|
- .then(function (items) {
|
35
|
|
- $scope.page = page;
|
36
|
|
- $scope.items = items;
|
37
|
|
- $scope.pages = [];
|
38
|
|
- var start = Math.max(0, $scope.page - 5);
|
39
|
|
- var end = Math.min(start + 10, (items.Count / $scope.perPage) + (items.Count % $scope.perPage == 0 ? -1 : 0));
|
40
|
|
- for (var i = start; i < end; ++i) {
|
41
|
|
- $scope.pages.push(i);
|
42
|
|
- }
|
43
|
|
- }, function (error) {
|
44
|
|
- });
|
45
|
|
- };
|
46
|
|
-
|
47
|
|
- if ($scope.tableOptions.displayItem != null){
|
48
|
|
- $scope.displayItem = function(item)
|
|
18
|
+ if ($scope.tableOptions.onItemDeleted == null) {
|
|
19
|
+ $scope.tableOptions.onItemDeleted = function(item)
|
49
|
20
|
{
|
50
|
|
- return $scope.tableOptions.displayItem(item, $scope);
|
51
|
|
- };
|
|
21
|
+ }
|
52
|
22
|
}
|
53
|
|
- else {
|
54
|
|
- $scope.displayItem = function (item) {
|
55
|
|
- var ctrl = $scope.tableOptions.getEditController();
|
56
|
|
- dialogs.create('views/modals/' + ctrl.toLowerCase() + '.html', ctrl + 'Controller', item)
|
57
|
|
- .result.then(function (data) {
|
58
|
|
- $scope.loadPage($scope.page);
|
59
|
|
- });
|
60
|
|
- };
|
|
23
|
+ if ($scope.tableOptions.onItemEdited == null) {
|
|
24
|
+ $scope.tableOptions.onItemEdited = function(item)
|
|
25
|
+ {
|
|
26
|
+ }
|
61
|
27
|
}
|
|
28
|
+ if ($scope.tableOptions.onItemAdded == null) {
|
|
29
|
+ $scope.tableOptions.onItemAdded = function(item)
|
|
30
|
+ {
|
|
31
|
+ }
|
|
32
|
+ }
|
|
33
|
+ var onItemClicked = $scope.tableOptions.onItemClicked;
|
|
34
|
+ $scope.tableOptions.onItemClicked = function (item) {
|
|
35
|
+ if (onItemClicked != null) {
|
|
36
|
+ onItemClicked(item);
|
|
37
|
+ }
|
|
38
|
+ var ctrl = $scope.tableOptions.getEditController();
|
|
39
|
+ dialogs.create('views/modals/' + ctrl.toLowerCase() + '.html', ctrl + 'Controller', item)
|
|
40
|
+ .result.then(function (data) {
|
|
41
|
+ $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
|
|
42
|
+ $scope.tableOptions.onItemEdited(data);
|
|
43
|
+ });
|
|
44
|
+ };
|
|
45
|
+
|
62
|
46
|
|
63
|
|
- $scope.removeItems = function () {
|
64
|
|
- if ($scope.selectedItems.length == 0) {
|
65
|
|
- $scope.loadPage($scope.page);
|
|
47
|
+ $scope.tableOptions.canCheck = $scope.tableOptions.canDelete;
|
|
48
|
+ $scope.tableOptions.canClick = $scope.tableOptions.canEdit;
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+ $scope.deleteItems = function () {
|
|
52
|
+ if ($scope.tableOptions.checkedItems.length == 0) {
|
|
53
|
+ $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
|
66
|
54
|
return;
|
67
|
55
|
}
|
68
|
|
- $scope.tableOptions.getDelPromise($scope.selectedItems[0], promiseDelItems)
|
|
56
|
+ var promiseDelItems = {
|
|
57
|
+ id: "promiseDelItems",
|
|
58
|
+ loadGroups: [$scope.tableOptions.luBusy.group]
|
|
59
|
+ };
|
|
60
|
+ var item = $scope.tableOptions.checkedItems[0];
|
|
61
|
+ $scope.tableOptions.getDelPromise(item, promiseDelItems)
|
69
|
62
|
.then(function (data) {
|
70
|
|
- $scope.selectedItems.splice(0, 1);
|
71
|
|
- $scope.removeItems();
|
|
63
|
+ $scope.tableOptions.onItemDeleted(item, $scope);
|
|
64
|
+ $scope.tableOptions.checkedItems.splice(0, 1);
|
|
65
|
+ $scope.deleteItems();
|
72
|
66
|
}, function (error) {
|
73
|
67
|
luticateDialogErrorHelper.errorDialog(error)
|
74
|
68
|
.result.then(function (data) {
|
75
|
|
- $scope.loadPage($scope.page);
|
|
69
|
+ $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
|
76
|
70
|
}, function (error) {
|
77
|
71
|
});
|
78
|
72
|
});
|
|
@@ -82,46 +76,10 @@ angular.module('luticateUtils')
|
82
|
76
|
var ctrl = $scope.tableOptions.getEditController();
|
83
|
77
|
dialogs.create('views/modals/' + ctrl.toLowerCase() + '.html', ctrl + 'Controller', null)
|
84
|
78
|
.result.then(function (data) {
|
85
|
|
- $scope.loadPage($scope.page);
|
|
79
|
+ $scope.tableOptions.luBasicTableScope.loadPage($scope.tableOptions.page);
|
|
80
|
+ $scope.tableOptions.onItemAdded(data);
|
86
|
81
|
});
|
87
|
82
|
};
|
88
|
|
-
|
89
|
|
- $scope.toggleSelectedItem = function (item) {
|
90
|
|
- var id = $scope.tableOptions.getItemId(item);
|
91
|
|
- var idx = $scope.selectedItems.indexOf(id);
|
92
|
|
- if (idx > -1) {
|
93
|
|
- $scope.selectedItems.splice(idx, 1);
|
94
|
|
- }
|
95
|
|
- else {
|
96
|
|
- $scope.selectedItems.push(id);
|
97
|
|
- }
|
98
|
|
- };
|
99
|
|
-
|
100
|
|
- $scope.toggleSelectAll = function () {
|
101
|
|
- if ($scope.selectedItems.length == $scope.items.Data.length) {
|
102
|
|
- $scope.selectedItems = [];
|
103
|
|
- }
|
104
|
|
- else {
|
105
|
|
- $scope.selectedItems = [];
|
106
|
|
- for (var i = 0; i < $scope.items.Data.length; ++i) {
|
107
|
|
- $scope.selectedItems.push($scope.tableOptions.getItemId($scope.items.Data[i]));
|
108
|
|
- }
|
109
|
|
- }
|
110
|
|
- };
|
111
|
|
-
|
112
|
|
- $scope.isItemChecked = function(item)
|
113
|
|
- {
|
114
|
|
- return $scope.selectedItems.indexOf($scope.tableOptions.getItemId(item)) > -1;
|
115
|
|
- };
|
116
|
|
-
|
117
|
|
- if (!$scope.tableOptions.getItemId) {
|
118
|
|
- $scope.tableOptions.getItemId = function(item)
|
119
|
|
- {
|
120
|
|
- return item.Id;
|
121
|
|
- };
|
122
|
|
- }
|
123
|
|
-
|
124
|
|
- $scope.loadPage($scope.page);
|
125
|
83
|
}
|
126
|
84
|
};
|
127
|
85
|
}
|
|
@@ -129,40 +87,15 @@ angular.module('luticateUtils')
|
129
|
87
|
|
130
|
88
|
angular.module('luticateUtils').run(['$templateCache', function($templateCache)
|
131
|
89
|
{
|
132
|
|
- $templateCache.put('/luticate/lutable.html', '<div lu-busy="itemList">' +
|
133
|
|
-' <table class="col-sm-12 table table-hover">' +
|
134
|
|
-' <thead>' +
|
135
|
|
-' <tr>' +
|
136
|
|
-' <th lu-show-permission="{{ tableOptions.permissions.del }}">' +
|
137
|
|
-' <input type="checkbox" ng-click="toggleSelectAll()"' +
|
138
|
|
-' ng-checked="selectedItems.length == items.Data.length && items.Data.length != 0">' +
|
139
|
|
-' </th>' +
|
140
|
|
-' <th class="col-sm-{{ col.width }}" ng-repeat="col in tableOptions.columns">{{ col.name }}</th>' +
|
141
|
|
-'</tr>' +
|
142
|
|
-'</thead>' +
|
143
|
|
-'<tbody>' +
|
144
|
|
-'<tr ng-repeat="item in items.Data" style="cursor: pointer" ng-click="displayItem(item)">' +
|
145
|
|
-' <td lu-show-permission="{{ tableOptions.permissions.del }}">' +
|
146
|
|
-' <input name="selectedItems[]" type="checkbox" ng-checked="isItemChecked(item)"' +
|
147
|
|
- ' ng-click="$event.stopPropagation();toggleSelectedItem(item)" >' +
|
148
|
|
-' </td>' +
|
149
|
|
-' <td ng-repeat="col in tableOptions.columns">{{ col.getValue(item) }}</td>' +
|
150
|
|
-'</tr>' +
|
151
|
|
-'</tbody>' +
|
152
|
|
-'</table>' +
|
153
|
|
-
|
154
|
|
-'<div class="col-sm-12 text-center">' +
|
155
|
|
-' <a class="{{ p == page ? \'pagination-current\' : \'pagination-not-current\'}}" href="" ng-repeat="p in pages" ng-click="loadPage(p)">{{ p + 1 }} </a>' +
|
156
|
|
-'</div>' +
|
157
|
|
-
|
|
90
|
+ $templateCache.put('/luticate/lutable.html',
|
|
91
|
+' <lu-basic-table options="tableOptions"></lu-basic-table>' +
|
158
|
92
|
'<div class="col-sm-12">' +
|
159
|
|
-' <button class="btn btn-default" type="button" ng-click="removeItems()"' +
|
160
|
|
-'ng-disabled="selectedItems.length == 0" lu-show-permission="{{ tableOptions.permissions.del }}">' +
|
161
|
|
-' <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Remove' +
|
|
93
|
+' <button class="btn btn-default" type="button" ng-click="deleteItems()"' +
|
|
94
|
+'ng-disabled="tableOptions.checkedItems.length == 0" ng-show="tableOptions.canDelete()">' +
|
|
95
|
+' <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete' +
|
162
|
96
|
' </button>' +
|
163
|
|
-' <button class="btn btn-default" type="button" ng-click="addItem()" lu-show-permission="{{ tableOptions.permissions.add }}">' +
|
|
97
|
+' <button class="btn btn-default" type="button" ng-click="addItem()" ng-show="tableOptions.canAdd()">' +
|
164
|
98
|
' <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add' +
|
165
|
99
|
' </button>' +
|
166
|
|
-' </div>' +
|
167
|
100
|
' </div>');
|
168
|
101
|
}]);
|