admin: display publication confirmation; show an alert when empty scene

This commit is contained in:
nemunaire 2017-11-21 22:23:49 +01:00 committed by Pierre-Olivier Mercier
parent f2089c4d96
commit eefac93091
2 changed files with 19 additions and 6 deletions

View file

@ -75,7 +75,7 @@ angular.module("FICApp")
}) })
.factory("Scene", function($resource) { .factory("Scene", function($resource) {
return $resource("/api/public.json", null, { return $resource("/api/public.json", null, {
'update': {method: 'PUT'}, 'update': {method: 'PUT', isArray: true},
}) })
}) })
.factory("Team", function($resource) { .factory("Team", function($resource) {
@ -368,7 +368,7 @@ angular.module("FICApp")
}; };
}) })
.controller("PublicController", function($scope, Scene, Theme, Teams, Exercice) { .controller("PublicController", function($scope, $rootScope, Scene, Theme, Teams, Exercice) {
$scope.scenes = Scene.query(); $scope.scenes = Scene.query();
$scope.themes = Theme.query(); $scope.themes = Theme.query();
$scope.teams = Teams.get(); $scope.teams = Teams.get();
@ -403,23 +403,31 @@ angular.module("FICApp")
$scope.exercices = Exercice.query(); $scope.exercices = Exercice.query();
$scope.clearScene = function() { $scope.clearScene = function() {
Scene.delete(function() { $scope.someUpdt = true;
$scope.scenes = []; $scope.scenes = [];
});
}; };
$scope.saveScenes = function() { $scope.saveScenes = function() {
Scene.update($scope.scenes); $scope.someUpdt = false;
var prms = Scene.update($scope.scenes);
prms.$promise.then(function() {
$rootScope.newBox('success', 'Scene successfully published!');
}, function(response) {
$rootScope.newBox('danger', 'An error occurs when saving scene:', response.data);
});
}; };
$scope.addScene = function() { $scope.addScene = function() {
$scope.someUpdt = true;
$scope.scenes.push({params: {}}); $scope.scenes.push({params: {}});
}; };
$scope.delScene = function(s) { $scope.delScene = function(s) {
$scope.someUpdt = true;
angular.forEach($scope.scenes, function(scene, k) { angular.forEach($scope.scenes, function(scene, k) {
if (scene == s) if (scene == s)
$scope.scenes.splice(k, 1); $scope.scenes.splice(k, 1);
}); });
}; };
$scope.upScene = function(s) { $scope.upScene = function(s) {
$scope.someUpdt = true;
angular.forEach($scope.scenes, function(scene, k) { angular.forEach($scope.scenes, function(scene, k) {
if (scene == s && k > 0) { if (scene == s && k > 0) {
$scope.scenes.splice(k, 1); $scope.scenes.splice(k, 1);
@ -428,6 +436,7 @@ angular.module("FICApp")
}); });
}; };
$scope.downScene = function(s) { $scope.downScene = function(s) {
$scope.someUpdt = true;
var move = true; var move = true;
angular.forEach($scope.scenes, function(scene, k) { angular.forEach($scope.scenes, function(scene, k) {
if (move && scene == s) { if (move && scene == s) {

View file

@ -2,6 +2,10 @@
<h2>Interface publique<a ng-click="clearScene()" class="pull-right btn btn-danger"><span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span> Vider la scène</a><a ng-click="addScene()" class="pull-right btn btn-primary" style="margin-right: 10px"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter un élément</a><button type="submit" style="margin-right: 10px" class="pull-right btn btn-success"><span class="glyphicon glyphicon-save" aria-hidden="true"></span> Publier cette scène</button> <h2>Interface publique<a ng-click="clearScene()" class="pull-right btn btn-danger"><span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span> Vider la scène</a><a ng-click="addScene()" class="pull-right btn btn-primary" style="margin-right: 10px"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter un élément</a><button type="submit" style="margin-right: 10px" class="pull-right btn btn-success"><span class="glyphicon glyphicon-save" aria-hidden="true"></span> Publier cette scène</button>
</h2> </h2>
<div class="alert alert-info" ng-if="!scenes.length">
<strong ng-if="!someUpdt">Aucun contenu n'est actuellement affiché.</strong>
<strong ng-if="someUpdt">Aucun contenu à afficher.</strong>
</div>
<div class="well" ng-repeat="scene in scenes"> <div class="well" ng-repeat="scene in scenes">
<div class="form-group"> <div class="form-group">
<div class="col-sm-offset-2 col-sm-6"> <div class="col-sm-offset-2 col-sm-6">