-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instead of using a tokenfield in a new screen it has been added: - A delete icon for each row in the table, for deleting a user. - An "Add user" link, for adding a user using a modal with an autocomplete box. This way we don't use tokenfield, that is currently not maintained.
- Loading branch information
Showing
7 changed files
with
139 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Webui2::GroupsController | ||
def webui2_update | ||
authorize @group, :update? | ||
|
||
user = User.find_by_login(webui2_group_params[:userid]) | ||
if user && @group.add_user(user) | ||
flash[:success] = "User '#{user}' successfully added to group '#{@group}'." | ||
redirect_to group_show_path(title: @group) + '#tab-group-members' | ||
else | ||
redirect_back(fallback_location: root_path, error: "Group couldn't be updated: #{@group.errors.full_messages.to_sentence}") | ||
end | ||
end | ||
|
||
def webui2_delete | ||
authorize @group, :update? | ||
|
||
user = User.find_by_login(params[:user]) | ||
if user && @group.remove_user(user) | ||
flash[:success] = "User '#{user}' successfully removed from group '#{@group}'." | ||
redirect_to group_show_path(title: @group) + '#tab-group-members' | ||
else | ||
redirect_back(fallback_location: root_path, | ||
error: "User '#{user}' couldn't be removed from '#{@group}': #{@group.errors.full_messages.to_sentence}") | ||
end | ||
end | ||
|
||
private | ||
|
||
def webui2_group_params | ||
params.require(:group).permit(:title, :userid) | ||
end | ||
end |
34 changes: 34 additions & 0 deletions
34
src/api/app/views/webui2/webui/groups/_add_user_modal.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.modal.fade#add-user-modal{ tabindex: -1, role: 'dialog', aria: { labelledby: 'edit-modal-label', hidden: true } } | ||
.modal-dialog.modal-dialog-centered{ role: 'document' } | ||
.modal-content | ||
= form_for(@group, url: group_update_path + '#tab-group-members', method: :post) do | ||
.modal-header | ||
%h5.modal-title#edit-modal-label Add User | ||
.modal-body | ||
.form-group#add-user-modal-input | ||
.input-group | ||
.input-group-prepend | ||
%span.input-group-text#add-user-search-icon | ||
%i.fa.fa-search | ||
%i.fas.fa-spinner.fa-spin.d-none | ||
= text_field_tag 'group[userid]', '', required: true, placeholder: 'Type to autocomplete...', class: 'form-control' | ||
.modal-footer | ||
= render partial: 'webui2/shared/dialog_action_buttons' | ||
|
||
= content_for :ready_function do | ||
:plain | ||
$('#group_userid').autocomplete({ | ||
appendTo: '#add-user-modal-input', | ||
source: '#{url_for controller: 'user', action: 'autocomplete'}', | ||
search: function(event, ui) { | ||
var icon = $('#add-user-search-icon i:first-child'); | ||
icon.addClass('d-none'); | ||
icon.next().removeClass('d-none'); | ||
}, | ||
response: function(event, ui) { | ||
var icon = $('#add-user-search-icon i:first-child'); | ||
icon.removeClass('d-none'); | ||
icon.next().addClass('d-none'); | ||
}, | ||
minLength: 2 | ||
}); |
10 changes: 8 additions & 2 deletions
10
src/api/app/views/webui2/webui/groups/_breadcrumb_items.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
= render partial: 'webui/main/breadcrumb_items' | ||
%li.breadcrumb-item | ||
= link_to 'Groups', groups_path | ||
%li.breadcrumb-item.active{ 'aria-current' => 'page' } | ||
= @group | ||
- if current_page?(group_show_path) | ||
%li.breadcrumb-item.active{ 'aria-current' => 'page' } | ||
= @group | ||
- else | ||
%li.breadcrumb-item | ||
= link_to @group, group_show_path(@group) | ||
%li.breadcrumb-item.active{ 'aria-current' => 'page' } | ||
Edit |
13 changes: 13 additions & 0 deletions
13
src/api/app/views/webui2/webui/groups/_remove_user_modal.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.modal.fade{ id: "delete-group-user-#{user.id}-modal", tabindex: -1, role: 'dialog', aria: { labelledby: 'delete-modal-label', hidden: true } } | ||
.modal-dialog.modal-dialog-centered{ role: 'document' } | ||
.modal-content | ||
.modal-header | ||
%h5.modal-title | ||
Remove user '#{user}'? | ||
.modal-body | ||
%p Please confirm removing user '#{user}' from group '#{group}' | ||
= form_tag(group_user_delete_path(group, user), method: :delete) do | ||
.modal-footer | ||
%button.btn.btn-sm.btn-outline-secondary.px-4{ data: { dismiss: 'modal' } } | ||
Cancel | ||
= submit_tag('Delete', class: 'btn btn-sm btn-danger px-4') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters