Added verify configuration button

pull/1122/head
Luca Di Leo 2022-01-13 07:26:33 -08:00
rodzic 620af7fc53
commit 7578e01a0f
1 zmienionych plików z 68 dodań i 1 usunięć

Wyświetl plik

@ -10,7 +10,74 @@ On this screen, you can provide the registry url and credentials to access Drone
<h4>Settings</h4>
{% csrf_token %}
{% include "app/plugins/templates/form.html" %}
<button type="submit" class="btn btn-primary"><i class="fa fa-save fa-fw"></i> Save Configuration</i></button>
<button id="btnVerify" type="button" class="btn btn-success" disabled><i class="fas fa-user-check"></i>&nbsp;&nbsp;Verify Configuration</i></button>
<button type="submit" class="btn btn-primary"><i class="fa fa-save fa-fw"></i>&nbsp;&nbsp;Save Configuration</i></button>
</form>
<div id="alert-result" style="display: none; margin-top: 20px" class="alert" role="alert"></div>
<script>
$(document).ready(function() {
var running = false;
var timeout = null;
$("input[name=registry_url],input[name=username],input[name=password]").on('keyup', function() {
var alert = $("#alert-result").hide();
if (timeout != null) clearTimeout(timeout);
$("#btnVerify").prop('disabled',
$("input[name=registry_url]").val().length == 0 ||
$("input[name=username]").val().length == 0 ||
$("input[name=password]").val().length == 0);
});
$("#btnVerify").click(function() {
if (running) return;
running = true;
if (timeout != null) clearTimeout(timeout);
var alert = $("#alert-result");
alert.attr('class', 'alert alert-info');
alert.text("Testing configuration...");
alert.show();
$.ajax({
url: "/api/plugins/dronedb/checkcredentials",
type: "POST",
data: {
"csrfmiddlewaretoken": $("input[name=csrfmiddlewaretoken]").val(),
"hubUrl": $("input[name=registry_url]").val(),
"userName": $("input[name=username]").val(),
"password": $("input[name=password]").val()
},
success: function(data) {
if (data.success) {
alert.attr('class', 'alert alert-success');
alert.text("Configuration verified successfully!");
} else {
alert.attr('class', 'alert alert-danger');
alert.text("Configuration verification failed!");
}
var timeoutID = setTimeout(function() { alert.hide(); }, 5000);
},
error: function(data) {
alert.attr('class', 'alert alert-danger');
alert.text("Configuration failed!");
},
complete: function() {
running = false;
}
});
});
});
</script>
{% endblock %}