Merge pull request #1995 from emanuelschuetze/fix1991

Add/Remove a group to selected users (Fixes #1991)
This commit is contained in:
Norman Jäckel 2016-02-23 23:37:57 +01:00
commit 73cc1a5dfb
2 changed files with 71 additions and 20 deletions

View File

@ -421,17 +421,17 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
$scope.alert = { type: 'danger', msg: message, show: true }; $scope.alert = { type: 'danger', msg: message, show: true };
}); });
}; };
// *** delete mode functions *** // *** select mode functions ***
$scope.isDeleteMode = false; $scope.isSelectMode = false;
// check all checkboxes // check all checkboxes
$scope.checkAll = function () { $scope.checkAll = function () {
angular.forEach($scope.users, function (user) { angular.forEach($scope.users, function (user) {
user.selected = $scope.selectedAll; user.selected = $scope.selectedAll;
}); });
}; };
// uncheck all checkboxes if isDeleteMode is closed // uncheck all checkboxes if isSelectMode is closed
$scope.uncheckAll = function () { $scope.uncheckAll = function () {
if (!$scope.isDeleteMode) { if (!$scope.isSelectMode) {
$scope.selectedAll = false; $scope.selectedAll = false;
angular.forEach($scope.users, function (user) { angular.forEach($scope.users, function (user) {
user.selected = false; user.selected = false;
@ -441,16 +441,42 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
// delete all selected users // delete all selected users
$scope.deleteMultiple = function () { $scope.deleteMultiple = function () {
angular.forEach($scope.users, function (user) { angular.forEach($scope.users, function (user) {
if (user.selected) if (user.selected) {
User.destroy(user.id); User.destroy(user.id);
}
}); });
$scope.isDeleteMode = false; $scope.isSelectMode = false;
$scope.uncheckAll(); $scope.uncheckAll();
}; };
// delete single user // delete single user
$scope.delete = function (user) { $scope.delete = function (user) {
User.destroy(user.id); User.destroy(user.id);
}; };
// add group for selected users
$scope.addGroupMultiple = function (group) {
angular.forEach($scope.users, function (user) {
if (user.selected) {
user.groups.push(group);
User.save(user);
}
});
$scope.isSelectMode = false;
$scope.uncheckAll();
};
// remove group for selected users
$scope.removeGroupMultiple = function (group) {
angular.forEach($scope.users, function (user) {
if (user.selected) {
var groupIndex = user.groups.indexOf(parseInt(group));
if (groupIndex > -1) {
user.groups.splice(groupIndex, 1);
User.save(user);
}
}
});
$scope.isSelectMode = false;
$scope.uncheckAll();
};
} }
]) ])

View File

@ -39,10 +39,10 @@
<div class="details"> <div class="details">
<div class="row"> <div class="row">
<div class="col-sm-6"> <div class="col-sm-6">
<!-- delete mode --> <!-- select mode -->
<button os-perms="users.can_manage" class="btn" <button os-perms="users.can_manage" class="btn"
ng-class="$parent.isDeleteMode ? 'btn-primary' : 'btn-default'" ng-class="$parent.isSelectMode ? 'btn-primary' : 'btn-default'"
ng-click="$parent.isDeleteMode = !$parent.isDeleteMode; uncheckAll()"> ng-click="$parent.isSelectMode = !$parent.isSelectMode; uncheckAll()">
<i class="fa fa-check-square-o"></i> <i class="fa fa-check-square-o"></i>
<translate>Select ...</translate> <translate>Select ...</translate>
</button> </button>
@ -77,15 +77,40 @@
<translate>Is present</translate> <translate>Is present</translate>
</div> </div>
</div> </div>
<div uib-collapse="!isDeleteMode" class="row spacer"> <div uib-collapse="!isSelectMode" class="row spacer">
<div class="col-sm-12 text-left"> <div os-perms="users.can_manage" ng-show="isSelectMode" class="col-sm-12 text-left form-inline">
<!-- actions -->
<select ng-model="selectedAction" class="form-control">
<option value="" translate>--- Select action ---</option>
<option value="delete" translate>Delete</option>
<option value="addGroup" translate>Add group</option>
<option value="removeGroup" translate>Remove group</option>
</select>
<!-- delete button --> <!-- delete button -->
<a ng-show="isDeleteMode" <a ng-show="selectedAction == 'delete'"
os-perms="users.can_manage" ng-click="deleteMultiple()" ng-click="deleteMultiple()"
class="btn btn-primary"> class="btn btn-default">
<i class="fa fa-trash fa-lg"></i> <i class="fa fa-trash fa-lg"></i>
<translate>Delete selected participants</translate> <translate>Delete selected participants</translate>
</a> </a>
<!-- group select -->
<select ng-show="selectedAction == 'addGroup' || selectedAction == 'removeGroup'"
ng-model="selectedGroup" class="form-control">
<option value="" translate>--- Select group ---</option>
<option ng-repeat="group in groups" value="{{ group.id }}">{{ group.name | translate }}</option>
</select>
<!-- add group button -->
<a ng-show="selectedAction == 'addGroup'"
ng-click="addGroupMultiple(selectedGroup)" class="btn btn-default">
<i class="fa fa-plus fa-lg"></i>
<translate>Add group</translate>
</a>
<!-- remove group button -->
<a ng-show="selectedAction == 'removeGroup'"
ng-click="removeGroupMultiple(selectedGroup)" class="btn btn-default">
<i class="fa fa-minus fa-lg"></i>
<translate>Remove group</translate>
</a>
</div> </div>
</div> </div>
@ -106,9 +131,9 @@
<thead> <thead>
<tr> <tr>
<!-- projector column --> <!-- projector column -->
<th ng-show="!isDeleteMode" os-perms="core.can_manage_projector" class="minimum"> <th ng-show="!isSelectMode" os-perms="core.can_manage_projector" class="minimum">
<!-- delete selection column --> <!-- selection column -->
<th ng-show="isDeleteMode" os-perms="users.can_manage" class="minimum deleteColumn"> <th ng-show="isSelectMode" os-perms="users.can_manage" class="minimum deleteColumn">
<input type="checkbox" ng-model="$parent.selectedAll" ng-change="checkAll()"> <input type="checkbox" ng-model="$parent.selectedAll" ng-change="checkAll()">
<th ng-click="toggleSort('first_name')" class="sortable"> <th ng-click="toggleSort('first_name')" class="sortable">
<translate>Name</translate> <translate>Name</translate>
@ -135,15 +160,15 @@
<tr ng-repeat="user in usersFiltered | limitTo : itemsPerPage : limitBegin" class="animate-item" <tr ng-repeat="user in usersFiltered | limitTo : itemsPerPage : limitBegin" class="animate-item"
ng-class="{ 'activeline': user.isProjected(), 'selected': user.selected }"> ng-class="{ 'activeline': user.isProjected(), 'selected': user.selected }">
<!-- projector column --> <!-- projector column -->
<td ng-show="!isDeleteMode" os-perms="core.can_manage_projector"> <td ng-show="!isSelectMode" os-perms="core.can_manage_projector">
<a class="btn btn-default btn-sm" <a class="btn btn-default btn-sm"
ng-class="{ 'btn-primary': user.isProjected() }" ng-class="{ 'btn-primary': user.isProjected() }"
ng-click="user.project()" ng-click="user.project()"
title="{{ 'Project user' | translate }}"> title="{{ 'Project user' | translate }}">
<i class="fa fa-video-camera"></i> <i class="fa fa-video-camera"></i>
</a> </a>
<!-- delete selection column --> <!-- selection column -->
<td ng-show="isDeleteMode" os-perms="users.can_manage" class="deleteColumn"> <td ng-show="isSelectMode" os-perms="users.can_manage" class="deleteColumn">
<input type="checkbox" ng-model="user.selected"> <input type="checkbox" ng-model="user.selected">
<!-- user data colums --> <!-- user data colums -->
<td ng-mouseover="user.hover=true" ng-mouseleave="user.hover=false"> <td ng-mouseover="user.hover=true" ng-mouseleave="user.hover=false">