| author | ymh <ymh.work@gmail.com> |
| Wed, 08 Jan 2020 17:49:53 +0100 | |
| changeset 205 | 147583c43f0d |
| parent 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 |
|
|
170
533a98367f99
filter book in the request through 'type' parameter instead of filtering on client side
rougeronj
parents:
146
diff
changeset
|
8 |
$scope.books = Book.query({type: 'book', format:'json'}, function(data){ |
|
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
|
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++) { |
|
170
533a98367f99
filter book in the request through 'type' parameter instead of filtering on client side
rougeronj
parents:
146
diff
changeset
|
14 |
data[i].slides = Slide.query({idBook:data[i].id, limit: 5, format:'json'}); |
|
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 |
} |
|
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 |
}); |
|
146
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
99
diff
changeset
|
17 |
|
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
99
diff
changeset
|
18 |
// $scope.$on('slideDeleted', function (event, data) { |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
99
diff
changeset
|
19 |
// console.log(data); // 'Data to send' |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
99
diff
changeset
|
20 |
// }); |
| 91 | 21 |
|
|
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
|
22 |
$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
|
23 |
$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
|
24 |
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
|
25 |
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
|
26 |
}).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
|
27 |
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
|
28 |
$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
|
29 |
}); |
|
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 |
}); |
|
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 |
}) |
| 91 | 33 |
|
|
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
|
34 |
.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
|
35 |
$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
|
36 |
|
|
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.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
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
}); |
|
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 |
}); |
|
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 |
}); |
| 91 | 44 |
|
|
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
|
45 |
$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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
}); |
|
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 |
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
|
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 |
}; |
|
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 |
$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
|
55 |
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
|
56 |
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
|
57 |
$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
|
58 |
}, |
|
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 |
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
|
60 |
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
|
61 |
$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
|
62 |
} |
|
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 |
}); |
|
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 |
.controller('ModalAddBookCtrl', function ($scope, Book, $modalInstance) { |
| 91 | 68 |
|
|
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
|
69 |
$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
|
70 |
$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
|
71 |
}; |
|
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 |
$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
|
73 |
$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
|
74 |
} |
|
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 |
; |
|
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 |
$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
|
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.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
|
79 |
$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
|
80 |
}; |
|
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 |
|
|
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 |
$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
|
83 |
$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
|
84 |
}; |
|
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 |
}); |
| 24 | 86 |
})(); |