vlad 6 년 전
부모
커밋
08e4a1fa79
3개의 변경된 파일49개의 추가작업 그리고 11개의 파일을 삭제
  1. 37 7
      app/controllers/authors.controller.js
  2. 9 1
      app/services/books.factory.js
  3. 3 3
      app/views/authors.template.html

+ 37 - 7
app/controllers/authors.controller.js

@@ -1,5 +1,5 @@
 (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()
         .then(function(respons){
@@ -11,7 +11,19 @@
             })
         });
         $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 = {
             name: 'awesome user'
@@ -20,12 +32,30 @@
             console.log($scope.user)
         };
         $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)
+        }
     }])
 })();

+ 9 - 1
app/services/books.factory.js

@@ -11,7 +11,9 @@ app.factory('books.repository', ['webApi', '$http', function(webApi, $http) {
 		addBook: _addBook,
 		deleteBook: _deleteBook,
 		searchBy: _searchBy,
-		updateAuthorsById: _updateAuthorsById 
+		updateAuthorsById: _updateAuthorsById,
+		addAuthor: _addAuthor,
+		deleteAuthorById: _deleteAuthorById
 	};
 
 	function _getBooks() {
@@ -39,6 +41,12 @@ app.factory('books.repository', ['webApi', '$http', function(webApi, $http) {
 	function _updateAuthorsById(data, id){
 		return $http.put(webApi.DOMAIN + '/api/v2/authors/' + id, data);
 	}
+	function _addAuthor(data){
+		return $http.post(webApi.DOMAIN + '/api/v2/authors' , data);
+	}
+	function _deleteAuthorById(id){
+		return $http.delete(webApi.DOMAIN + '/api/v2/authors/' + id);
+	}
 }]);
 
 })();

+ 3 - 3
app/views/authors.template.html

@@ -1,5 +1,5 @@
 <h2 class="page-header">Athors</h2>
-
+<button class="btn btn-primary pull-right" ng-click="addAuthors()">Add Author</button>
 <table class="table table-hover">
     <thead>
         <th>Firstname</th>
@@ -10,10 +10,10 @@
         <td><span editable-text="author.lastname" e-form='editableForm' e-ng-model='author.lastname' e-name='lastname'>{{author.lastname || '-'}}</span></td>
         <td class="float-right">
             <span ng-show="!editableForm.$visible">
-                <button  class="btn-danger btn-xs pull-right" ng-click="deteteAuthor(author)"><i class="glyphicon glyphicon-trash"></i></button>
+                <button  class="btn-danger btn-xs pull-right" ng-click="deleteAuthor(author.id)"><i class="glyphicon glyphicon-trash"></i></button>
                 <button  class="btn-warning btn-xs pull-right" ng-click="editableForm.$show()"><i class="glyphicon glyphicon-pencil"></i></button>
             </span>
-            <form editable-form name="editableForm" ng-show="editableForm.$visible" onaftersave='saveAuthor($data,author.id)'>
+            <form editable-form name="editableForm" ng-show="editableForm.$visible" onaftersave='saveAuthor($data,author.id)' shown='inserted === author'>
                 <span>
                         <button type="button" class="btn-danger btn-lg pull-right" ng-disabled="editableForm.$waiting" ng-click="editableForm.$cancel()"><i class="glyphicon glyphicon-remove"></i></button>
                         <button  type="submit" class="btn-warning btn-lg pull-right" ng-disabled="editableForm.$waiting" ng-click=""><i class="glyphicon glyphicon-ok "></i></button>