(function(){
    'use strict';

    angular.module('ammicoSlides',['ngResource', 'ngRoute'])
    .controller('slidesCtrl', function($scope, $routeParams, Slide, Utils){
        
        $scope.slide = Slide.get({idSlide:$routeParams.idSlide, format:'json'}, function(data){
            data = Utils.sanitizeUrls(data);
        });

    })
    .directive('slideEditor', function() {
        return {
            restrict: 'AE',
            replace: true,
            scope: false,
            templateUrl: 'slides/data_editor.html',
            controller: function($scope){
                $scope.slidesave = function(){
                    if(typeof $scope.slide.tags === 'string'){
                        $scope.slide.tags = $scope.slide.tags.split(',');
                        for (var i = $scope.slide.tags.length - 1; i >= 0; i--) {
                            $scope.slide.tags[i] = $scope.slide.tags[i].trim();
                        }
                    }
                    $scope.slide.editMode = false;
                    $scope.slide.$update({format:'json'});
                };
                $scope.doubleClick = function(){
                    $scope.slide.editMode = true;
                };
            }
        };
    });

})();
