From ef81845361b7a24eb02bd497b9843e03b9659596 Mon Sep 17 00:00:00 2001 From: Artem Martynovich Date: Fri, 23 Aug 2019 18:33:38 +0600 Subject: [PATCH 1/3] Avoid multiple removal of Credentials. --- backend/device_registry/templates/credentials.html | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/backend/device_registry/templates/credentials.html b/backend/device_registry/templates/credentials.html index fccf5dc92..57e799463 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').on('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); From 476db1d187eb14573398cd6f6b07a7bd01ccae3a Mon Sep 17 00:00:00 2001 From: Artem Martynovich Date: Fri, 23 Aug 2019 18:46:41 +0600 Subject: [PATCH 2/3] Avoid multiple deletion of Pairing Keys. --- backend/backend/static/js/app.js | 2 +- .../templates/credentials.html | 2 +- .../templates/pairing_keys.html | 49 ++++++------------- 3 files changed, 17 insertions(+), 36 deletions(-) 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 57e799463..90c3e498f 100644 --- a/backend/device_registry/templates/credentials.html +++ b/backend/device_registry/templates/credentials.html @@ -463,7 +463,7 @@
View credentials.
}); - $('#confirm-btn').on('click', (e) => { + $('#confirm-btn').click(e => { console.log('del'); $.ajax({ diff --git a/backend/device_registry/templates/pairing_keys.html b/backend/device_registry/templates/pairing_keys.html index 95e068cbd..7ab173a33 100644 --- a/backend/device_registry/templates/pairing_keys.html +++ b/backend/device_registry/templates/pairing_keys.html @@ -219,9 +219,16 @@
List of keys not yet applied.
{ title:"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" @@ -247,13 +254,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 +265,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 +371,6 @@
List of keys not yet applied.
wott_alert_strings(errMsgs, alert_box_id); } - const copyToClipboard = str => { - const el = document.createElement('textarea'); // Create a