2016-06-02 05:34:03 +00:00
|
|
|
angular.module('networks', [])
|
2017-09-19 14:58:30 +00:00
|
|
|
.controller('NetworksController', ['$scope', '$state', 'Network', 'NetworkService', 'Notifications', 'Pagination',
|
|
|
|
function ($scope, $state, Network, NetworkService, Notifications, Pagination) {
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.state = {};
|
2017-01-24 01:28:40 +00:00
|
|
|
$scope.state.pagination_count = Pagination.getPaginationCount('networks');
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.state.selectedItemCount = 0;
|
2016-07-08 05:26:18 +00:00
|
|
|
$scope.state.advancedSettings = false;
|
2016-08-17 05:25:42 +00:00
|
|
|
$scope.sortType = 'Name';
|
2016-07-06 07:04:45 +00:00
|
|
|
$scope.sortReverse = false;
|
2016-09-14 04:28:38 +00:00
|
|
|
|
2017-01-24 01:28:40 +00:00
|
|
|
$scope.changePaginationCount = function() {
|
|
|
|
Pagination.setPaginationCount('networks', $scope.state.pagination_count);
|
|
|
|
};
|
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.order = function(sortType) {
|
|
|
|
$scope.sortReverse = ($scope.sortType === sortType) ? !$scope.sortReverse : false;
|
|
|
|
$scope.sortType = sortType;
|
|
|
|
};
|
2015-12-18 05:35:04 +00:00
|
|
|
|
2017-01-04 20:15:41 +00:00
|
|
|
$scope.selectItems = function(allSelected) {
|
|
|
|
angular.forEach($scope.state.filteredNetworks, function (network) {
|
|
|
|
if (network.Checked !== allSelected) {
|
|
|
|
network.Checked = allSelected;
|
|
|
|
$scope.selectItem(network);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.selectItem = function (item) {
|
|
|
|
if (item.Checked) {
|
|
|
|
$scope.state.selectedItemCount++;
|
|
|
|
} else {
|
|
|
|
$scope.state.selectedItemCount--;
|
|
|
|
}
|
|
|
|
};
|
2015-12-18 05:35:04 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.removeAction = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadNetworksSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
var counter = 0;
|
|
|
|
var complete = function () {
|
|
|
|
counter = counter - 1;
|
|
|
|
if (counter === 0) {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadNetworksSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
angular.forEach($scope.networks, function (network) {
|
|
|
|
if (network.Checked) {
|
|
|
|
counter = counter + 1;
|
|
|
|
Network.remove({id: network.Id}, function (d) {
|
2016-09-01 00:20:19 +00:00
|
|
|
if (d.message) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Error', d, 'Unable to remove network');
|
2016-07-27 05:36:22 +00:00
|
|
|
} else {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.success('Network removed', network.Id);
|
2016-07-27 05:36:22 +00:00
|
|
|
var index = $scope.networks.indexOf(network);
|
|
|
|
$scope.networks.splice(index, 1);
|
|
|
|
}
|
2016-06-02 05:34:03 +00:00
|
|
|
complete();
|
|
|
|
}, function (e) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', e, 'Unable to remove network');
|
2016-06-02 05:34:03 +00:00
|
|
|
complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2015-12-21 02:07:57 +00:00
|
|
|
|
2017-06-01 08:14:55 +00:00
|
|
|
function initView() {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadNetworksSpinner').show();
|
2017-09-19 14:58:30 +00:00
|
|
|
|
|
|
|
NetworkService.networks(true, true, true, true)
|
|
|
|
.then(function success(data) {
|
|
|
|
$scope.networks = data;
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2016-10-08 01:59:58 +00:00
|
|
|
$scope.networks = [];
|
2017-09-19 14:58:30 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve networks');
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
$('#loadNetworksSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
}
|
2016-08-10 06:20:18 +00:00
|
|
|
|
2017-06-01 08:14:55 +00:00
|
|
|
initView();
|
2016-06-02 05:34:03 +00:00
|
|
|
}]);
|