2016-06-02 05:34:03 +00:00
|
|
|
angular.module('networks', [])
|
|
|
|
.controller('NetworksController', ['$scope', 'Network', 'ViewSpinner', 'Messages', 'errorMsgFilter',
|
|
|
|
function ($scope, Network, ViewSpinner, Messages, errorMsgFilter) {
|
2015-12-21 02:07:57 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.state = {};
|
|
|
|
$scope.state.toggle = false;
|
|
|
|
$scope.state.selectedItemCount = 0;
|
|
|
|
$scope.sortType = 'Name';
|
|
|
|
$scope.sortReverse = true;
|
2015-12-21 02:07:57 +00:00
|
|
|
|
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
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.toggleSelectAll = function () {
|
|
|
|
angular.forEach($scope.state.filteredNetworks, function (i) {
|
|
|
|
i.Checked = $scope.state.toggle;
|
|
|
|
});
|
|
|
|
if ($scope.state.toggle) {
|
|
|
|
$scope.state.selectedItemCount = $scope.state.filteredNetworks.length;
|
|
|
|
} else {
|
|
|
|
$scope.state.selectedItemCount = 0;
|
|
|
|
}
|
|
|
|
};
|
2015-12-18 05:35:04 +00:00
|
|
|
|
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 () {
|
|
|
|
ViewSpinner.spin();
|
|
|
|
var counter = 0;
|
|
|
|
var complete = function () {
|
|
|
|
counter = counter - 1;
|
|
|
|
if (counter === 0) {
|
|
|
|
ViewSpinner.stop();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
angular.forEach($scope.networks, function (network) {
|
|
|
|
if (network.Checked) {
|
|
|
|
counter = counter + 1;
|
|
|
|
Network.remove({id: network.Id}, function (d) {
|
|
|
|
Messages.send("Network deleted", network.Id);
|
|
|
|
var index = $scope.networks.indexOf(network);
|
|
|
|
$scope.networks.splice(index, 1);
|
|
|
|
complete();
|
|
|
|
}, function (e) {
|
|
|
|
Messages.error("Failure", e.data);
|
|
|
|
complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2015-12-21 02:07:57 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
function fetchNetworks() {
|
|
|
|
ViewSpinner.spin();
|
|
|
|
Network.query({}, function (d) {
|
|
|
|
$scope.networks = d;
|
|
|
|
ViewSpinner.stop();
|
|
|
|
}, function (e) {
|
|
|
|
Messages.error("Failure", e.data);
|
|
|
|
ViewSpinner.stop();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
fetchNetworks();
|
|
|
|
}]);
|