| author | rougeronj |
| Tue, 17 Mar 2015 16:34:23 +0100 | |
| changeset 14 | 4d27fbc3f9df |
| parent 9 | 962604899225 |
| child 39 | b714bcbe915c |
| permissions | -rw-r--r-- |
| 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 |
}) |
|
|
8
824c87a9084c
(really) better management of slideshowModel with new api.
cavaliet
parents:
4
diff
changeset
|
12 |
.service('slideshowModel', function(searchApi) { |
|
824c87a9084c
(really) better management of slideshowModel with new api.
cavaliet
parents:
4
diff
changeset
|
13 |
this.slideshow = searchApi.searchResource({q:'stop_email=toto@gmail.com', of: 'json', synthesis: 'false', nresults:'50', callback: 'JSON_CALLBACK'}).getJsonp(); |
| 0 | 14 |
}) |
| 2 | 15 |
.controller('slideshowCtrl', function($scope, $filter, $location, $routeParams, $timeout, searchApi, slideshowModel){ |
| 0 | 16 |
$scope.slideshow = slideshowModel.slideshow; |
|
8
824c87a9084c
(really) better management of slideshowModel with new api.
cavaliet
parents:
4
diff
changeset
|
17 |
|
| 1 | 18 |
$scope.iSlide = parseInt($routeParams.iSlide) || 0; |
| 2 | 19 |
if(typeof $routeParams.searched !== 'undefined'){ |
20 |
var a = $routeParams.searched.split(','); |
|
21 |
var q = a[0], i = parseInt(a[1]); |
|
22 |
if(a.length===2 && !isNaN(i)){ |
|
| 9 | 23 |
searchApi.searchResource({q:q, of: 'json', synthesis: 'false', nresults:'50', callback: 'JSON_CALLBACK'}).getJsonp().$promise.then( |
| 2 | 24 |
//success |
25 |
function( data ){ |
|
| 9 | 26 |
$scope.slideshow.hits.push(data.hits[i]); |
| 2 | 27 |
// timeout because |
| 9 | 28 |
$timeout(function(){$scope.slideshow.hits[$scope.slideshow.hits.length-1].active = true;}, 500); |
| 2 | 29 |
}, |
30 |
//error |
|
31 |
function( error ){ |
|
32 |
alert('Erreur avec la requĂȘte (dans slideshow)', error); |
|
33 |
} |
|
34 |
); |
|
35 |
} |
|
36 |
} |
|
| 4 | 37 |
$timeout(function(){ |
|
8
824c87a9084c
(really) better management of slideshowModel with new api.
cavaliet
parents:
4
diff
changeset
|
38 |
if($scope.iSlide>=0 && $scope.iSlide<$scope.slideshow.hits.length){ |
|
824c87a9084c
(really) better management of slideshowModel with new api.
cavaliet
parents:
4
diff
changeset
|
39 |
$scope.slideshow.hits[$scope.iSlide].active = true; |
| 4 | 40 |
var l = $location.path(); |
41 |
if(l.substr(0,16)==='/slideshow/edit/'){ |
|
|
8
824c87a9084c
(really) better management of slideshowModel with new api.
cavaliet
parents:
4
diff
changeset
|
42 |
$scope.slideshow.hits[$scope.iSlide].editMode = true; |
| 4 | 43 |
} |
44 |
} |
|
|
8
824c87a9084c
(really) better management of slideshowModel with new api.
cavaliet
parents:
4
diff
changeset
|
45 |
}, 500); |
|
824c87a9084c
(really) better management of slideshowModel with new api.
cavaliet
parents:
4
diff
changeset
|
46 |
|
| 0 | 47 |
$scope.save = function(){ |
| 1 | 48 |
$scope.slideshow |
| 0 | 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 |
} |
|
| 4 | 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; |
|
| 0 | 86 |
$scope.save(); |
87 |
}; |
|
88 |
} |
|
89 |
}; |
|
90 |
}); |
|
91 |
||
92 |
})(); |