Commit 1438ac9e authored by thejoelinux's avatar thejoelinux

test avec angular/route/resource/REST

parent e1f7614e
<!DOCTYPE html>
<html ng-app="ludotheque">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/cdn/css/bootstrap/3.3.5/bootstrap.min.css"></link>
<link rel="stylesheet" href="/cdn/css/bootstrap/3.3.5/bootstrap-theme.min.css"></link>
<script src="/cdn/js/jquery/2.1.4/jquery.min.js"></script>
<script src="/cdn/js/angular/1.5.5/angular.min.js"></script>
<title>Ludotheque v2.0</title>
</head>
<body ng-cloak>
<div ng-view></div>
<!-- Placed at the end of the document so the pages load faster -->
<script src="/cdn/js/angular/1.5.5/angular-route.min.js"></script>
<script src="/cdn/js/angular/1.5.5/angular-resource.min.js"></script>
<script src="js/app.js"></script>
<script src="js/routes.js"></script>
<script src="js/controllers/payment_methods_index_controller.js"></script>
<script src="js/controllers/payment_methods_edit_controller.js"></script>
<script src="js/controllers/payment_methods_create_controller.js"></script>
<script src="js/resources/payment_method.js"></script>
</body>
</html>
(function(){
angular.module('ludotheque', ['ngRoute', 'ngResource']);
})();
angular.module('ludotheque').controller('PaymentMethodsCreateController', function($scope, PaymentMethod) {
// Create a new blank ... no thanks
$scope.payment_method = new PaymentMethod();
$scope.createPaymentMethod = function(payment_method) {
$scope.errors = null;
$scope.updating = true;
payment_method.$create().catch(function(payment_methodData) {
$scope.errors = [payment_methodData.data.error];
}).finally(function() {
$scope.updating = false;
});
};
});
angular.module('ludotheque').controller('PaymentMethodsEditController', function($scope, $routeParams, PaymentMethod) {
$scope.payment_method = PaymentMethod.get({id: $routeParams.id})
$scope.updatePaymentMethod = function(payment_method) {
$scope.errors = null;
$scope.updating = true;
payment_method.$update().catch(function(payment_methodData) {
$scope.errors = [payment_methodData.data.error];
}).finally(function() {
$scope.updating = false;
});
};
});
angular.module('ludotheque').controller('PaymentMethodsIndexController', function($scope, PaymentMethod) {
// Without NgResource
// Note.all().success(function(data) {
// $scope.notes = data;
// });
// With NgResource
$scope.payment_methods = PaymentMethod.query();
});
/*
This is a way of handling ajax requests using NgResource, it performs a similar function
to the Note Service.
*/
angular.module('ludotheque').factory('PaymentMethod', function PaymentMethodFactory($resource) {
return $resource('rest/payment_methods/:id', {}, {
update: {
method: "PUT"
},
create: {
method: "POST"
}
});
});
(function(){
angular.module('ludotheque').config(function($routeProvider){
$routeProvider.when('/payment_methods', {
templateUrl: 'views/payment_methods/ng_index.html',
controller: 'PaymentMethodsIndexController'
})
.when('/payment_methods/new', {
templateUrl: 'views/payment_methods/ng_new.html',
controller: 'PaymentMethodsCreateController'
})
.when('/payment_methods/:id', {
templateUrl: 'views/payment_methods/ng_edit.html',
controller: 'PaymentMethodsEditController'
})
.when('/', {
templateUrl: 'views/ng_index.html'
})
.otherwise({
redirectTo: '/'
});
});
})();
<a href="#/payment_methods">Payment methods</a>
<div class="new-payment_method">
<div class="new-payment_method-container">
<ul class='errors' ng-if="errors">
<li ng-repeat="error in errors">{{error}}</li>
</ul>
<form class="form">
<fieldset class="form-field">
<label class="form-label" for="name">Name</label>
<input class="form-input" name="name" ng-model="payment_method.name" />
</fieldset>
<fieldset class="form-field">
<label class="form-label" for="description">Description</label>
<textarea class="form-input" name="description" ng-model="payment_method.description" placeholder="A short description of this payment_method"></textarea>
</fieldset>
<button class="btn" ng-click="updatePaymentMethod(payment_method)" ng-disabled="updating">{{updating ? 'Saving...' : 'Save'}}</button>
</form>
</div>
</div>
<div ng-repeat="payment_method in payment_methods">
<a ng-href="#/payment_methods/{{payment_method.id}}">
{{ payment_method.name }} - {{ payment_method.description }}</a>
</div>
<div>
<a href="#/payment_methods/new">Nouvelle méthode de paiement</a>
</div>
<div class="new-payment_method">
<div class="new-payment_method-container">
<ul class='errors' ng-if="errors">
<li ng-repeat="error in errors">{{error}}</li>
</ul>
<form class="form">
<fieldset class="form-field">
<label class="form-label" for="name">Name</label>
<input class="form-input" name="name" ng-model="payment_method.name" />
</fieldset>
<fieldset class="form-field">
<label class="form-label" for="description">Description</label>
<textarea class="form-input" name="description" ng-model="payment_method.description" placeholder="A short description of this payment_method"></textarea>
</fieldset>
<button class="btn" ng-click="createPaymentMethod(payment_method)" ng-disabled="updating">{{updating ? 'Saving...' : 'Save'}}</button>
</form>
</div>
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment