client/app/books/books_controller.js
author rougeronj
Mon, 23 Mar 2015 12:22:44 +0100
changeset 24 21ecbde9e080
child 32 802ba9793507
permissions -rw-r--r--
add books controller to handle list of books
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
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
     4
	angular.module('ammicoBooks',['ngRoute'])
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
     5
	.service('booksModel', function(searchApi) {
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
     6
		this.books = searchApi.getResource.query({action:'books', format:'json'}); 
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
     7
	})
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
     8
	.controller('booksCtrl', function($scope, $location, booksModel){
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
     9
		$scope.books = booksModel.books;
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    10
		$scope.searchSubmit = function(){
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    11
			$location.path('/search/' + $scope.q);
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    12
		};
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    13
	})
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    14
	.controller('bookCtrl', function($scope, searchApi, $routeParams, booksModel) {
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    15
		$scope.slides = searchApi.getResource.query({action:'books/'+$routeParams.idBook+'/slides', format:'json'}, function(data){
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    16
			if (typeof(booksModel.slide) === 'undefined')
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    17
				booksModel.slides = []; 
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    18
			booksModel.slides[$routeParams.idBook] = data;
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    19
		});
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    20
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    21
		$scope.deleteItem = function(i){
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    22
			if(0<=i && i<$scope.slides.length){
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    23
				if(window.confirm('Êtes-vous sûr(e) de vouloir effacer cet élément ? Cette action est irrémédiable.')){
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    24
					$scope.slides.splice(i, 1);
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    25
				}
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    26
			}
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    27
		};
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    28
	});
21ecbde9e080 add books controller to handle list of books
rougeronj
parents:
diff changeset
    29
})();