Disable button dont hide them + dont select current user

This commit is contained in:
Niels Lyngsø
2019-02-11 14:30:01 +01:00
parent a77b0fc51f
commit e4a492dc57
2 changed files with 46 additions and 42 deletions

View File

@@ -196,27 +196,23 @@
vm.activeLayout = selectedLayout;
}
function selectUser(user, event) {
// prevent the current user to be selected, why?
//if (!user.isCurrentUser) {
if (user.selected) {
var index = vm.selection.indexOf(user.id);
vm.selection.splice(index, 1);
user.selected = false;
} else {
user.selected = true;
vm.selection.push(user.id);
}
setBulkActions(vm.users);
if (event) {
event.preventDefault();
event.stopPropagation();
}
//}
function selectUser(user) {
if (user.isCurrentUser) {
return;
}
if (user.selected) {
var index = vm.selection.indexOf(user.id);
vm.selection.splice(index, 1);
user.selected = false;
} else {
user.selected = true;
vm.selection.push(user.id);
}
setBulkActions(vm.users);
}
function clearSelection() {
@@ -621,18 +617,20 @@
var firstSelectedUserGroups;
angular.forEach(users, function (user) {
if (!user.selected) {
return;
}
console.log("CHECK")
// if the current user is selected prevent any bulk actions with the user included
if (user.isCurrentUser) {
vm.allowDisableUser = false;
vm.allowEnableUser = false;
vm.allowUnlockUser = false;
vm.allowSetUserGroup = false;
return;
console.log("IS CURRENT!")
return false;
}
if (user.userDisplayState && user.userDisplayState.key === "Disabled") {
@@ -656,16 +654,17 @@
}
// store the user group aliases of the first selected user
if (!firstSelectedUserGroups) {
firstSelectedUserGroups = user.userGroups.map(function (ug) { return ug.alias; });
vm.allowSetUserGroup = true;
} else if (vm.allowSetUserGroup === true) {
// for 2nd+ selected user, compare the user group aliases to determine if we should allow bulk editing.
// we don't allow bulk editing of users not currently having the same assigned user groups, as we can't
// really support that in the user group picker.
var userGroups = user.userGroups.map(function (ug) { return ug.alias; });
if (_.difference(firstSelectedUserGroups, userGroups).length > 0) {
vm.allowSetUserGroup = false;
if (vm.allowSetUserGroup === true) {
if (!firstSelectedUserGroups) {
firstSelectedUserGroups = user.userGroups.map(function (ug) { return ug.alias; });
} else {
// for 2nd+ selected user, compare the user group aliases to determine if we should allow bulk editing.
// we don't allow bulk editing of users not currently having the same assigned user groups, as we can't
// really support that in the user group picker.
var userGroups = user.userGroups.map(function (ug) { return ug.alias; });
if (_.difference(firstSelectedUserGroups, userGroups).length > 0) {
vm.allowSetUserGroup = false;
}
}
}
});

View File

@@ -63,7 +63,7 @@
<umb-editor-sub-header-content-right ng-if="vm.selection.length > 0">
<umb-button
style="margin-right: 5px;"
ng-if="vm.allowSetUserGroup"
disabled="!vm.allowSetUserGroup"
type="button"
size="xs"
button-style="white"
@@ -74,7 +74,7 @@
<umb-button
style="margin-right: 5px;"
ng-if="vm.allowEnableUser"
disabled="!vm.allowEnableUser"
type="button"
size="xs"
button-style="white"
@@ -86,7 +86,7 @@
<umb-button
style="margin-right: 5px;"
ng-if="vm.allowUnlockUser"
disabled="!vm.allowUnlockUser"
type="button"
size="xs"
button-style="white"
@@ -97,7 +97,7 @@
</umb-button>
<umb-button
ng-if="vm.allowDisableUser"
disabled="!vm.allowDisableUser"
type="button"
size="xs"
button-style="white"
@@ -242,9 +242,14 @@
</tr>
</thead>
<tbody>
<tr ng-repeat="user in vm.users track by user.key" ng-click="vm.clickUser(user)" style="cursor: pointer;" ng-mouseenter="user.hover = true" ng-mouseleave="user.hover = false">
<tr ng-repeat="user in vm.users track by user.key"
ng-click="vm.selectUser(user, vm.selection, $event)"
ng-class="{'--selected': user.selected}"
style="cursor: pointer;"
ng-mouseenter="user.hover = true"
ng-mouseleave="user.hover = false">
<td style="padding-left: 10px;">
<div ng-if="!user.isCurrentUser" ng-click="vm.selectUser(user, vm.selection, $event)">
<div ng-if="!user.isCurrentUser">
<umb-checkmark
ng-if="vm.selection.length > 0 || user.hover"
checked="user.selected"
@@ -252,7 +257,7 @@
</umb-checkmark>
</div>
</td>
<td scope="row">
<td scope="row" ng-click="vm.clickUser(user)">
<umb-avatar
size="xs"
color="secondary"
@@ -261,7 +266,7 @@
img-srcset="{{user.avatars[1]}} 2x, {{user.avatars[2]}} 3x">
</umb-avatar>
</td>
<td class="bold">{{user.name}}</td>
<td class="bold" ng-click="vm.clickUser(user)">{{user.name}}</td>
<td><span ng-repeat="userGroup in user.userGroups">{{ userGroup.name }}<span ng-if="!$last">, </span></span></td>
<td>{{ user.formattedLastLogin }}</td>
<td style="text-transform: capitalize;">