admin: can perform mass editing on exercices

This commit is contained in:
nemunaire 2018-11-21 01:19:13 +01:00 committed by Pierre-Olivier Mercier
commit 6b54704d59
4 changed files with 97 additions and 9 deletions

View file

@ -205,7 +205,8 @@ angular.module("FICApp")
})
.factory("Exercice", function($resource) {
return $resource("/api/exercices/:exerciceId", { exerciceId: '@id' }, {
update: {method: 'PUT'}
update: {method: 'PUT'},
patch: {method: 'PATCH'}
})
})
.factory("ExerciceTags", function($resource) {
@ -962,10 +963,27 @@ angular.module("FICApp")
};
})
.controller("AllExercicesListController", function($scope, Exercice, $routeParams, $location, $rootScope, $http) {
.controller("AllExercicesListController", function($scope, Exercice, $routeParams, $location, $rootScope, $http, $filter) {
$scope.exercices = Exercice.query();
$scope.exercice = {}; // Array used to save fields to updates in selected exercices
$scope.fields = ["title", "overview"];
$scope.toggleSelectAll = function() {
angular.forEach($filter('filter')($scope.exercices, $scope.query), function(ex) {
ex.selected = !$scope.selectall
})
}
$scope.updateExercices = function() {
angular.forEach($scope.exercices, function(ex) {
if (ex.selected) {
Exercice.patch({exerciceId: ex.id}, $scope.exercice);
}
})
$scope.exercice = {};
$rootScope.newBox('success', 'Édition de masse terminée avec succès');
}
$scope.show = function(id) {
$location.url("/exercices/" + id);
};