/**
 * 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();
            }
        }
        
        $scope.edit=function(image){
            $rootScope.$broadcast("editImageEvent", image, Image.getData().axioms);
            
        }
    }]);
