zhongrj
2025-11-25 b89962006164a462404b79a738bee8cbb6d7fe7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{% extends "app/plugins/templates/base.html" %}
{% load bootstrap_extras %}
{% block content %}
<h3>DroneDB</h3>
Provide your credentials to access <a href="https://dronedb.app" target="_blank">DroneDB</a>:
<br/>
<br/>
<form action="" method="post" class="oam-form oam-token-form">
    {% csrf_token %}
    {% include "app/plugins/templates/form.html" %}
    <button id="btnVerify" type="button" class="btn btn-success" disabled><i class="fas fa-user-check"></i>&nbsp;&nbsp;Verify Configuration</button>
    <button type="submit" class="btn btn-primary" disabled><i class="fa fa-save fa-fw"></i>&nbsp;&nbsp;Save Configuration</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,button[type=submit]").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();
 
            $("#btnVerify").prop('disabled', true);
 
            $.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!");
                    }
 
                    timeout = setTimeout(function() { alert.hide(); }, 5000);
 
                },
                error: function(data) {
                    alert.attr('class', 'alert alert-danger');
                    alert.text("Configuration failed: cannot reach server!");
                },
                complete: function() {
                    running = false;
                    $("#btnVerify").prop('disabled', false);
                }
            });
    
        });
    });
 
</script>
 
{% endblock %}