1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| <!DOCTYPE html>
<html ng-app="app">
<head lang="en">
<meta charset="UTF-8">
<title>Angular Firebase</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<!-- CHARGEMENT DES LIBRAIRIES -->
<!-- CHARGEMENT LIB ANGULAR -->
<script type="text/javascript" src="angular-1.3.13/angular.min.js"></script>
<script src="angular-route.min.js"></script>
<script src="librairies/angular-locale_fr-fr.js"></script>
<!-- CHARGEMENT LIB FIREBASE -->
<script src='https://cdn.firebase.com/js/client/2.2.1/firebase.js'></script>
<!-- AngularFire -->
<script src="https://cdn.firebase.com/libs/angularfire/1.1.3/angularfire.min.js"></script>
<!-- CSS DE L'APPLICATION -->
<link href="truc34.css" media="screen" rel="stylesheet" type="text/css" />
<!-- FIN DE CHARGEMENT DES LIBRAIRIES -->
<script>
var app = angular.module('app', ['firebase']);
app.constant('FIREBASE_URI', 'https://blinding-heat-xxxx.firebaseio.com/testing/');
app.controller('MainCtrl', ['$scope', 'ItemsService', function ($scope, ItemsService) {
$scope.newItem = { name: "", description: "", count: "","members": [{"nom": "jose"},{"nom": "thierry"}]};
$scope.currentItem = null;
$scope.i = "nouveau";
$scope.items = ItemsService.getItems();
$scope.addItem = function () {
ItemsService.addItem(angular.copy($scope.newItem));
$scope.newItem = { name: '', description: '', count: 0 };// reinit du formulaire
};
$scope.updateItem = function (id) {
ItemsService.updateItem(id);
};
$scope.removeItem = function (id) {
ItemsService.removeItem(id);
};
$scope.addMember = function (id,i){
$scope.items[id].members.push({"nom":i})
ItemsService.updateItem(id);
};
}]);
app.factory('ItemsService', ['$firebaseArray', 'FIREBASE_URI', function ($firebaseArray, FIREBASE_URI) {
var ref = new Firebase(FIREBASE_URI);
var items = $firebaseArray(ref);
var getItems = function () {
return items;
};
var addItem = function (item) {
items.$add(item);
};
var updateItem = function (id) {
items.$save(id);
};
var removeItem = function (id) {
items.$remove(id);
};
return {
getItems: getItems,
addItem: addItem,
updateItem: updateItem,
removeItem: removeItem
}
}]);
</script>
</head>
<body ng-controller="MainCtrl">
<table class="table edit">
<thead>
<tr>
<th>Nom</th>
<th>Description</th>
<th>Effectif</th>
<th>Suppression</th>
<th>Nouveau Membre</th>
<th>Ajout Membres</th>
<th>Membres</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="(id, item) in items">
<td><input type="text" ng-model="item.name" ng-blur="updateItem(id)"/></td>
<td><input type="text" ng-model="item.description" ng-blur="updateItem(id)"/></td>
<td><input type="text" ng-model="item.count" ng-blur="updateItem(id)"/></td>
<td><a href="#" ng-click="removeItem(id)" class="navbar-link">Supprimer </a></td>
<td><input type="text" ng-model="i" />{{i}}</td>
<td><button class="btn btn-default" ng-click="addMember(id,i)">Ajouter membre</button></td>
<td><span ng-repeat="membre in item.members">{{membre.nom}}<span>
</td>
</tr>
</tbody>
</table>
<div class="well">
<h4>Ajouter une Classe</h4>
Général:
<form class="form-inline" role="form" novalidate ng-submit="addItem()">
<div class="form-group">
<input type="text" class="form-control" ng-model="newItem.name" placeholder="Nom">
</div>
<div class="form-group">
<input type="text" class="form-control" ng-model="newItem.description" placeholder="Description">
</div>
<div class="form-group">
<input type="text" class="form-control" ng-model="newItem.count" placeholder="Effectif">
</div>
<button type="submit" class="btn btn-default">Ajouter</button>
</form>
</div>
</body>
</html> |
Partager