Commit 3e15ccfe authored by Tobias Kallauke's avatar Tobias Kallauke
Browse files

Update member removal to use checkboxes

parent bc7aec85
......@@ -26,28 +26,8 @@ function delete_users(users: number[]) {
$(() => {
let loading = false
let users_to_delete: number[] = []
$("button.btn-delete-user").on("click", function () {
if (loading) return
const btn = $(this)
const uid = Number(btn.data("uid"))
const index = users_to_delete.indexOf(uid)
if (index != -1) {
btn.parents("tr").removeClass("mark-delete")
users_to_delete.splice(index, 1)
} else {
btn.parents("tr").addClass("mark-delete")
users_to_delete.push(uid)
}
})
$(".adminEmailCopy").on("click", function (e) {
$(".adminEmailCopy").addClass("buttonToFadeGreen");
......@@ -78,20 +58,30 @@ $(() => {
updates.push({uid: el.data("uid"), role: value});
});
let users_to_remove: number[] = []
$(".form-check-input.member-remove").each(function () {
const checked = (this as HTMLInputElement).checked
if (checked) {
const uid = parseInt((this as HTMLInputElement).dataset.uid)
if (isNaN(uid)) throw Error("Could not parse data-uid for member remove checkbox")
users_to_remove.push(uid)
}
})
// No roles changed and no members marked for removal
if (updates.length === 0 && users_to_delete.length === 0) {
if (updates.length === 0 && users_to_remove.length === 0) {
location.reload()
return
}
// Remove any role updates for users that are marked for removal
updates = updates.filter(e => !users_to_delete.includes(e.uid))
updates = updates.filter(e => !users_to_remove.includes(e.uid))
const request = []
if (updates.length > 0)
request.push(update_roles(updates))
if (users_to_delete.length > 0)
request.push(delete_users(users_to_delete))
if (users_to_remove.length > 0)
request.push(delete_users(users_to_remove))
// Wait for all request to complete
$.when(...request).then(function (x) {
......@@ -140,4 +130,4 @@ $(() => {
location.reload()
})
})
});
})
<%= render partial: "shared/group-header", locals: { group: @group } %>
<%= render partial: "shared/group-nav", locals: {group_id: @group_id, consumers: @consumers, members_selected: true } %>
<%= render partial: "shared/group-header", locals: { group: @group } %>
<%= render partial: "shared/group-nav", locals: { group_id: @group_id, consumers: @consumers, members_selected: true } %>
<table class="table">
<thead>
<tr>
<th><%= t('group.get.tableLogin') %></th>
<th><%= t('group.get.tableRole') %></th>
<th style="text-align: right"><%= t('group.get.tableDelete') %></th>
<th class="text-center"><%= t('group.get.tableDelete') %></th>
</tr>
</thead>
<tbody>
<% if @my_role == Roles::ADMIN %>
<% @members.each do |m| %>
<tr>
<% if @my_role == Roles::ADMIN %>
<% @members.each do |m| %>
<tr>
<td><%= m.login %></td>
<td>
<select class="form-control role-select" data-uid="<%= m.id %>" data-initial="<%= m.role %>">
<option value="0" <%= 'selected' if m.role == Roles::ADMIN %>><%= t('group.get.role.admin') %></option>
<option value="1" <%= 'selected' if m.role == Roles::MEMBER %>><%= t('group.get.role.participant') %></option>
<option value="2" <%= 'selected' if m.role == Roles::GUEST %>><%= t('group.get.role.guest') %></option>
<select class="form-control role-select" data-uid="<%= m.id %>" data-initial="<%= m.role %>"
autocomplete="off" aria-label="Rolle des Mitglieds"
>
<option value="0" <%= 'selected' if m.role == Roles::ADMIN %>><%= t('group.get.role.admin') %></option>
<option value="1" <%= 'selected' if m.role == Roles::MEMBER %>><%= t('group.get.role.participant') %></option>
<option value="2" <%= 'selected' if m.role == Roles::GUEST %>><%= t('group.get.role.guest') %></option>
</select>
</td>
<td style="text-align: right">
<button type="button" class="btn btn-danger btn-delete-user" data-uid="<%= m.id %>">
<span>X</span>
</button>
<td class="text-center">
<div class="form-check">
<input class="form-check-input position-static member-remove" type="checkbox"
id="member-delete-<%= m.id %>" data-uid="<%= m.id %>"
autocomplete="off" aria-label="Mitglied löschen"
>
</div>
</td>
</tr>
</tr>
<% end %>
<tr>
<td>
<form class="d-flex" id="user-add-form">
<input type="text" class="form-control mr-1" id="user-add-input" style="max-width: 20ch" autocomplete="off">
<button type="submit" class="btn btn-success" id="user-add-button">
<span class="spinner-border spinner-border-sm d-none" role="status" aria-hidden="true"></span>
<%= t('group.get.addButton') %>
</button>
</form>
<div class="mt-2 alert alert-danger d-none" id="user-add-error">Test</div>
</td>
<td colspan="2">
<button type="button" class="btn btn-success role-save">
<% end %>
<tr>
<td>
<form class="d-flex" id="user-add-form">
<input type="text" class="form-control mr-1" id="user-add-input" style="max-width: 20ch" autocomplete="off">
<button type="submit" class="btn btn-success" id="user-add-button">
<span class="spinner-border spinner-border-sm d-none" role="status" aria-hidden="true"></span>
<span><%= t('group.get.saveButton') %></span>
<%= t('group.get.addButton') %>
</button>
</td>
</tr>
<% end %>
</form>
<div class="mt-2 alert alert-danger d-none" id="user-add-error">Test</div>
</td>
<% if @my_role == Roles::MEMBER %>
<% @members.each do |m| %>
<tr>
<td colspan="2">
<button type="button" class="btn btn-success role-save">
<span class="spinner-border spinner-border-sm d-none" role="status" aria-hidden="true"></span>
<span><%= t('group.get.saveButton') %></span>
</button>
</td>
</tr>
<% end %>
<% if @my_role == Roles::MEMBER %>
<% @members.each do |m| %>
<tr>
<td><%= m.login %></td>
<td colspan="2">
<% if m.role == Roles::ADMIN %>
<%= t('group.get.role.admin') %>
<% end %>
<% if m.role == Roles::MEMBER %>
<%= t('group.get.role.participant') %>
<% end %>
<% if m.role == Roles::GUEST %>
<%= t('group.get.role.guest') %>
<% end %>
<% if m.role == Roles::ADMIN %>
<%= t('group.get.role.admin') %>
<% end %>
<% if m.role == Roles::MEMBER %>
<%= t('group.get.role.participant') %>
<% end %>
<% if m.role == Roles::GUEST %>
<%= t('group.get.role.guest') %>
<% end %>
</td>
</tr>
<% end %>
<% end %>
<% end %>
<% if @my_role == Roles::GUEST %>
<% @members.each do |m| %>
<% if m.id == session[:user_id] %>
<tr>
<td><%= m.login %></td>
<td colspan="2">
<% if @my_role == Roles::GUEST %>
<% @members.each do |m| %>
<% if m.id == session[:user_id] %>
<tr>
<td><%= m.login %></td>
<td colspan="2">
<%= t('group.get.role.guest') %>
</td>
</tr>
<% end %>
</td>
</tr>
<% end %>
<% end %>
<% end %>
</tbody>
</table>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment