Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="fr" ng-app="demoApp">
- <head>
- <meta charset="utf-8" />
- <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 *">
- <meta name="format-detection" content="telephone=no">
- <meta name="msapplication-tap-highlight" content="no">
- <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
- <link rel="stylesheet" type="text/css" href="css/style.css">
- <title>Pense-bête</title>
- </head>
- <script type="text/javascript" src="cordova.js"></script>
- <script type="text/javascript" src="js/index.js"></script>
- <script type="text/javascript" src="js/angular.js"></script>
- <script type="text/javascript" src="js/todoList.js"></script>
- <body>
- <header>
- <h1>Pense-bête</h1>
- </header>
- <section ng-controller="todoCtrl">
- <form id="todo-form" ng-submit="addTodo()">
- <input id="new-todo" placeholder="Que voulez-vous acheter ?" ng-model="newTodo" />
- </form>
- <article ng-show="todos.length">
- <ul id="todo-list">
- <li ng-repeat="todo in todos" ng-class="{completed: todo.completed}">
- <div class="view">
- <input class="mark" type="checkbox" ng-model="todo.completed" />
- <span>{{todo.title}}</span>
- <span class="close" ng-click="removeTodo(todo)">x</span>
- </div>
- </li>
- </ul>
- <div>
- <input id="mark-all" type="checkbox" ng-model="allChecked" ng-click="markAll(allChecked)" />
- <label class="btn btn-info" for="mark-all">Tout cocher</label>
- <button class="btn btn-danger" ng-click="clearCompletedTodos()">Supprimer les tâches cochées</button>
- <button class="glyphicon glyphicon-refresh" ng-click="savedata()">Synchroniser ma liste</button>
- </div>
- <div class="view" ng-model="result">
- <span>{{result}}</span>
- </div>
- </article>
- </section>
- </body>
- </html>
- // js/todoList.js
- 'use strict';
- /**
- * Déclaration de l'application demoApp
- */
- var demoApp = angular.module('demoApp', [
- // Dépendances du "module"
- 'todoList'
- ]);
- /**
- * Déclaration du module todoList
- */
- var todoList = angular.module('todoList',[]);
- /**
- * Contrôleur de l'application "Todo List" décrite dans le chapitre "La logique d'AngularJS".
- */
- todoList.controller('todoCtrl', ['$scope','$http',
- function ($scope,$http) {
- // Pour manipuler plus simplement les todos au sein du contrôleur
- // On initialise les todos avec un tableau vide : []
- var todos = $scope.todos = [];
- $scope.url = 'js/todolist_updater.php';
- // Ajouter un todo
- $scope.addTodo = function () {
- var newTodo = $scope.newTodo.trim();
- if (!newTodo.length) {
- return;
- }
- todos.push({
- // on ajoute le todo au tableau des todos
- title: newTodo,
- completed: false
- });
- // Réinitialisation de la variable newTodo
- $scope.newTodo = '';
- };
- // Enlever un todo
- $scope.removeTodo = function (todo) {
- todos.splice(todos.indexOf(todo), 1);
- };
- // Cocher / Décocher tous les todos
- $scope.markAll = function (completed) {
- todos.forEach(function (todo) {
- todo.completed = !completed;
- });
- };
- // Enlever tous les todos cochés
- $scope.clearCompletedTodos = function () {
- $scope.todos = todos = todos.filter(function (todo) {
- return !todo.completed;
- });
- };
- $scope.savedata = function($type_maj,$data,$uid) {
- $type_maj="create";
- $uid="0";
- // Create the http post request
- // the data holds the keywords
- // The request is a JSON request.
- $http.post($scope.url, { "data" : $type_maj + "/" + $data + "/" + $uid}).
- success(function(data, status) {
- $scope.status = status;
- $scope.data = data;
- $scope.result = data; // Show result from server in our <pre></pre> element
- })
- .
- error(function(data, status) {
- $scope.data = data || "Request failed";
- $scope.status = status;
- });
- }
- }
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement