(function(){ app.controller('Authors', ['$scope', 'books.repository', '$routeParams','utils', '$uibModal', function ($scope, booksRepository, $routeParams, utils, $uibModal){ booksRepository.getAuthors() .then(function(respons){ $scope.authors = respons.data },function(error){ utils.notify({ message: error.statusText, type: 'danger' }) }); $scope.deleteAuthor = function(id){ var modal = $uibModal.open({ templateUrl: 'app/modals/confirm/confirm.template.html', controller: 'Confirm', size: 'sm' }) modal.result.then(function(result){ if(!result) return; booksRepository.deleteAuthorById(id).then(function(respons){ $scope.authors.splice($scope.authors.indexOf(id), 1); }) }) }; $scope.user = { name: 'awesome user' }; $scope.updateUser = function(){ console.log($scope.user) }; $scope.saveAuthor = function(data, author){ if(author){ booksRepository.updateAuthorsById(data, author).then(function(respons){ utils.notify({ message: 'Authors edite', type: 'succes' }) }) }else { booksRepository.addAuthor(data, author).then(function(respons){ utils.notify({ message: 'Authors Add', type: 'succes' }) }) } }; $scope.addAuthors = function(){ $scope.inserted = { id: 0, firstname: '', lastname: '', }; $scope.authors.push($scope.inserted) } }]) })();