| author | rougeronj |
| Fri, 03 Apr 2015 10:41:27 +0200 | |
| changeset 58 | e71b49ff4a23 |
| parent 57 | 388b29d38b44 |
| child 65 | 8116c2b28414 |
| permissions | -rw-r--r-- |
| 24 | 1 |
(function(){ |
2 |
'use strict'; |
|
3 |
||
|
49
88cd0bb61c12
add ui-sortble lib to be able to sort the list of the slide in the book view - it sends a post request to the server to update the slides' order
rougeronj
parents:
42
diff
changeset
|
4 |
angular.module('ammicoBooks',['ngRoute', 'ui.sortable']) |
|
57
388b29d38b44
add authentication and controle of authentication before routing
rougeronj
parents:
55
diff
changeset
|
5 |
.controller('booksCtrl', function($scope, $location, $modal, ammicoApi){ |
| 55 | 6 |
$scope.books = ammicoApi.listBooks.query({format:'json'}); |
| 24 | 7 |
$scope.searchSubmit = function(){ |
8 |
$location.path('/search/' + $scope.q); |
|
9 |
}; |
|
| 53 | 10 |
|
11 |
$scope.addBook = function () { |
|
12 |
$modal.open({ |
|
13 |
templateUrl: 'books/add_modal.html', |
|
14 |
controller: 'ModalAddBookCtrl' |
|
15 |
}); |
|
16 |
}; |
|
| 24 | 17 |
}) |
| 55 | 18 |
.controller('bookCtrl', function($scope, ammicoApi, $routeParams) { |
19 |
$scope.slides = ammicoApi.booksSlides.query({idBook:$routeParams.idBook, format:'json'}); |
|
|
49
88cd0bb61c12
add ui-sortble lib to be able to sort the list of the slide in the book view - it sends a post request to the server to update the slides' order
rougeronj
parents:
42
diff
changeset
|
20 |
$scope.slides.sort(function (a, b) { |
|
88cd0bb61c12
add ui-sortble lib to be able to sort the list of the slide in the book view - it sends a post request to the server to update the slides' order
rougeronj
parents:
42
diff
changeset
|
21 |
return a.orderIndex > b.orderIndex; |
|
88cd0bb61c12
add ui-sortble lib to be able to sort the list of the slide in the book view - it sends a post request to the server to update the slides' order
rougeronj
parents:
42
diff
changeset
|
22 |
}); |
|
88cd0bb61c12
add ui-sortble lib to be able to sort the list of the slide in the book view - it sends a post request to the server to update the slides' order
rougeronj
parents:
42
diff
changeset
|
23 |
$scope.sortableOptions = { |
|
88cd0bb61c12
add ui-sortble lib to be able to sort the list of the slide in the book view - it sends a post request to the server to update the slides' order
rougeronj
parents:
42
diff
changeset
|
24 |
stop: function() { |
|
88cd0bb61c12
add ui-sortble lib to be able to sort the list of the slide in the book view - it sends a post request to the server to update the slides' order
rougeronj
parents:
42
diff
changeset
|
25 |
var order = $scope.slides.map(function(i){ |
|
88cd0bb61c12
add ui-sortble lib to be able to sort the list of the slide in the book view - it sends a post request to the server to update the slides' order
rougeronj
parents:
42
diff
changeset
|
26 |
return i.id; |
|
88cd0bb61c12
add ui-sortble lib to be able to sort the list of the slide in the book view - it sends a post request to the server to update the slides' order
rougeronj
parents:
42
diff
changeset
|
27 |
}); |
| 55 | 28 |
ammicoApi.order.save({idBook:$routeParams.idBook}, {order: order}); |
|
49
88cd0bb61c12
add ui-sortble lib to be able to sort the list of the slide in the book view - it sends a post request to the server to update the slides' order
rougeronj
parents:
42
diff
changeset
|
29 |
} |
|
88cd0bb61c12
add ui-sortble lib to be able to sort the list of the slide in the book view - it sends a post request to the server to update the slides' order
rougeronj
parents:
42
diff
changeset
|
30 |
}; |
|
88cd0bb61c12
add ui-sortble lib to be able to sort the list of the slide in the book view - it sends a post request to the server to update the slides' order
rougeronj
parents:
42
diff
changeset
|
31 |
|
| 24 | 32 |
$scope.deleteItem = function(i){ |
33 |
if(0<=i && i<$scope.slides.length){ |
|
34 |
if(window.confirm('Êtes-vous sûr(e) de vouloir effacer cet élément ? Cette action est irrémédiable.')){ |
|
| 55 | 35 |
ammicoApi.slide.delete({idSlide: $scope.slides[i].id}, function(){ |
|
42
edbfef527c66
remove unused success callback - remove unused css
rougeronj
parents:
32
diff
changeset
|
36 |
$scope.slides.splice(i, 1); |
|
32
802ba9793507
add delete request to delete a slide - rename some .ressources fonctions
rougeronj
parents:
24
diff
changeset
|
37 |
}); |
| 24 | 38 |
} |
39 |
} |
|
40 |
}; |
|
| 53 | 41 |
}) |
| 55 | 42 |
.controller('ModalAddBookCtrl', function ($scope, ammicoApi, $modalInstance) { |
| 53 | 43 |
|
44 |
$scope.add = function(){ |
|
| 55 | 45 |
ammicoApi.listBooks.save({title: $scope.title}); |
| 53 | 46 |
$modalInstance.close(); |
47 |
}; |
|
48 |
||
49 |
$scope.cancel = function () { |
|
50 |
$modalInstance.dismiss('cancel'); |
|
51 |
}; |
|
| 24 | 52 |
}); |
53 |
})(); |