client/app/books/books_controller.js
author rougeronj
Fri, 03 Apr 2015 10:41:27 +0200
changeset 58 e71b49ff4a23
parent 57 388b29d38b44
child 65 8116c2b28414
permissions -rw-r--r--
add config.py to gitignore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
     1
(function(){
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
     2
	'use strict';
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
     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
10fd23382e76 split ammico $resource to a new .Service
rougeronj
parents: 53
diff changeset
     6
		$scope.books = ammicoApi.listBooks.query({format:'json'});
24
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
     7
		$scope.searchSubmit = function(){
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
     8
			$location.path('/search/' + $scope.q);
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
     9
		};
53
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    10
		
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    11
		$scope.addBook = function () {
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    12
			$modal.open({
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    13
				templateUrl: 'books/add_modal.html',
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    14
				controller: 'ModalAddBookCtrl'
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    15
			});
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    16
		};
24
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    17
	})
55
10fd23382e76 split ammico $resource to a new .Service
rougeronj
parents: 53
diff changeset
    18
	.controller('bookCtrl', function($scope, ammicoApi, $routeParams) {
10fd23382e76 split ammico $resource to a new .Service
rougeronj
parents: 53
diff changeset
    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
10fd23382e76 split ammico $resource to a new .Service
rougeronj
parents: 53
diff changeset
    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
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    32
		$scope.deleteItem = function(i){
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    33
			if(0<=i && i<$scope.slides.length){
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    34
				if(window.confirm('Êtes-vous sûr(e) de vouloir effacer cet élément ? Cette action est irrémédiable.')){
55
10fd23382e76 split ammico $resource to a new .Service
rougeronj
parents: 53
diff changeset
    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
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    38
				}
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    39
			}
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    40
		};
53
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    41
	})
55
10fd23382e76 split ammico $resource to a new .Service
rougeronj
parents: 53
diff changeset
    42
	.controller('ModalAddBookCtrl', function ($scope, ammicoApi, $modalInstance) {
53
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    43
		
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    44
		$scope.add = function(){
55
10fd23382e76 split ammico $resource to a new .Service
rougeronj
parents: 53
diff changeset
    45
			ammicoApi.listBooks.save({title: $scope.title});
53
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    46
			$modalInstance.close();
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    47
		};
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    48
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    49
		$scope.cancel = function () {
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    50
			$modalInstance.dismiss('cancel');
dac1df90b49e fucntion and button to add a book
rougeronj
parents: 49
diff changeset
    51
		};
24
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    52
	});
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    53
})();