File size: 2,724 Bytes
ba76493
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Create Pole Record</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>
    <div class="container mt-5">
        <h2>Create Pole Record</h2>
        <form id="createPoleForm">
            <div class="form-group">
                <label for="name">Pole Name:</label>
                <input type="text" class="form-control" id="name" required>
            </div>
            <div class="form-group">
                <label for="powerRequired">Power Required:</label>
                <input type="number" class="form-control" id="powerRequired" required>
            </div>
            <div class="form-group">
                <label for="rfidTag">RFID Tag:</label>
                <input type="text" class="form-control" id="rfidTag" required>
            </div>
            <div class="form-group">
                <label for="locationLat">Location Latitude:</label>
                <input type="number" step="any" class="form-control" id="locationLat" required>
            </div>
            <div class="form-group">
                <label for="locationLong">Location Longitude:</label>
                <input type="number" step="any" class="form-control" id="locationLong" required>
            </div>
            <button type="submit" class="btn btn-primary">Create Pole</button>
        </form>
        <div id="responseMessage" class="mt-3"></div>
    </div>

    <script>
        $('#createPoleForm').on('submit', function(e) {
            e.preventDefault();

            const poleData = {
                name: $('#name').val(),
                powerRequired: $('#powerRequired').val(),
                rfidTag: $('#rfidTag').val(),
                locationLat: $('#locationLat').val(),
                locationLong: $('#locationLong').val(),
            };

            $.ajax({
                url: 'http://localhost:5000/create_pole', // Flask API endpoint
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(poleData),
                success: function(response) {
                    $('#responseMessage').html('<div class="alert alert-success">Pole record created successfully!</div>');
                },
                error: function(error) {
                    $('#responseMessage').html('<div class="alert alert-danger">Failed to create pole record!</div>');
                }
            });
        });
    </script>
</body>
</html>