From 53e012f29648775c7d8a97f8fbc6ad4ff5ca80fa Mon Sep 17 00:00:00 2001 From: Hideki Nakamura Date: Mon, 18 Dec 2017 00:53:03 +0900 Subject: [PATCH] Add delete SSH Key dialog --- editor/js/ui/projectUserSettings.js | 60 +++++++++++++++++++++++++---- editor/js/ui/projects.js | 8 ---- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/editor/js/ui/projectUserSettings.js b/editor/js/ui/projectUserSettings.js index afb111134..3c32984a8 100644 --- a/editor/js/ui/projectUserSettings.js +++ b/editor/js/ui/projectUserSettings.js @@ -53,15 +53,55 @@ RED.projects.userSettings = (function() { var sshkeyListOptions = { height: "300px", deleteAction: function(entry, header) { - sendSSHKeyManagementAPI("DELETE_KEY", entry.name, function(data) { - hideSSHKeyGenerateForm(); - utils.refreshSSHKeyList(sshkeysList); + var spinner = utils.addSpinnerOverlay(header).addClass('projects-dialog-spinner-contain'); + var notification = RED.notify("Are you sure you want to delete the SSH Keys '"+entry.name+"'? This cannot be undone.", { + type: 'warning', + modal: true, + fixed: true, + buttons: [ + { + text: RED._("common.label.cancel"), + click: function() { + spinner.remove(); + notification.close(); + } + }, + { + text: "Delete SSH Keys", + click: function() { + notification.close(); + sendSSHKeyManagementAPI("DELETE_KEY", entry.name, null, function(data) { + spinner.remove(); + hideSSHKeyGenerateForm(); + utils.refreshSSHKeyList(sshkeysList); + }, function(err) { + spinner.remove(); + console.log('Delete error! error:', err); + notification = RED.notify("Failed to delete the SSH Keys '"+entry.name+"'.", { + type: "error", + modal: true, + fixed: false + }); + }); + } + } + ] }); }, selectAction: function(entry, header) { - sendSSHKeyManagementAPI("GET_KEY_DETAIL", entry.name, function(data) { + var spinner = utils.addSpinnerOverlay(header).addClass('projects-dialog-spinner-contain'); + sendSSHKeyManagementAPI("GET_KEY_DETAIL", entry.name, null, function(data) { + spinner.remove(); setDialogContext(entry.name, data.publickey); dialog.dialog("open"); + }, function(err) { + console.log('Get SSH Key detail error! error:', err); + spinner.remove(); + notification = RED.notify("Failed to get the SSH Key detail '"+entry.name+"'.", { + type: "error", + modal: true, + fixed: false + }); }); } }; @@ -134,7 +174,8 @@ RED.projects.userSettings = (function() { email: gitEmailInput.val(), password: sshkeyPassphraseInput.val(), size: 4096 - }, + }, + gitconfigContainer, function() { hideSSHKeyGenerateForm(); utils.refreshSSHKeyList(sshkeysList); @@ -154,7 +195,7 @@ RED.projects.userSettings = (function() { }); } - function sendSSHKeyManagementAPI(type, param, successCallback, failCallback) { + function sendSSHKeyManagementAPI(type, param, overlay, successCallback, failCallback) { var url; var method; var payload; @@ -180,10 +221,13 @@ RED.projects.userSettings = (function() { console.error('Unexpected type....'); return; } - var spinner = utils.addSpinnerOverlay(gitconfigContainer); + // var spinner = utils.addSpinnerOverlay(gitconfigContainer); + var spinner = overlay ? utils.addSpinnerOverlay(overlay) : null; var done = function(err) { - spinner.remove(); + if ( spinner ) { + spinner.remove(); + } if (err) { console.log(err); return; diff --git a/editor/js/ui/projects.js b/editor/js/ui/projects.js index 665444656..4ea645fb8 100644 --- a/editor/js/ui/projects.js +++ b/editor/js/ui/projects.js @@ -728,8 +728,6 @@ RED.projects = (function() { return container; } - // var selectedSSHKey = null; - // var sshkeyList = null; $.fn.isVisible = function() { return $.expr.filters.visible(this[0]); } @@ -774,7 +772,6 @@ RED.projects = (function() { }); $.getJSON("settings/user/keys", function(data) { data.keys.forEach(function(key) { - console.log('key:', key); if ( sshkeyList ) { sshkeyList.editableList('addItem',key); } @@ -788,7 +785,6 @@ RED.projects = (function() { $.data(container[0], 'selected', null); $.data(container[0], 'sshkeys', sshkeyList); } - console.log('container.sshkeys:', container.data('sshkeys')); return container; } function getSelectedSSHKey(container) { @@ -801,16 +797,12 @@ RED.projects = (function() { } } function refreshSSHKeyList(container) { - console.log('refreshSSHKeyList'); var sshkeyList = $.data(container[0], 'sshkeys'); - console.log(' ---> container:', container); - console.log(' ---> container.sshkeyList:', sshkeyList); if ( container && sshkeyList ) { sshkeyList.empty(); $.getJSON("settings/user/keys", function(data) { var keyList = $.data(container[0], 'sshkeys'); data.keys.forEach(function(key) { - console.log('key:', key); if ( keyList ) { keyList.editableList('addItem',key); }