Advertisement
Shaco74

todos.html

Nov 26th, 2021
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!doctype html>
  2. <html>
  3. <head>
  4.   <meta charset="utf-8"/>
  5.   <title>Todo REST service</title>
  6.   <link rel="stylesheet" href="https://unpkg.com/wingcss"/>
  7.   <!-- Load AngularJS -->
  8.   <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
  9.   <script type="text/javascript">
  10.     var app = angular.module("TodoManagement", []);
  11.  
  12.     //Controller Part
  13.     app.controller("TodoManagementController", function ($scope, $http) {
  14.  
  15.       //Initialize page with default data which is blank in this example
  16.       $scope.todos = [];
  17.  
  18.       $scope.form = {
  19.         name: "",
  20.         status: true
  21.       };
  22.  
  23.       //Now load the data from server
  24.       _refreshPageData();
  25.  
  26.       //HTTP POST methods for add fruits
  27.       $scope.add = function () {
  28.         var data = { "name": $scope.form.name, "finished": $scope.form.status };
  29.  
  30.         $http({
  31.           method: "POST",
  32.           url: '/todos',
  33.           data: angular.toJson(data),
  34.           headers: {
  35.             'Content-Type': 'application/json'
  36.           }
  37.         }).then(_success, _error);
  38.       };
  39.  
  40.       /* Private Methods */
  41.       //HTTP GET- get all fruits collection
  42.       function _refreshPageData() {
  43.         $http({
  44.           method: 'GET',
  45.           url: '/todos'
  46.         }).then(function successCallback(response) {
  47.           $scope.todos = response.data;
  48.         }, function errorCallback(response) {
  49.           console.log(response.statusText);
  50.         });
  51.       }
  52.  
  53.       function _success(response) {
  54.         _refreshPageData();
  55.         _clearForm();
  56.       }
  57.  
  58.       function _error(response) {
  59.         alert(response.data.message || response.statusText);
  60.       }
  61.  
  62.       //Clear the form
  63.       function _clearForm() {
  64.         $scope.form.name = "";
  65.         $scope.form.status = "";
  66.       }
  67.     });
  68.   </script>
  69. </head>
  70. <body ng-app="TodoManagement" ng-controller="TodoManagementController">
  71.  
  72. <div class="container">
  73.   <h1>REST Service - Todo</h1>
  74.  
  75.   <h3>Add a Todo</h3>
  76.   <form ng-submit="add()">
  77.     <div class="row">
  78.       <div style="display: flex; flex-direction: column; align-items: center;gap: 0px;    justify-content: center;">
  79.         <pre style="margin: 5px;">Erledigt</pre>
  80.         <input type="checkbox"   ng-model="form.status" size="60"/>
  81.       </div>
  82.       <div class="col-8"><input type="text" placeholder="Name" ng-model="form.name" size="60"/></div>
  83.     </div>
  84.     <input type="submit" value="Save"/>
  85.   </form>
  86.  
  87.   <h3>Todo List</h3>
  88.   <div class="row">
  89.     <div class="col-4">Name</div>
  90.     <div class="col-8">Status</div>
  91.     <div class="col-9">Status</div>
  92.   </div>
  93.   <div class="row" ng-repeat="todo in todos">
  94.     <div class="col-4">{{ todo.name }}</div>
  95.     <div class="col-8">{{ todo.status }}</div>
  96.    
  97.     <div class="col-9">{{ todo.status }}</div>
  98.   </div>
  99. </div>
  100.  
  101. </body>
  102. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement