|
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 |
}) |
|
4
|
16 |
.service('slideshowModel', function(slideshowApi) { |
|
2
|
17 |
console.log('slideshow 6',this); |
|
4
|
18 |
this.slideshow = slideshowApi.slideshow.get(); |
|
0
|
19 |
}) |
|
2
|
20 |
.controller('slideshowCtrl', function($scope, $filter, $location, $routeParams, $timeout, searchApi, slideshowModel){ |
|
4
|
21 |
console.log('slideshow 7', $location, $routeParams, searchApi, slideshowModel); |
|
0
|
22 |
$scope.slideshow = slideshowModel.slideshow; |
|
1
|
23 |
$scope.iSlide = parseInt($routeParams.iSlide) || 0; |
|
4
|
24 |
console.log('$routeParams',$routeParams); |
|
2
|
25 |
if(typeof $routeParams.searched !== 'undefined'){ |
|
|
26 |
var a = $routeParams.searched.split(','); |
|
|
27 |
var q = a[0], i = parseInt(a[1]); |
|
|
28 |
if(a.length===2 && !isNaN(i)){ |
|
|
29 |
searchApi.searchResource({q:q, of: 'json', synthesis: 'false', nresults:'50', callback: 'JSON_CALLBACK'}).$promise.then( |
|
|
30 |
//success |
|
|
31 |
function( data ){ |
|
|
32 |
var hit = data.hits[i]; |
|
|
33 |
$scope.slideshow.images.push({url: $filter('meta')(hit.metas, 'url'), |
|
|
34 |
title: $filter('meta')(hit.metas, 'name'), |
|
|
35 |
description: $filter('meta')(hit.metas, 'description'), tags: [], user_title:'', user_description:''}); |
|
|
36 |
// timeout because |
|
|
37 |
$timeout(function(){$scope.slideshow.images[$scope.slideshow.images.length-1].active = true;}, 200); |
|
|
38 |
}, |
|
|
39 |
//error |
|
|
40 |
function( error ){ |
|
|
41 |
alert('Erreur avec la requĂȘte (dans slideshow)', error); |
|
|
42 |
} |
|
|
43 |
); |
|
|
44 |
} |
|
|
45 |
} |
|
4
|
46 |
$timeout(function(){ |
|
|
47 |
if($scope.iSlide>=0 && $scope.iSlide<$scope.slideshow.images.length){ |
|
|
48 |
$scope.slideshow.images[$scope.iSlide].active = true; |
|
|
49 |
var l = $location.path(); |
|
|
50 |
if(l.substr(0,16)==='/slideshow/edit/'){ |
|
|
51 |
$scope.slideshow.images[$scope.iSlide].editMode = true; |
|
|
52 |
} |
|
|
53 |
} |
|
|
54 |
}, 200); |
|
0
|
55 |
|
|
|
56 |
$scope.save = function(){ |
|
1
|
57 |
console.log('8 call save POST',$scope.slideshow); |
|
|
58 |
$scope.slideshow |
|
0
|
59 |
.$save() |
|
|
60 |
.then( |
|
|
61 |
function(response) { |
|
|
62 |
console.log('NICE SAVING!', response); |
|
|
63 |
}, |
|
|
64 |
function(reason){ |
|
|
65 |
alert('An error occured while saving : ' + reason); |
|
|
66 |
} |
|
|
67 |
); |
|
|
68 |
}; |
|
|
69 |
}) |
|
|
70 |
.directive('slideEditor', function() { |
|
|
71 |
return { |
|
|
72 |
restrict: 'AE', |
|
|
73 |
replace: true, |
|
|
74 |
scope: false, |
|
|
75 |
templateUrl: 'slideshow/dataEditor.html', |
|
|
76 |
//controller: function($scope, $element, $attrs){ |
|
|
77 |
controller: function($scope){ |
|
|
78 |
$scope.slidesave = 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 |
} |
|
4
|
85 |
$scope.slide.editMode = false; |
|
|
86 |
$scope.save(); |
|
|
87 |
}; |
|
|
88 |
$scope.editSlidesave = function(){ |
|
|
89 |
if(typeof $scope.slide.tags === 'string'){ |
|
|
90 |
$scope.slide.tags = $scope.slide.tags.split(','); |
|
|
91 |
} |
|
|
92 |
for (var i = $scope.slide.tags.length - 1; i >= 0; i--) { |
|
|
93 |
$scope.slide.tags[i] = $scope.slide.tags[i].trim(); |
|
|
94 |
} |
|
|
95 |
$scope.slide.editMode = false; |
|
0
|
96 |
$scope.save(); |
|
|
97 |
}; |
|
|
98 |
} |
|
|
99 |
}; |
|
|
100 |
}); |
|
|
101 |
|
|
|
102 |
})(); |