-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create CopyToClipboardInput view component
- Loading branch information
Showing
6 changed files
with
35 additions
and
46 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/api/app/components/copy_to_clipboard_input_component.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,23 @@ | ||
-# TODO: Relying on a form builder is a bit weird. We could perhaps directly use `text_field_tag` instead and pass an input value to the component. | ||
= @form_builder.text_field(:string_readonly, id: 'copy-to-clipboard-readonly', class: 'form-control', readonly: true) | ||
.input-group-append#copy-to-clipboard | ||
%span.input-group-text | ||
%i.fas.fa-clipboard | ||
|
||
:javascript | ||
function copyToClipboard() { | ||
document.getElementById('copy-to-clipboard-readonly').select(); | ||
document.execCommand('copy'); | ||
} | ||
|
||
- content_for :ready_function do | ||
:plain | ||
// Definition of the tooltip and click event handler for the "Copy to clipboard" icon | ||
$('#copy-to-clipboard').tooltip({ title: 'Copy to clipboard' }).on('click', function () { | ||
copyToClipboard(); | ||
|
||
// Shows "Copied!" tooltip. Later on shows the previous message 'Copy to clipboard' as tooltip. | ||
$(this).tooltip('dispose').tooltip({ title: 'Copied!' }).tooltip('show').on('hidden.bs.tooltip', function () { | ||
$(this).tooltip('dispose').tooltip({ title: 'Copy to clipboard' }); | ||
}); | ||
}); |
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,6 @@ | ||
class CopyToClipboardInputComponent < ApplicationComponent | ||
def initialize(form_builder:) | ||
super | ||
@form_builder = form_builder | ||
end | ||
end |
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,7 +1,7 @@ | ||
$('#flash').html("<%= escape_javascript(render(layout: false, partial: 'layouts/webui/flash', object: flash)) %>"); | ||
<% if flash[:error].blank? %> | ||
$('#created-token').removeClass('d-none'); | ||
$('#token_string_readonly').val("<%= escape_javascript(string) %>"); | ||
$('.form-row :input').not('#token_string_readonly').prop('disabled', true); | ||
$('#copy-to-clipboard-readonly').val("<%= escape_javascript(string) %>"); | ||
$('.form-row :input').not('#copy-to-clipboard-readonly').prop('disabled', true); | ||
$('.actions').html("<%= escape_javascript(render partial: 'actions') %>"); | ||
<% end %> |
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
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