vlad 6 vuotta sitten
vanhempi
commit
ffd5b6d054

+ 10 - 6
app/controllers/authors.controller.js

@@ -1,5 +1,6 @@
 (function(){
     app.controller('Authors', ['$scope', 'books.repository', '$routeParams','utils', function ($scope, booksRepository, $routeParams, utils){
+        
         booksRepository.getAuthors()
         .then(function(respons){
             $scope.authors = respons.data
@@ -8,20 +9,23 @@
                 message: error.statusText,
                 type: 'danger'
             })
-        })
+        });
         $scope.deleteAuthor = function(id){
             $scope.authors.splice($scope.authors.indexOf(id), 1)
         };
-        // utils.notify({
-        //     message: 'her na lob',
-        //     type: 'danger'
-        // })
         $scope.user = {
             name: 'awesome user'
         };
         $scope.updateUser = function(){
             console.log($scope.user)
         };
-        
+        $scope.saveAuthor = function(data, author){
+            booksRepository.updateAuthorsById(data, author).then(function(respons){
+                utils.notify({
+                    message: 'authors edite',
+                    type: 'succes'
+                })
+            })
+        };
     }])
 })();

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

@@ -10,7 +10,8 @@ app.factory('books.repository', ['webApi', '$http', function(webApi, $http) {
 		updateBookById: _updateBookById,
 		addBook: _addBook,
 		deleteBook: _deleteBook,
-		searchBy: _searchBy
+		searchBy: _searchBy,
+		updateAuthorsById: _updateAuthorsById 
 	};
 
 	function _getBooks() {
@@ -35,6 +36,9 @@ app.factory('books.repository', ['webApi', '$http', function(webApi, $http) {
 	function _searchBy(string){
 		return $http.get(webApi.DOMAIN + '/api/v2/search?string=' + string);
 	}
+	function _updateAuthorsById(data, id){
+		return $http.put(webApi.DOMAIN + '/api/v2/authors/' + id, data);
+	}
 }]);
 
 })();

+ 14 - 9
app/views/authors.template.html

@@ -1,19 +1,24 @@
 <h2 class="page-header">Athors</h2>
 
-<a href="#" editable-text="user.name" onaftersave='updateUser()'>{{ user.name || "empty" }}</a>
-
 <table class="table table-hover">
     <thead>
         <th>Firstname</th>
         <th>Lastname</th>
     </thead>
     <tbody ng-repeat="author in authors">
-        <th>{{author.firstname}}</th>
-        <th>{{author.lastname}}</th>
-        <th class="float-right">
-            <button  class="btn-danger btn-xs pull-right" ng-click="deteteAuthor(author)"><i class="glyphicon glyphicon-trash"></i></button>
-            <button  class="btn-warning btn-xs pull-right"><i class="glyphicon glyphicon-pencil"></i></button>
- 
-        </th>
+        <td><span editable-text="author.firstname" e-form='editableForm' e-ng-model='author.firstname' e-name='firstname'>{{author.firstname || '-'}}</span></td>
+        <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-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)'>
+                <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> 
+                </span>
+            </form>
+        </td>
     </tbody>
 </table>

+ 0 - 0
article-map.ls