[admin] Add events

This commit is contained in:
nemunaire 2016-12-26 03:44:04 +01:00 committed by Pierre-Olivier Mercier
commit b6782962f1
5 changed files with 187 additions and 1 deletions

View file

@ -33,6 +33,14 @@ angular.module("FICApp", ["ngRoute", "ngResource", "ngSanitize"])
controller: "TeamNewController",
templateUrl: "views/team-new.html"
})
.when("/events", {
controller: "EventsListController",
templateUrl: "views/event-list.html"
})
.when("/events/:eventId", {
controller: "EventController",
templateUrl: "views/event.html"
})
.when("/", {
templateUrl: "views/home.html"
});
@ -43,6 +51,11 @@ angular.module("FICApp")
.factory("Version", function($resource) {
return $resource("/api/version")
})
.factory("Event", function($resource) {
return $resource("/api/events/:eventId", { eventId: '@id' }, {
'update': {method: 'PUT'},
})
})
.factory("Team", function($resource) {
return $resource("/api/teams/:teamId", { teamId: '@id' }, {
'update': {method: 'PUT'},
@ -166,6 +179,42 @@ angular.module("FICApp")
$scope.v = Version.get();
})
.controller("EventsListController", function($scope, Event, $location) {
$scope.events = Event.query();
$scope.fields = ["id", "kind", "txt", "time"];
$scope.clearEvents = function(id) {
Event.delete(function() {
$scope.events = [];
});
};
$scope.show = function(id) {
$location.url("/events/" + id);
};
})
.controller("EventController", function($scope, Event, $routeParams, $location) {
$scope.event = Event.get({ eventId: $routeParams.eventId });
$scope.fields = ["kind", "txt", "time"];
$scope.kinds = {
"alert-info": "Info",
"alert-warning": "Warning",
"alert-success": "Success"
};
$scope.saveEvent = function() {
if (this.event.id) {
this.event.$update();
} else {
this.event.$save(function() {
$location.url("/events/" + $scope.event.id);
});
}
}
$scope.deleteEvent = function() {
this.event.$remove(function() { $location.url("/events/");});
}
})
.controller("ThemesListController", function($scope, Theme, $location) {
$scope.themes = Theme.query();
$scope.fields = ["id", "name"];

View file

@ -0,0 +1,19 @@
<h2>&Eacute;vénements<a ng-click="clearEvents()" class="pull-right btn btn-danger"><span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span> Vider la liste</a><a ng-click="show('new')" class="pull-right btn btn-primary" style="margin-right: 10px"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter un événement</a></h2>
<p><input type="search" class="form-control" placeholder="Search" ng-model="query"></p>
<table class="table table-hover table-bordered">
<thead>
<tr>
<th ng-repeat="field in fields">
{{ field }}
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="event in events | filter: query" ng-click="show(event.id)">
<td ng-repeat="field in fields">
{{ event[field] }}
</td>
</tr>
</tbody>
</table>

View file

@ -0,0 +1,20 @@
<h2>&Eacute;vénement</h2>
<form ng-submit="saveEvent()" class="form-horizontal">
<div class="form-group" ng-repeat="field in fields">
<label for="{{ field }}" class="col-sm-1 control-label">{{ field | capitalize }}</label>
<div class="col-sm-11">
<input type="text" class="form-control" id="{{ field }}" ng-model="event[field]" ng-show="field != 'kind' && field != 'time'">
<input type="datetime" class="form-control" id="{{ field }}" ng-model="event[field]" ng-show="field == 'time' && event.id">
<select class="form-control" id="{{ field }}" ng-model="event[field]" ng-options="k as v for (k, v) in kinds" ng-show="field == 'kind'">
</select>
</div>
</div>
<div class="text-right" ng-show="event.id">
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-save" aria-hidden="true"></span> Save</button>
<a class="btn btn-danger" ng-click="deleteEvent()"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</a>
</div>
<div class="text-right" ng-show="!event.id">
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter l'événement</button>
</div>
</form>