client/app/slideshow/slideshow_controller.js
changeset 39 b714bcbe915c
parent 14 4d27fbc3f9df
child 56 e38e9d5114ad
equal deleted inserted replaced
38:96a7d3e4d073 39:b714bcbe915c
     7         .when('/', {
     7         .when('/', {
     8           templateUrl: 'slideshow/slideshow.html',
     8           templateUrl: 'slideshow/slideshow.html',
     9           controller: 'slideshowCtrl'
     9           controller: 'slideshowCtrl'
    10         });
    10         });
    11     })
    11     })
    12     .service('slideshowModel', function(searchApi) {
    12     .controller('slideshowCtrl', function($scope, searchApi){
    13       this.slideshow = searchApi.searchResource({q:'stop_email=toto@gmail.com', of: 'json', synthesis: 'false', nresults:'50', callback: 'JSON_CALLBACK'}).getJsonp();
    13     	$scope.slideshow = searchApi.booksSlides.query({idBook:'12', format:'json'}, function(data){
    14     })
    14     		data = searchApi.sanitizeUrls(data);
    15     .controller('slideshowCtrl', function($scope, $filter, $location, $routeParams, $timeout, searchApi, slideshowModel){
    15     	});
    16       $scope.slideshow = slideshowModel.slideshow;
    16     	$scope.book = searchApi.book.get({idBook:'12', format:'json'});
    17       
    17     	$scope.showSlide = function(index){
    18       $scope.iSlide = parseInt($routeParams.iSlide) || 0;
    18     		console.log(index);
    19       if(typeof $routeParams.searched !== 'undefined'){
    19     	};
    20           var a = $routeParams.searched.split(',');
    20     });
    21           var q = a[0], i = parseInt(a[1]);
       
    22           if(a.length===2 && !isNaN(i)){
       
    23               searchApi.searchResource({q:q, of: 'json', synthesis: 'false', nresults:'50', callback: 'JSON_CALLBACK'}).getJsonp().$promise.then(
       
    24                   //success
       
    25                   function( data ){
       
    26                       $scope.slideshow.hits.push(data.hits[i]);
       
    27                       // timeout because
       
    28                       $timeout(function(){$scope.slideshow.hits[$scope.slideshow.hits.length-1].active = true;}, 500);
       
    29                   },
       
    30                   //error
       
    31                   function( error ){
       
    32                       alert('Erreur avec la requĂȘte (dans slideshow)', error);
       
    33                   }
       
    34               );
       
    35           }
       
    36       }
       
    37       $timeout(function(){
       
    38           if($scope.iSlide>=0 && $scope.iSlide<$scope.slideshow.hits.length){
       
    39               $scope.slideshow.hits[$scope.iSlide].active = true;
       
    40               var l = $location.path();
       
    41               if(l.substr(0,16)==='/slideshow/edit/'){
       
    42                   $scope.slideshow.hits[$scope.iSlide].editMode = true;
       
    43               }
       
    44           }
       
    45       }, 500);
       
    46       
       
    47       $scope.save = function(){
       
    48           $scope.slideshow
       
    49           .$save()
       
    50           .then(
       
    51               function(response) {
       
    52                   console.log('NICE SAVING!', response);
       
    53               },
       
    54               function(reason){
       
    55                   alert('An error occured while saving : ' + reason);
       
    56               }
       
    57           );
       
    58       };
       
    59     })
       
    60     .directive('slideEditor', function() {
       
    61       return {
       
    62           restrict: 'AE',
       
    63           replace: true,
       
    64           scope: false,
       
    65           templateUrl: 'slideshow/dataEditor.html',
       
    66           //controller: function($scope, $element, $attrs){
       
    67           controller: function($scope){
       
    68               $scope.slidesave = function(){
       
    69                   if(typeof $scope.slide.tags === 'string'){
       
    70                       $scope.slide.tags = $scope.slide.tags.split(',');
       
    71                   }
       
    72                   for (var i = $scope.slide.tags.length - 1; i >= 0; i--) {
       
    73                       $scope.slide.tags[i] = $scope.slide.tags[i].trim();
       
    74                   }
       
    75                   $scope.slide.editMode = false;
       
    76                   $scope.save();
       
    77               };
       
    78               $scope.editSlidesave = function(){
       
    79                   if(typeof $scope.slide.tags === 'string'){
       
    80                       $scope.slide.tags = $scope.slide.tags.split(',');
       
    81                   }
       
    82                   for (var i = $scope.slide.tags.length - 1; i >= 0; i--) {
       
    83                       $scope.slide.tags[i] = $scope.slide.tags[i].trim();
       
    84                   }
       
    85                   $scope.slide.editMode = false;
       
    86                   $scope.save();
       
    87               };
       
    88           }
       
    89       };
       
    90   });
       
    91 
       
    92 })();
    21 })();