12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- (function ()
- {
- 'use strict';
- app.controller('BookDetails', ['$scope', 'books.repository', '$routeParams','utils', function ($scope, booksRepository, $routeParams, utils)
- {
- var details = {};
- booksRepository.getBookById($routeParams.id)
- .then(function(response) {
- $scope.details = response.data;
- $scope.details.date = new Date($scope.details.date)
- console.log($scope.details)
- }, function(error) {
- utils.notify({
- message: error.statusText,
- type: 'danger'
- })
- }
- )
- $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;
- }
- }
- ]);
- }
- )();
|