| author | rougeronj |
| Wed, 08 Apr 2015 00:36:37 +0200 | |
| changeset 77 | ee963d1c409b |
| parent 74 | 44ebb0d0b836 |
| child 91 | f7a844a9079e |
| 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){ |
|
74
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
6 |
$scope.books = ammicoApi.listBooks.query({format:'json'}, function(data){ |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
7 |
data.sort(function (a, b) { |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
8 |
return a.date < b.date; |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
9 |
}); |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
10 |
}); |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
11 |
|
| 24 | 12 |
$scope.searchSubmit = function(){ |
13 |
$location.path('/search/' + $scope.q); |
|
14 |
}; |
|
|
74
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
15 |
|
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
16 |
$scope.addBook = function (idParent) { |
| 53 | 17 |
$modal.open({ |
18 |
templateUrl: 'books/add_modal.html', |
|
19 |
controller: 'ModalAddBookCtrl' |
|
|
74
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
20 |
}).result.then(function (title) { |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
21 |
ammicoApi.listBooks.save({idParent:idParent, title: title}, function(newBook){ |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
22 |
$scope.books.push(newBook); |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
23 |
}); |
| 53 | 24 |
}); |
25 |
}; |
|
|
74
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
26 |
$scope.deleteItem = function(book){ |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
27 |
if(window.confirm('Êtes-vous sûr(e) de vouloir effacer cet élément ? Cette action est irrémédiable.')){ |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
28 |
ammicoApi.book.delete({idBook: book.id}, function(){ |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
29 |
$scope.books.splice($scope.books.indexOf(book), 1); |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
30 |
}, |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
31 |
function(error) { |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
32 |
if (error.status === 404){ |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
33 |
$scope.books.splice($scope.books.indexOf(book), 1); |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
34 |
} |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
35 |
}); |
|
69
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
36 |
} |
|
88f76bf93465
update list book view with accordeons and add delete fonction on a book
rougeronj
parents:
65
diff
changeset
|
37 |
}; |
| 24 | 38 |
}) |
| 55 | 39 |
.controller('bookCtrl', function($scope, ammicoApi, $routeParams) { |
|
74
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
40 |
$scope.slides = ammicoApi.booksSlides.query({idBook:$routeParams.idBook, format:'json'}, function(data){ |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
41 |
data.sort(function (a, b) { |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
42 |
return a.orderIndex > b.orderIndex; |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
43 |
}); |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
44 |
}); |
|
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 |
$scope.sortableOptions = { |
|
74
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
46 |
stop: function() { |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
47 |
var order = $scope.slides.map(function(i){ |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
48 |
return i.id; |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
49 |
}); |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
50 |
ammicoApi.order.save({idBook:$routeParams.idBook}, {order: order}); |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
51 |
} |
|
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
|
52 |
}; |
|
74
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
53 |
|
| 24 | 54 |
$scope.deleteItem = function(i){ |
55 |
if(0<=i && i<$scope.slides.length){ |
|
56 |
if(window.confirm('Êtes-vous sûr(e) de vouloir effacer cet élément ? Cette action est irrémédiable.')){ |
|
| 55 | 57 |
ammicoApi.slide.delete({idSlide: $scope.slides[i].id}, function(){ |
|
42
edbfef527c66
remove unused success callback - remove unused css
rougeronj
parents:
32
diff
changeset
|
58 |
$scope.slides.splice(i, 1); |
|
65
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
59 |
}, |
|
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
60 |
function(error) { |
|
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
61 |
if (error.status === 404){ |
|
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
62 |
$scope.slides.splice(i, 1); |
|
8116c2b28414
add book to current scope on success add on server side
rougeronj
parents:
57
diff
changeset
|
63 |
} |
|
32
802ba9793507
add delete request to delete a slide - rename some .ressources fonctions
rougeronj
parents:
24
diff
changeset
|
64 |
}); |
| 24 | 65 |
} |
66 |
} |
|
67 |
}; |
|
| 53 | 68 |
}) |
| 55 | 69 |
.controller('ModalAddBookCtrl', function ($scope, ammicoApi, $modalInstance) { |
|
74
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
70 |
|
| 53 | 71 |
$scope.add = function(){ |
|
74
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
72 |
$modalInstance.close($scope.title); |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
73 |
// ammicoApi.listBooks.save({title: $scope.title}, function(newBook){ |
|
44ebb0d0b836
get the book id of the book to delete from the template instead of $index (because we reorder the list so $index are not really clear anymore)
rougeronj
parents:
69
diff
changeset
|
74 |
// }); |
| 53 | 75 |
}; |
76 |
$scope.cancel = function () { |
|
77 |
$modalInstance.dismiss('cancel'); |
|
78 |
}; |
|
| 24 | 79 |
}); |
80 |
})(); |