mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 19:03:30 -05:00
For users who: - want to send messages from a template - want to edit templates For developers: - who need to get the ID of a template This commit mainly cleans up the choose template page so there are less options, and the options that are there are less wordy. This means: - moving ‘send yourself a test’ onto the send messages page, and making it button - stripping a lot of stuff out of the ‘send from API’ page, so it’s more obvious what the template ID is
55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
(function(Modules) {
|
|
"use strict";
|
|
|
|
if (!document.queryCommandSupported('copy')) return;
|
|
|
|
Modules.ApiKey = function() {
|
|
|
|
const states = {
|
|
'keyVisible': (key, thing) => `
|
|
<span class="api-key-key">${key}</span>
|
|
<input type='button' class='api-key-button-copy' value='Copy ${thing} to clipboard' />
|
|
`,
|
|
'keyCopied': thing => `
|
|
<span class="api-key-key">Copied to clipboard</span>
|
|
<input type='button' class='api-key-button-show' value='Show ${thing}' />
|
|
`
|
|
};
|
|
|
|
this.copyKey = function(keyElement, callback) {
|
|
var selection = window.getSelection ? window.getSelection() : document.selection,
|
|
range = document.createRange();
|
|
selection.removeAllRanges();
|
|
range.selectNodeContents(keyElement);
|
|
selection.addRange(range);
|
|
document.execCommand('copy');
|
|
selection.removeAllRanges();
|
|
callback();
|
|
};
|
|
|
|
this.start = function(component) {
|
|
|
|
const $component = $(component),
|
|
key = $component.data('key'),
|
|
thing = $component.data('thing');
|
|
|
|
$component
|
|
.html(states.keyVisible(key, thing))
|
|
.attr('aria-live', 'polite')
|
|
.on(
|
|
'click', '.api-key-button-copy', () =>
|
|
this.copyKey(
|
|
$('.api-key-key', component)[0], () =>
|
|
$component.html(states.keyCopied(thing))
|
|
)
|
|
)
|
|
.on(
|
|
'click', '.api-key-button-show', () =>
|
|
$component.html(states.keyVisible(key, thing))
|
|
);
|
|
|
|
};
|
|
};
|
|
|
|
})(window.GOVUK.Modules);
|