diff --git a/src/main/webapp/scripts/app/app.js b/src/main/webapp/scripts/app/app.js index 1be9626c0b54691b3293555060a749f8498026a8..5510889e345f876020b8b09d0471869fb944a154 100644 --- a/src/main/webapp/scripts/app/app.js +++ b/src/main/webapp/scripts/app/app.js @@ -36,7 +36,7 @@ petClinicApp.config(['$stateProvider', '$urlRouterProvider', function($stateProv }). state('app.ownerlist', { - url: 'owner/list', + url: 'owner/list?lastName', views: { 'content@': { templateUrl: 'scripts/app/owner/ownerList.html', diff --git a/src/main/webapp/scripts/app/owner/OwnerController.js b/src/main/webapp/scripts/app/owner/OwnerController.js index a46a3b6db0dfbd5ec705fc75488d6648c7c618b5..8202a17bf2451aeb0fd70373842a1067e5ab48d2 100644 --- a/src/main/webapp/scripts/app/owner/OwnerController.js +++ b/src/main/webapp/scripts/app/owner/OwnerController.js @@ -3,30 +3,31 @@ /* * Owner Search */ -angular.module('controllers').controller('ownerSearchController', ['$scope', '$rootScope', '$resource', '$state', - function($scope, $rootScope, $resource, $state) { - - $scope.submitOwnerFindForm = function() { - - var destUrl = '/petclinic/owner/list?lastName=' - if(angular.isDefined($scope.ownerFindForm)) { - destUrl += $scope.ownerFindForm.lastName; - } +angular.module('controllers').controller('ownerSearchController', ['$scope', '$state', + function($scope, $state) { + + $scope.ownerSearchForm = {}; + // form always needs to be initialised + // otherwise we can't read $scope.ownerSearchForm.lastName - var ownerResource = $resource(destUrl); - $rootScope.owners = ownerResource.query(); - $state.go('app.ownerlist'); //updating URL in address bar - }}]); + $scope.submitOwnerSearchForm = function() { + var lastNameValue; + $state.go('app.ownerlist', {lastName: $scope.ownerSearchForm.lastName}); +}}]); /* * Owners List */ -angular.module('controllers').controller('ownerListController', ['$scope', '$rootScope', - function($scope, $rootScope, $location) { - if ($rootScope.owners!=null){ - $scope.ownerList = $rootScope.owners; - } - }]); +angular.module('controllers').controller('ownerListController', ['$scope', '$resource', '$stateParams', + function($scope, $resource, $stateParams) { + + var destUrl = '/petclinic/owner/list?lastName='; + if(angular.isDefined($stateParams.lastName)) { + destUrl += $stateParams.lastName; + } + var ownerResource = $resource(destUrl); + $scope.ownerList = ownerResource.query(); +}]); /* * Owners detail (used for both Editable and non-editable pages) @@ -46,6 +47,8 @@ function loadOwner($scope, $resource, $stateParams) { angular.module('controllers').controller('ownerFormController', ['$scope', '$resource', '$http', '$stateParams', '$state', function($scope, $resource, $http, $stateParams, $state) { + scope.submitOwnerForm = {}; + $scope.submitOwnerForm = function() { var form = $scope.owner; diff --git a/src/main/webapp/scripts/app/owner/ownerSearchForm.html b/src/main/webapp/scripts/app/owner/ownerSearchForm.html index 778b091956fd97a719e2f683a1e64c6d3ed0fb63..528a87e79aa3ce4bce8a5fc4b5d07b92a852dc2d 100644 --- a/src/main/webapp/scripts/app/owner/ownerSearchForm.html +++ b/src/main/webapp/scripts/app/owner/ownerSearchForm.html @@ -1,15 +1,15 @@ - <h2>Find Owners</h2> - <form class="form-horizontal" id="ownerFindForm" data-ng-controller="ownerSearchController"> + <h2>Find Ownersss</h2> + <form class="form-horizontal" ng-controller="ownerSearchController"> <fieldset> <div class="control-group" id="lastName"> <label class="control-label">Last name </label> - <input ng-model="ownerFindForm.lastName" size="30" maxlength="80"/> + <input ng-model="ownerSearchForm.lastName" size="30" maxlength="80"/> </div> <div class="form-actions"> - <button type="submit" ng-click="submitOwnerFindForm()">Find Owner</button> + <button type="submit" ng-click="submitOwnerSearchForm()">Find Ownerss</button> </div> </fieldset> </form> <br/> - <a href="/owners/new">Add Owner</a> + <a href="/owners/new">Add Ownerss</a>