istic-openstack/client/js/controllers/image/image.js
2016-05-06 14:24:15 +02:00

50 lines
1.4 KiB
JavaScript
Executable file

/**
* The image controller
*
* @param {$scope} $scope The $scope service from angular
*/
mainApp.controller('imageCtrl', ['$scope', 'Image', 'Loading', 'Identity', '$rootScope', function ($scope, Image, Loading, Identity, $rootScope)
{
// Update view
var callMeAfterGetImage = function () {
$scope.images = Image.getData().images;
Loading.stop();
};
// If user is login try to retrieve data
if (Identity.isAlreadyLogin()) {
if (Image.getData().images == null) {
Loading.start();
Image.getImages(callMeAfterGetImage);
} else {
callMeAfterGetImage();
}
}
// Manager logout event
$scope.$on('updateImageEvent', function () {
// If user is login try to retrieve data
if (Identity.isAlreadyLogin()) {
Loading.start();
Image.getImages(callMeAfterGetImage);
}
});
$scope.edit = function (image) {
$rootScope.$broadcast("editImageEvent", image, Image.getData().axioms);
}
$scope.showCreateImageModal = function () {
$rootScope.$broadcast("showCreateImageModalEvent");
};
$scope.deleteImage = function (id) {
Image.deleteImage(id, function () {
$rootScope.$broadcast("updateImageEvent");
})
}
}]);