| author | rougeronj |
| Wed, 10 Jun 2015 15:15:41 +0200 | |
| changeset 155 | e7c887d93039 |
| parent 146 | c6fa8ee3f562 |
| child 170 | 533a98367f99 |
| permissions | -rw-r--r-- |
| 24 | 1 |
(function(){ |
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
2 |
'use strict'; |
| 91 | 3 |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
4 |
angular.module('ammicoBooks',['ngRoute', 'ui.sortable']) |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
5 |
.controller('booksCtrl', function($scope, $location, $modal, Book, Slide){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
6 |
$scope.editable = true; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
7 |
|
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
8 |
$scope.books = Book.query({format:'json'}, function(data){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
9 |
data.sort(function (a, b) { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
10 |
return a.date < b.date; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
11 |
}); |
|
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
|
12 |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
13 |
for (var i = 0; i < data.length; i++) { |
|
146
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
99
diff
changeset
|
14 |
if (data[i].id_article === null){ |
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
15 |
data[i].slides = Slide.query({idBook:data[i].id, limit: 5, format:'json'}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
16 |
} |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
17 |
} |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
18 |
}); |
|
146
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
99
diff
changeset
|
19 |
|
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
99
diff
changeset
|
20 |
// $scope.$on('slideDeleted', function (event, data) { |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
99
diff
changeset
|
21 |
// console.log(data); // 'Data to send' |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
99
diff
changeset
|
22 |
// }); |
| 91 | 23 |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
24 |
$scope.addBook = function (idParent) { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
25 |
$modal.open({ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
26 |
templateUrl: 'books/add_modal.html', |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
27 |
controller: 'ModalAddBookCtrl' |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
28 |
}).result.then(function (title) { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
29 |
Book.save({idParent:idParent, title: title}, function(newBook){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
30 |
$scope.books.push(newBook); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
31 |
}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
32 |
}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
33 |
}; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
34 |
}) |
| 91 | 35 |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
36 |
.controller('bookCtrl', function($scope, $location, $routeParams, $modal, Book, Slide, Order) { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
37 |
$scope.editable = true; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
38 |
|
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
39 |
$scope.book = Book.get({idBook:$routeParams.idBook, format:'json'}, function(data){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
40 |
data.slides = Slide.query({idBook: data.id, format:'json'}, function(data){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
41 |
data.sort(function (a, b) { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
42 |
return a.orderIndex > b.orderIndex; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
43 |
}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
44 |
}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
45 |
}); |
| 91 | 46 |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
47 |
$scope.sortableOptions = { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
48 |
stop: function() { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
49 |
var order = $scope.book.slides.map(function(i){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
50 |
return i.id; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
51 |
}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
52 |
Order.save({idBook:$routeParams.idBook}, {order: order}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
53 |
} |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
54 |
}; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
55 |
|
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
56 |
$scope.deleteItem = function(item){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
57 |
if(window.confirm('Êtes-vous sûr(e) de vouloir effacer cet élément ? Cette action est irrémédiable.')){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
58 |
Slide.delete({idSlide: item.id}, function(){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
59 |
$scope.book.slides.splice($scope.book.slides.indexOf(item), 1); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
60 |
}, |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
61 |
function(error) { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
62 |
if (error.status === 404){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
63 |
$scope.book.slides.splice($scope.book.indexOf(item), 1); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
64 |
} |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
65 |
}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
66 |
} |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
67 |
}; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
68 |
}) |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
69 |
.controller('ModalAddBookCtrl', function ($scope, Book, $modalInstance) { |
| 91 | 70 |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
71 |
$scope.add = function(){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
72 |
$modalInstance.close($scope.title); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
73 |
}; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
74 |
$scope.cancel = function () { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
75 |
$modalInstance.dismiss('cancel'); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
76 |
} |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
77 |
; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
78 |
$scope.books = Book.query({format:'json'}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
79 |
|
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
80 |
$scope.addToBook = function(idBook){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
81 |
$modalInstance.close(idBook); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
82 |
}; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
83 |
|
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
84 |
$scope.cancel = function () { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
85 |
$modalInstance.dismiss('cancel'); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
86 |
}; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
87 |
}); |
| 24 | 88 |
})(); |