|
@@ -4,12 +4,44 @@
|
|
|
|
|
|
app.controller('BookDetails', ['$scope', 'books.repository', '$routeParams', function ($scope, booksRepository, $routeParams)
|
|
app.controller('BookDetails', ['$scope', 'books.repository', '$routeParams', function ($scope, booksRepository, $routeParams)
|
|
{
|
|
{
|
|
|
|
+ var details = {};
|
|
booksRepository.getBookById($routeParams.id)
|
|
booksRepository.getBookById($routeParams.id)
|
|
.then(function(response) {
|
|
.then(function(response) {
|
|
- console.log(response.data);
|
|
|
|
|
|
+ $scope.details = response.data;
|
|
|
|
+ $scope.details.date = new Date($scope.details.date)
|
|
|
|
+ console.log($scope.details)
|
|
}, function(error) {
|
|
}, function(error) {
|
|
alert(error)}
|
|
alert(error)}
|
|
)
|
|
)
|
|
|
|
+
|
|
|
|
+ $scope.isEditeMode = false;
|
|
|
|
+ $scope.edite = function(){
|
|
|
|
+ $scope.isEditeMode = true;
|
|
|
|
+ details = angular.copy($scope.details)
|
|
|
|
+ }
|
|
|
|
+ $scope.noEdite = function(){
|
|
|
|
+ $scope.isEditeMode = false;
|
|
|
|
+ $scope.details = angular.copy(details)
|
|
|
|
+ }
|
|
|
|
+ booksRepository.getAuthors()
|
|
|
|
+ .then(function(response){
|
|
|
|
+ $scope.authors = response.data.map(function(author){
|
|
|
|
+ return {
|
|
|
|
+ id: author.id,
|
|
|
|
+ name: author.firstname + ' ' + author.lastname
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ $scope.save = function(){
|
|
|
|
+ booksRepository.updateBookById($scope.details.id, $scope.details)
|
|
|
|
+ $scope.isEditeMode = false;
|
|
|
|
+ };
|
|
|
|
+ $scope.getAuthorsById = function(id){
|
|
|
|
+ if(!$scope.authors || !id) return;
|
|
|
|
+ return $scope.authors.filter(function(item){
|
|
|
|
+ return item.id === id;
|
|
|
|
+ })[0].name;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
]);
|
|
]);
|
|
}
|
|
}
|