Make group buttons toggle able

This commit is contained in:
Johannes Zellner
2016-02-10 14:39:49 +01:00
parent 36ded4c06a
commit c1280ddcc2
2 changed files with 11 additions and 2 deletions

View File

@@ -125,7 +125,7 @@
<div class="form-group">
<label class="control-label" for="inputUserEditGroups">Groups</label>
<div>
<button class="btn btn-default" data-toggle="button" ng-repeat="group in groups" ng-click="userEditToggleGroup(group);">{{ group.name }}</button>
<button class="btn btn-default" type="button" ng-repeat="group in groups" ng-click="userEditToggleGroup(group);" ng-class="{ 'btn-primary': (useredit.groupIds.indexOf(group.id) !== -1) }">{{ group.name }}</button>
</div>
</div>
<div class="form-group" ng-class="{ 'has-error': (useredit_form.password.$dirty && useredit_form.password.$invalid) || (!useredit_form.password.$dirty && useredit.error.password)}">

View File

@@ -135,7 +135,7 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
$scope.useredit.displayName = userInfo.displayName;
$scope.useredit.email = userInfo.email;
$scope.useredit.userInfo = userInfo;
$scope.useredit.groups = userInfo.groupIds;
$scope.useredit.groupIds = angular.copy(userInfo.groupIds);
$scope.useredit_form.$setPristine();
$scope.useredit_form.$setUntouched();
@@ -143,6 +143,15 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
$('#userEditModal').modal('show');
};
$scope.userEditToggleGroup = function (group) {
var pos = $scope.useredit.groupIds.indexOf(group.id);
if (pos === -1) {
$scope.useredit.groupIds.push(group.id);
} else {
$scope.useredit.groupIds.splice(pos, 1);
}
};
$scope.doUserEdit = function () {
$scope.useredit.error.displayName = null;
$scope.useredit.error.email = null;