2016-06-02 05:34:03 +00:00
|
|
|
angular.module('volumes', [])
|
2017-01-24 01:28:40 +00:00
|
|
|
.controller('VolumesController', ['$scope', '$state', 'Volume', 'Messages', 'Pagination',
|
|
|
|
function ($scope, $state, Volume, Messages, 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('volumes');
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.state.selectedItemCount = 0;
|
2016-08-17 05:25:42 +00:00
|
|
|
$scope.sortType = 'Name';
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.sortReverse = true;
|
2016-07-06 07:04:45 +00:00
|
|
|
$scope.config = {
|
|
|
|
Name: ''
|
|
|
|
};
|
2017-01-24 01:28:40 +00:00
|
|
|
|
|
|
|
$scope.changePaginationCount = function() {
|
|
|
|
Pagination.setPaginationCount('volumes', $scope.state.pagination_count);
|
|
|
|
};
|
2016-07-06 07:04:45 +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-21 03:17:01 +00:00
|
|
|
|
2017-01-04 20:15:41 +00:00
|
|
|
$scope.selectItems = function (allSelected) {
|
|
|
|
angular.forEach($scope.state.filteredVolumes, function (volume) {
|
|
|
|
if (volume.Checked !== allSelected) {
|
|
|
|
volume.Checked = allSelected;
|
|
|
|
$scope.selectItem(volume);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.selectItem = function (item) {
|
|
|
|
if (item.Checked) {
|
|
|
|
$scope.state.selectedItemCount++;
|
|
|
|
} else {
|
|
|
|
$scope.state.selectedItemCount--;
|
|
|
|
}
|
|
|
|
};
|
2015-12-21 03:17:01 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.removeAction = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadVolumesSpinner').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
|
|
|
$('#loadVolumesSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
angular.forEach($scope.volumes, function (volume) {
|
|
|
|
if (volume.Checked) {
|
|
|
|
counter = counter + 1;
|
|
|
|
Volume.remove({name: volume.Name}, function (d) {
|
2016-09-07 06:21:46 +00:00
|
|
|
if (d.message) {
|
|
|
|
Messages.error("Unable to remove volume", {}, d.message);
|
|
|
|
} else {
|
|
|
|
Messages.send("Volume deleted", volume.Name);
|
|
|
|
var index = $scope.volumes.indexOf(volume);
|
|
|
|
$scope.volumes.splice(index, 1);
|
|
|
|
}
|
2016-06-02 05:34:03 +00:00
|
|
|
complete();
|
|
|
|
}, function (e) {
|
2016-09-02 05:51:41 +00:00
|
|
|
Messages.error("Failure", e, "Unable to remove volume");
|
2016-06-02 05:34:03 +00:00
|
|
|
complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2015-12-21 03:17:01 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
function fetchVolumes() {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadVolumesSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Volume.query({}, function (d) {
|
2016-11-25 06:16:28 +00:00
|
|
|
$scope.volumes = d.Volumes || [];
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadVolumesSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadVolumesSpinner').hide();
|
2016-09-02 05:51:41 +00:00
|
|
|
Messages.error("Failure", e, "Unable to retrieve volumes");
|
2016-10-08 01:59:58 +00:00
|
|
|
$scope.volumes = [];
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
fetchVolumes();
|
|
|
|
}]);
|