| author | rougeronj |
| Tue, 07 Apr 2015 11:55:11 +0200 | |
| changeset 72 | ed2ee692ff6f |
| parent 69 | 88f76bf93465 |
| child 74 | 44ebb0d0b836 |
| 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' |
|
|
65
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
15 |
}).result.then(function (newBook) { |
|
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
16 |
$scope.books.push(newBook); |
| 53 | 17 |
}); |
18 |
}; |
|
|
69
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
19 |
$scope.deleteItem = function(i){ |
|
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
20 |
if(0<=i && i<$scope.books.length){ |
|
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
21 |
if(window.confirm('Êtes-vous sûr(e) de vouloir effacer cet élément ? Cette action est irrémédiable.')){ |
|
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
22 |
ammicoApi.book.delete({idBook: $scope.books[i].id}, function(){ |
|
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
23 |
$scope.books.splice(i, 1); |
|
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
24 |
}, |
|
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
25 |
function(error) { |
|
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
26 |
if (error.status === 404){ |
|
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
27 |
$scope.books.splice(i, 1); |
|
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
28 |
} |
|
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
29 |
}); |
|
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
30 |
} |
|
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
31 |
} |
|
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
32 |
}; |
| 24 | 33 |
}) |
| 55 | 34 |
.controller('bookCtrl', function($scope, ammicoApi, $routeParams) { |
35 |
$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
|
36 |
$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
|
37 |
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
|
38 |
}); |
|
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
|
39 |
$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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
}); |
| 55 | 44 |
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
|
45 |
} |
|
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
|
46 |
}; |
|
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
|
47 |
|
| 24 | 48 |
$scope.deleteItem = function(i){ |
49 |
if(0<=i && i<$scope.slides.length){ |
|
50 |
if(window.confirm('Êtes-vous sûr(e) de vouloir effacer cet élément ? Cette action est irrémédiable.')){ |
|
| 55 | 51 |
ammicoApi.slide.delete({idSlide: $scope.slides[i].id}, function(){ |
|
42
edbfef527c66
remove unused success callback - remove unused css
rougeronj
parents:
32
diff
changeset
|
52 |
$scope.slides.splice(i, 1); |
|
65
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
53 |
}, |
|
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
54 |
function(error) { |
|
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
55 |
if (error.status === 404){ |
|
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
56 |
$scope.slides.splice(i, 1); |
|
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
57 |
} |
|
32
802ba9793507
add delete request to delete a slide - rename some .ressources fonctions
rougeronj
parents:
24
diff
changeset
|
58 |
}); |
| 24 | 59 |
} |
60 |
} |
|
61 |
}; |
|
| 53 | 62 |
}) |
| 55 | 63 |
.controller('ModalAddBookCtrl', function ($scope, ammicoApi, $modalInstance) { |
| 53 | 64 |
|
65 |
$scope.add = function(){ |
|
|
65
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
66 |
ammicoApi.listBooks.save({title: $scope.title}, function(newBook){ |
|
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
67 |
$modalInstance.close(newBook); |
|
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
68 |
}); |
| 53 | 69 |
}; |
70 |
$scope.cancel = function () { |
|
71 |
$modalInstance.dismiss('cancel'); |
|
72 |
}; |
|
| 24 | 73 |
}); |
74 |
})(); |