add books controller to handle list of books
authorrougeronj
Mon, 23 Mar 2015 12:22:44 +0100
changeset 24 21ecbde9e080
parent 23 4a155e6fb409
child 25 4053d9a44548
add books controller to handle list of books
client/app/books/book.css
client/app/books/book.html
client/app/books/books.html
client/app/books/books_controller.js
client/app/books/books_controller_test.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/app/books/book.css	Mon Mar 23 12:22:44 2015 +0100
@@ -0,0 +1,43 @@
+.gallery .item {
+  overflow:hidden; position:relative; height: 250px; padding: 5px;
+}
+
+.img-ctn {
+    height: 100%; width: 100%; border: 1px solid #DDD; padding: 5px; overflow: hidden;
+}
+
+.img-ctn:hover {
+    background-color: #DDD;
+}
+
+.img-ctn p {
+    background-color: #ddd;
+    bottom: -5px;
+    display: none;
+    padding: 2px 5px;
+    position: absolute;
+    width: calc(100% - 22px);
+}
+
+.img-ctn:hover p, .img-ctn:hover .gallery-buttons {
+    display: block;
+}
+
+.gallery .item img {
+    margin: 0 auto;
+    max-height: 100%;
+}
+
+.gallery-buttons{
+	display: none;
+    position: absolute;
+    right: 10px;
+    top: 10px;
+}
+
+.subtitle {
+    border-top: 1px solid #000;
+    border-bottom: 1px dotted #000;
+    margin-top: 20px;
+    padding: 6px 0 10px;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/app/books/book.html	Mon Mar 23 12:22:44 2015 +0100
@@ -0,0 +1,15 @@
+<p>Books {{idBook}}&nbsp;:</p>
+
+<ul class="list-unstyled list-inline row gallery">
+  <li class="col-md-3 item" ng-repeat="i in slides">
+    <div class="img-ctn">
+        <img class="img img-responsive image" ng-src="{{ i.details.firstImg }}" />
+        <p>{{ i.details.title }}</p>
+        <div class="gallery-buttons">
+          <a class="btn btn-default" href="#/slide/edit/{{ $index }}"><span class="glyphicon glyphicon-pencil"></span></a>
+          <a class="btn btn-default" href="#/slide/{{ $index }}"><span class="glyphicon glyphicon-eye-open"></span></a>
+          <a class="btn btn-default" ng-click="deleteItem($index)"><span class="glyphicon glyphicon-trash"></span></a>
+        </div>
+    </div>
+  </li>
+</ul>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/app/books/books.html	Mon Mar 23 12:22:44 2015 +0100
@@ -0,0 +1,9 @@
+<p>Liste des books&nbsp;:</p>
+
+<ul class="row ">
+  <li class="" ng-repeat="i in books">
+    <div>
+       <a class="visite" href="#/books/{{ i.id }}">{{ i.title }}</a>
+    </div>
+  </li>
+</ul>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/app/books/books_controller.js	Mon Mar 23 12:22:44 2015 +0100
@@ -0,0 +1,29 @@
+(function(){
+	'use strict';
+
+	angular.module('ammicoBooks',['ngRoute'])
+	.service('booksModel', function(searchApi) {
+		this.books = searchApi.getResource.query({action:'books', format:'json'}); 
+	})
+	.controller('booksCtrl', function($scope, $location, booksModel){
+		$scope.books = booksModel.books;
+		$scope.searchSubmit = function(){
+			$location.path('/search/' + $scope.q);
+		};
+	})
+	.controller('bookCtrl', function($scope, searchApi, $routeParams, booksModel) {
+		$scope.slides = searchApi.getResource.query({action:'books/'+$routeParams.idBook+'/slides', format:'json'}, function(data){
+			if (typeof(booksModel.slide) === 'undefined')
+				booksModel.slides = []; 
+			booksModel.slides[$routeParams.idBook] = data;
+		});
+
+		$scope.deleteItem = function(i){
+			if(0<=i && i<$scope.slides.length){
+				if(window.confirm('Êtes-vous sûr(e) de vouloir effacer cet élément ? Cette action est irrémédiable.')){
+					$scope.slides.splice(i, 1);
+				}
+			}
+		};
+	});
+})();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/app/books/books_controller_test.js	Mon Mar 23 12:22:44 2015 +0100
@@ -0,0 +1,7 @@
+'use strict';
+
+describe("books_controller_test", function(){
+    it("should assert something",function(){
+        expect(true).toBe(true);
+    })
+})