diff --git a/backend/backend/static/js/app.js b/backend/backend/static/js/app.js
index 489cf8e7e..5a745826a 100644
--- a/backend/backend/static/js/app.js
+++ b/backend/backend/static/js/app.js
@@ -31,5 +31,5 @@ require('exports-loader?window.select23!../../staticfiles/tagulous/adaptor/selec
// Copy to clipboard
import * as clipboard from "clipboard-polyfill"
window.copyToClipboard = function(text) {
- return clipboard.writeText(text).then(console.log, console.error);
+ return clipboard.writeText(text);
}
\ No newline at end of file
diff --git a/backend/device_registry/templates/credentials.html b/backend/device_registry/templates/credentials.html
index fccf5dc92..90c3e498f 100644
--- a/backend/device_registry/templates/credentials.html
+++ b/backend/device_registry/templates/credentials.html
@@ -459,12 +459,11 @@
View credentials.
let data = table.row( $(this).parents('tr') ).data();
deleted_pk = data.pk;
- $('#confirm-btn').on('click', delete_credential );
show_confirm_dialog( "Confirm Removal", "Are you sure you want to delete?", "Delete" );
});
- function delete_credential() {
+ $('#confirm-btn').click(e => {
console.log('del');
$.ajax({
@@ -479,11 +478,11 @@
View credentials.
console.log(a.status, a.responseText);
alertbox_on_ajax_fail(a,del_modal_idx);
});
- }
+ });
function obj_to_kv_editor_data(obj)
{
- let rows = []
+ let rows = [];
for( let key in obj ) {
rows.push( [key, obj[key]] );
}
@@ -492,10 +491,10 @@
View credentials.
function get_kv_data_view(data, view_id, starred=true)
{
- let rows = []
+ let rows = [];
for( let key in data ){
let val = data[key].toString();
- val = (starred) ? '*'.repeat(val.length) : htmlEntities(val)
+ val = (starred) ? '*'.repeat(val.length) : htmlEntities(val);
rows.push( "
" + key + "
" + val + "
" );
}
let value = JSON.stringify(data);
diff --git a/backend/device_registry/templates/pairing_keys.html b/backend/device_registry/templates/pairing_keys.html
index 95e068cbd..a2cba1ae0 100644
--- a/backend/device_registry/templates/pairing_keys.html
+++ b/backend/device_registry/templates/pairing_keys.html
@@ -196,32 +196,30 @@
List of keys not yet applied.
return ``;
}
- function fa_button( type, btn, fa, onclick, popover=undefined)
- {
- let pop = ( popover === undefined ) ? "" : ' data-toggle="popover" data-placement="top" title="' +
- popover.title + (popover.content === undefined ? '"' : `" data-content="${popover.content}"`);
-
- return ``;
- }
function render_buttons(data, type, row, meta)
{
let save_url = `location.href='/pairing-keys/download?pk=${row.key}';`;
- return fa_button( "button", "btn-primary", "fas fa-copy fa-lg", `copy_key(this, '${row.key}')`,
- { title: "Copy key to clipboard",
- content: "Copy the enrollment string to the clipboard. The string is in the form 'key = value' " +
- "to simply paste to config.ini file."})
- + fa_button( "button", "btn-success", "fas fa-save fa-lg", save_url,
- { title:"Store key to disk", content: "Store generated enrollment key as ready to go config.ini file." } )
- + fa_button( "button", "btn-danger", "fas fa-trash fa-lg", "revoke_key(this)",
- { title:"Revoke the enrollment key"} )
+ let fa_button = ( type, btn, fa, onclick, title) =>
+ ``;
+
+ return fa_button( "button", "btn-primary", "fas fa-copy fa-lg", `copy_key(this, '${row.key}')`,"Copy key to clipboard")
+ + fa_button( "button", "btn-success", "fas fa-save fa-lg", save_url, "Store key to disk")
+ + fa_button( "button", "btn-danger", "fas fa-trash fa-lg", "revoke_key(this)","Revoke the enrollment key");
}
+ function copy_key(a){
+ copyToClipboard(
+ "enroll_token = " + a
+ );
+ }
+
+ var deleted_pk;
function revoke_key(a){
wott_alert_hide("main-alert");
- $('#confirm-btn').on("click", {key: a.parentElement.parentElement.parentElement.id}, delete_key );
+ deleted_pk = a.parentElement.parentElement.parentElement.id;
show_dialog("Confirm Revoke Key",
"Are you sure you want to revoke?",
"Revoke"
@@ -230,14 +228,9 @@
List of keys not yet applied.
function show_popover(el, title, content='')
{
- let title_store = el.attr('title');
- let content_store = el.attr('data-content');
el.attr('title', title);
el.attr('data-content', content);
- el.attr('title', title);
el.popover('show');
- el.attr('title', title_store);
- el.attr('data-content', content_store);
el.on( "mouseout", function (ev) {
let el = $(ev.currentTarget);
el.off("mouseout");
@@ -247,13 +240,10 @@
List of keys not yet applied.
function copy_key(btn, key){
let key_text = "enroll_token = " + key;
- navigator.clipboard.writeText(key_text).then(function() {
- show_popover($(btn), 'Copied', key_text);
- }, function() {
- let successful = copyToClipboard(key_text);
- let title = successful ? 'Copied' : 'Could not copy to clipboard. Check the browser permissions.';
- let msg = successful ? key_text : '';
- show_popover($(btn), title, msg);
+ copyToClipboard(key_text).then(() => {
+ show_popover($(btn), 'Copied', key_text);
+ }, () => {
+ show_popover($(btn), 'Could not copy to clipboard. Check the browser permissions.', '');
});
}
@@ -261,21 +251,19 @@
List of keys not yet applied.
* on confirm delete
* @param e - e.data.key <- key to delete
*/
- function delete_key(e)
- {
+ $('#confirm-btn').click(e => {
hide_dialog();
$.ajax({
- url: `/ajax-pairing-keys/${e.data.key}/delete/`,
+ url: `/ajax-pairing-keys/${deleted_pk}/delete/`,
type: "DELETE",
}).done(function () {
- console.log('success');
table.ajax.reload();
}).fail(function (a) {
console.log('error');
console.log(a.status, a.responseText);
alertbox_on_ajax_fail(a, "confirm-alert");
});
- }
+ });
/**
* id - key/row_id (they are the same)
@@ -369,27 +357,6 @@
List of keys not yet applied.
wott_alert_strings(errMsgs, alert_box_id);
}
- const copyToClipboard = str => {
- const el = document.createElement('textarea'); // Create a