From 10e1b337cfca5a1a5f456b2cba8783d84a8eb794 Mon Sep 17 00:00:00 2001 From: "Nguyen Anh Tuan, Tony" Date: Mon, 9 Feb 2015 22:48:22 +0800 Subject: [PATCH] TN: Add EditOwner function --- .../petclinic/rest/OwnerRestController.java | 11 ++++++++++- src/main/webapp/components/dashboard/_owners.html | 8 ++++---- .../webapp/components/owners/OwnerController.js | 14 ++++++++++++++ .../webapp/components/owners/owner_details.html | 12 ++++++------ src/main/webapp/js/app.js | 3 ++- src/main/webapp/services/services.js | 1 + 6 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/rest/OwnerRestController.java b/src/main/java/org/springframework/samples/petclinic/rest/OwnerRestController.java index a4e155804..e4eecd65b 100644 --- a/src/main/java/org/springframework/samples/petclinic/rest/OwnerRestController.java +++ b/src/main/java/org/springframework/samples/petclinic/rest/OwnerRestController.java @@ -17,6 +17,7 @@ package org.springframework.samples.petclinic.rest; import java.util.Collection; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.samples.petclinic.model.Owner; import org.springframework.samples.petclinic.service.ClinicService; @@ -44,7 +45,15 @@ public class OwnerRestController { @RequestMapping(value = "/owners", method = RequestMethod.POST) public @ResponseBody Owner create(@RequestBody Owner owner) { - this.clinicService.saveOwner(owner); + if (owner.getId()!=null && owner.getId()>0){ + Owner existingOwner = clinicService.findOwnerById(owner.getId()); + BeanUtils.copyProperties(owner, existingOwner, "pets", "id"); + clinicService.saveOwner(existingOwner); + } + else { + this.clinicService.saveOwner(owner); + } + return owner; } diff --git a/src/main/webapp/components/dashboard/_owners.html b/src/main/webapp/components/dashboard/_owners.html index 1cf81d769..aae3045ef 100644 --- a/src/main/webapp/components/dashboard/_owners.html +++ b/src/main/webapp/components/dashboard/_owners.html @@ -4,19 +4,19 @@
- Generic placeholder image + Generic placeholder image
-

+

  • - Generic placeholder image + Generic placeholder image
  • - +
diff --git a/src/main/webapp/components/owners/OwnerController.js b/src/main/webapp/components/owners/OwnerController.js index d9306a7c2..ce387dc4f 100644 --- a/src/main/webapp/components/owners/OwnerController.js +++ b/src/main/webapp/components/owners/OwnerController.js @@ -17,4 +17,18 @@ var OwnerDetailsController = ['$scope','$stateParams','Owner', function($scope,$ $scope.prevOwner = Owner.get({id:prevId}); $scope.nextOwner = Owner.get({id:nextId}); $scope.currentOwner = Owner.get($stateParams); + + $scope.saveOwner = function(){ + owner = $scope.currentOwner; + Owner.save(owner); + } +}]; + +var AddOwnerController = ['$scope','Owner', function($scope,Owner) { + + $scope.owner={firstName:'firstName',pets:[]}; + + $scope.addOwner = function(){ + Owner.$save($scope.owner); + } }]; \ No newline at end of file diff --git a/src/main/webapp/components/owners/owner_details.html b/src/main/webapp/components/owners/owner_details.html index 0f5a39575..9bc9146cb 100644 --- a/src/main/webapp/components/owners/owner_details.html +++ b/src/main/webapp/components/owners/owner_details.html @@ -258,11 +258,11 @@
- +
- +
@@ -284,15 +284,15 @@
- +
- +
- +
@@ -301,7 +301,7 @@
- +
diff --git a/src/main/webapp/js/app.js b/src/main/webapp/js/app.js index c86da5044..321db26de 100644 --- a/src/main/webapp/js/app.js +++ b/src/main/webapp/js/app.js @@ -2,7 +2,7 @@ var app = angular.module('spring-petclinic', ['ui.router','ui.router.stateHelper /** Start of Configurable constants **/ -app.constant('useMockData', true); +app.constant('useMockData', false); app.constant('context', '/petclinic'); /** End of Configurable constants **/ @@ -59,6 +59,7 @@ app.controller('VeterinarianController', VeterinarianController); app.controller('PetController', PetController); app.controller('OwnerController', OwnerController); app.controller('OwnerDetailsController', OwnerDetailsController); +app.controller('AddOwnerController', AddOwnerController); app.controller('VisitController', VisitController); /** Services **/ diff --git a/src/main/webapp/services/services.js b/src/main/webapp/services/services.js index 95421e4ac..062ed5db7 100644 --- a/src/main/webapp/services/services.js +++ b/src/main/webapp/services/services.js @@ -50,6 +50,7 @@ var MockService = ['$httpBackend', '$http', '$q', 'context', function($httpBacke console.log("Setting up passthrough for other urls"); var passThroughRegex = new RegExp('/'); $httpBackend.whenGET(passThroughRegex).passThrough(); + $httpBackend.whenPOST(passThroughRegex).passThrough(); } } }