|
0
|
1 |
(function(){ |
|
|
2 |
'use strict'; |
|
|
3 |
|
|
|
4 |
angular.module('ammicoSlideshow',['ngResource', 'ngRoute', 'ui.bootstrap']) |
|
|
5 |
.config(function ($routeProvider) { |
|
|
6 |
$routeProvider |
|
|
7 |
.when('/', { |
|
|
8 |
templateUrl: 'slideshow/slideshow.html', |
|
|
9 |
controller: 'slideshowCtrl' |
|
|
10 |
}); |
|
|
11 |
}) |
|
|
12 |
.service('slideshowApi', function($resource, context) { |
|
2
|
13 |
console.log('slideshow 5',this); |
|
1
|
14 |
this.slideshow = $resource(context.urls.slideshowUrl); |
|
0
|
15 |
}) |
|
|
16 |
.service('slideshowModel', function(slideshowApi, context) { |
|
2
|
17 |
console.log('slideshow 6',this); |
|
0
|
18 |
if(typeof context.slideshow === 'undefined') { |
|
2
|
19 |
console.log('slideshow 6-1'); |
|
0
|
20 |
this.slideshow = slideshowApi.slideshow.get(); |
|
|
21 |
} |
|
|
22 |
else { |
|
2
|
23 |
console.log('slideshow 6-2'); |
|
0
|
24 |
this.slideshow = new slideshowApi.slideshow(context.slideshow); |
|
|
25 |
} |
|
|
26 |
}) |
|
2
|
27 |
.controller('slideshowCtrl', function($scope, $filter, $location, $routeParams, $timeout, searchApi, slideshowModel){ |
|
|
28 |
console.log('slideshow 7', $filter, $routeParams, searchApi, slideshowModel); |
|
0
|
29 |
$scope.slideshow = slideshowModel.slideshow; |
|
1
|
30 |
$scope.iSlide = parseInt($routeParams.iSlide) || 0; |
|
2
|
31 |
if(typeof $routeParams.searched !== 'undefined'){ |
|
|
32 |
var a = $routeParams.searched.split(','); |
|
|
33 |
var q = a[0], i = parseInt(a[1]); |
|
|
34 |
if(a.length===2 && !isNaN(i)){ |
|
|
35 |
searchApi.searchResource({q:q, of: 'json', synthesis: 'false', nresults:'50', callback: 'JSON_CALLBACK'}).$promise.then( |
|
|
36 |
//success |
|
|
37 |
function( data ){ |
|
|
38 |
var hit = data.hits[i]; |
|
|
39 |
$scope.slideshow.images.push({url: $filter('meta')(hit.metas, 'url'), |
|
|
40 |
title: $filter('meta')(hit.metas, 'name'), |
|
|
41 |
description: $filter('meta')(hit.metas, 'description'), tags: [], user_title:'', user_description:''}); |
|
|
42 |
// timeout because |
|
|
43 |
$timeout(function(){$scope.slideshow.images[$scope.slideshow.images.length-1].active = true;}, 200); |
|
|
44 |
}, |
|
|
45 |
//error |
|
|
46 |
function( error ){ |
|
|
47 |
alert('Erreur avec la requĂȘte (dans slideshow)', error); |
|
|
48 |
} |
|
|
49 |
); |
|
|
50 |
} |
|
|
51 |
} |
|
0
|
52 |
|
|
|
53 |
$scope.save = function(){ |
|
1
|
54 |
console.log('8 call save POST',$scope.slideshow); |
|
|
55 |
$scope.slideshow |
|
0
|
56 |
.$save() |
|
|
57 |
.then( |
|
|
58 |
function(response) { |
|
|
59 |
console.log('NICE SAVING!', response); |
|
|
60 |
}, |
|
|
61 |
function(reason){ |
|
|
62 |
alert('An error occured while saving : ' + reason); |
|
|
63 |
} |
|
|
64 |
); |
|
|
65 |
}; |
|
|
66 |
}) |
|
|
67 |
.directive('slideEditor', function() { |
|
|
68 |
return { |
|
|
69 |
restrict: 'AE', |
|
|
70 |
replace: true, |
|
|
71 |
scope: false, |
|
|
72 |
templateUrl: 'slideshow/dataEditor.html', |
|
|
73 |
//controller: function($scope, $element, $attrs){ |
|
|
74 |
controller: function($scope){ |
|
|
75 |
$scope.slidesave = function(){ |
|
|
76 |
if(typeof $scope.slide.tags === 'string'){ |
|
|
77 |
$scope.slide.tags = $scope.slide.tags.split(','); |
|
|
78 |
} |
|
|
79 |
for (var i = $scope.slide.tags.length - 1; i >= 0; i--) { |
|
|
80 |
$scope.slide.tags[i] = $scope.slide.tags[i].trim(); |
|
|
81 |
} |
|
|
82 |
$scope.editMode = false; |
|
|
83 |
$scope.save(); |
|
|
84 |
}; |
|
|
85 |
} |
|
|
86 |
}; |
|
|
87 |
}); |
|
|
88 |
|
|
|
89 |
})(); |