|
19 | 19 |
|
20 | 20 |
|
21 | 21 | Upstream.setScope($scope, false, 'items', 'itemCount'); |
| 22 | + $scope.deleteItem = deleteItem |
| 23 | + $scope.deleteChecked = deleteChecked |
22 | 24 |
|
23 | 25 | // Add default list configuration variable to current scope |
24 | 26 | $scope = angular.extend($scope, angular.copy(ListConfig.getConfig())); |
|
115 | 117 | }); |
116 | 118 | } |
117 | 119 |
|
| 120 | + function deleteChecked() { |
| 121 | + |
| 122 | + var items = [] |
| 123 | + $scope.items.forEach(function(item){ |
| 124 | + if(item.checked) items.push(item) |
| 125 | + }) |
| 126 | + |
| 127 | + if(!items.length) { |
| 128 | + MessageService.error('You have not selected any upstreams to delete') |
| 129 | + return false |
| 130 | + } |
| 131 | + |
| 132 | + DialogService.prompt( |
| 133 | + "Delete Upstreams","Really want to delete the selected upstreams?", |
| 134 | + ['No don\'t','Yes! delete them'], |
| 135 | + function accept(){ |
| 136 | + deleteItems(items) |
| 137 | + },function decline(){}) |
| 138 | + |
| 139 | + } |
| 140 | + |
| 141 | + function deleteItems(items) { |
| 142 | + |
| 143 | + $scope.deleting = true; |
| 144 | + var promises = [] |
| 145 | + items.forEach(function(item){ |
| 146 | + promises.push(Upstream.delete(item.id)) |
| 147 | + }) |
| 148 | + |
| 149 | + $q |
| 150 | + .all(promises) |
| 151 | + .finally( |
| 152 | + function onFinally() { |
| 153 | + $scope.deleting = false; |
| 154 | + _fetchData() |
| 155 | + } |
| 156 | + ) |
| 157 | + ; |
| 158 | + } |
| 159 | + |
118 | 160 |
|
119 | 161 | // Listeners |
120 | 162 | $scope.$on('kong.upstream.created',function(ev,data){ |
121 | 163 | _fetchData() |
122 | 164 | }) |
123 | 165 |
|
124 | | - $scope.deleteItem = function(item) { |
| 166 | + |
| 167 | + |
| 168 | + function deleteItem(item) { |
125 | 169 | DialogService.prompt( |
126 | 170 | "Delete Upstream","Really want to delete the selected upstream?", |
127 | 171 | ['No don\'t','Yes! delete it'], |
|
0 commit comments