mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:15:50 +00:00
migrated from angular-router to ui-router
This article explains well why ui-router now is more popular: http://www.funnyant.com/angularjs-ui-router/
This commit is contained in:
parent
b67ce6b1ab
commit
e493177709
3 changed files with 28 additions and 25 deletions
|
@ -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',
|
||||
|
|
|
@ -3,30 +3,31 @@
|
|||
/*
|
||||
* Owner Search
|
||||
*/
|
||||
angular.module('controllers').controller('ownerSearchController', ['$scope', '$rootScope', '$resource', '$state',
|
||||
function($scope, $rootScope, $resource, $state) {
|
||||
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
|
||||
|
||||
$scope.submitOwnerFindForm = function() {
|
||||
|
||||
var destUrl = '/petclinic/owner/list?lastName='
|
||||
if(angular.isDefined($scope.ownerFindForm)) {
|
||||
destUrl += $scope.ownerFindForm.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;
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue