Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="fr" ng-app="demoApp">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
  6. <meta name="format-detection" content="telephone=no">
  7. <meta name="msapplication-tap-highlight" content="no">
  8. <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
  9. <link rel="stylesheet" type="text/css" href="css/style.css">
  10. <title>Pense-bête</title>
  11. </head>
  12. <script type="text/javascript" src="cordova.js"></script>
  13. <script type="text/javascript" src="js/index.js"></script>
  14. <script type="text/javascript" src="js/angular.js"></script>
  15. <script type="text/javascript" src="js/todoList.js"></script>
  16.  
  17. <body>
  18. <header>
  19. <h1>Pense-bête</h1>
  20. </header>
  21. <section ng-controller="todoCtrl">
  22. <form id="todo-form" ng-submit="addTodo()">
  23. <input id="new-todo" placeholder="Que voulez-vous acheter ?" ng-model="newTodo" />
  24. </form>
  25. <article ng-show="todos.length">
  26. <ul id="todo-list">
  27. <li ng-repeat="todo in todos" ng-class="{completed: todo.completed}">
  28. <div class="view">
  29. <input class="mark" type="checkbox" ng-model="todo.completed" />
  30. <span>{{todo.title}}</span>
  31. <span class="close" ng-click="removeTodo(todo)">x</span>
  32. </div>
  33. </li>
  34. </ul>
  35. <div>
  36. <input id="mark-all" type="checkbox" ng-model="allChecked" ng-click="markAll(allChecked)" />
  37. <label class="btn btn-info" for="mark-all">Tout cocher</label>
  38. <button class="btn btn-danger" ng-click="clearCompletedTodos()">Supprimer les tâches cochées</button>
  39.  
  40. <button class="glyphicon glyphicon-refresh" ng-click="savedata()">Synchroniser ma liste</button>
  41. </div>
  42. <div class="view" ng-model="result">
  43. <span>{{result}}</span>
  44. </div>
  45. </article>
  46. </section>
  47. </body>
  48. </html>
  49.  
  50. // js/todoList.js
  51. 'use strict';
  52.  
  53.  
  54. /**
  55. * Déclaration de l'application demoApp
  56. */
  57. var demoApp = angular.module('demoApp', [
  58. // Dépendances du "module"
  59. 'todoList'
  60. ]);
  61.  
  62. /**
  63. * Déclaration du module todoList
  64. */
  65. var todoList = angular.module('todoList',[]);
  66.  
  67.  
  68. /**
  69. * Contrôleur de l'application "Todo List" décrite dans le chapitre "La logique d'AngularJS".
  70. */
  71. todoList.controller('todoCtrl', ['$scope','$http',
  72. function ($scope,$http) {
  73.  
  74. // Pour manipuler plus simplement les todos au sein du contrôleur
  75. // On initialise les todos avec un tableau vide : []
  76. var todos = $scope.todos = [];
  77. $scope.url = 'js/todolist_updater.php';
  78.  
  79. // Ajouter un todo
  80. $scope.addTodo = function () {
  81.  
  82. var newTodo = $scope.newTodo.trim();
  83. if (!newTodo.length) {
  84. return;
  85. }
  86.  
  87. todos.push({
  88. // on ajoute le todo au tableau des todos
  89. title: newTodo,
  90. completed: false
  91. });
  92. // Réinitialisation de la variable newTodo
  93. $scope.newTodo = '';
  94. };
  95.  
  96. // Enlever un todo
  97. $scope.removeTodo = function (todo) {
  98. todos.splice(todos.indexOf(todo), 1);
  99. };
  100.  
  101. // Cocher / Décocher tous les todos
  102. $scope.markAll = function (completed) {
  103. todos.forEach(function (todo) {
  104. todo.completed = !completed;
  105. });
  106. };
  107.  
  108. // Enlever tous les todos cochés
  109. $scope.clearCompletedTodos = function () {
  110. $scope.todos = todos = todos.filter(function (todo) {
  111. return !todo.completed;
  112. });
  113. };
  114.  
  115. $scope.savedata = function($type_maj,$data,$uid) {
  116. $type_maj="create";
  117. $uid="0";
  118. // Create the http post request
  119. // the data holds the keywords
  120. // The request is a JSON request.
  121. $http.post($scope.url, { "data" : $type_maj + "/" + $data + "/" + $uid}).
  122. success(function(data, status) {
  123. $scope.status = status;
  124. $scope.data = data;
  125. $scope.result = data; // Show result from server in our <pre></pre> element
  126. })
  127. .
  128. error(function(data, status) {
  129. $scope.data = data || "Request failed";
  130. $scope.status = status;
  131. });
  132.  
  133. }
  134.  
  135. }
  136. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement