|
@@ -1,5 +1,5 @@
|
|
(function(){
|
|
(function(){
|
|
- app.controller('Authors', ['$scope', 'books.repository', '$routeParams','utils', function ($scope, booksRepository, $routeParams, utils){
|
|
|
|
|
|
+ app.controller('Authors', ['$scope', 'books.repository', '$routeParams','utils', '$uibModal', function ($scope, booksRepository, $routeParams, utils, $uibModal){
|
|
|
|
|
|
booksRepository.getAuthors()
|
|
booksRepository.getAuthors()
|
|
.then(function(respons){
|
|
.then(function(respons){
|
|
@@ -11,7 +11,19 @@
|
|
})
|
|
})
|
|
});
|
|
});
|
|
$scope.deleteAuthor = function(id){
|
|
$scope.deleteAuthor = function(id){
|
|
- $scope.authors.splice($scope.authors.indexOf(id), 1)
|
|
|
|
|
|
+
|
|
|
|
+ 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 = {
|
|
$scope.user = {
|
|
name: 'awesome user'
|
|
name: 'awesome user'
|
|
@@ -20,12 +32,30 @@
|
|
console.log($scope.user)
|
|
console.log($scope.user)
|
|
};
|
|
};
|
|
$scope.saveAuthor = function(data, author){
|
|
$scope.saveAuthor = function(data, author){
|
|
- booksRepository.updateAuthorsById(data, author).then(function(respons){
|
|
|
|
- utils.notify({
|
|
|
|
- message: 'authors edite',
|
|
|
|
- type: 'succes'
|
|
|
|
|
|
+ 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)
|
|
|
|
+ }
|
|
}])
|
|
}])
|
|
})();
|
|
})();
|