forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
76 lines (65 loc) · 2.6 KB
/
index.html
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
<html>
<head>
<link rel="shortcut icon" href="/stage/favicon.png" type="image/png">
<link rel="stylesheet" href="/stage/bootstrap.min.css" type="text/css">
<title>Short URL Manager</title>
</head>
<body>
<div class="container">
<div class="page-header">
<h1>Manage short URLs</h1>
</div>
<form id="add" class="form-inline">
<h3>Add new URL</h3>
<div class="form-group">
<label for="input-name">Short name</label>
<input type="text" class="form-control" id="input-name">
</div>
<div class="form-group">
<label for="input-url">URL</label>
<input type="text" class="form-control" id="input-url">
</div>
<button type="submit" class="btn btn-default">Add</button>
</form>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<table class="table table-hover" id="urltable">
<thead>
<tr>
<th>Short name</th>
<th>URL</th>
</tr>
</thead>
<tbody>
<script type="text/javascript">
function refreshList() {
$.getJSON('/stage/url', data => {
$("#urltable tbody tr").remove();
data.forEach(item =>
$("#urltable").append(
`<tr>
<td><a target="_blank" href=\"/stage/url/${item.name}\">${item.name}</a></td>
<td>${item.url}</td>
</tr>`
)
);
});
};
$(document).ready(() => {
refreshList();
$("#add").submit(ev => {
ev.preventDefault();
let name = document.getElementById("input-name").value;
let url = document.getElementById("input-url").value;
$.post('/stage/url/?name=' + name + "&url=" + url, {}, data => {
console.log(data);
refreshList();
document.getElementById("add").reset();
});
});
});
</script>
</tbody>
</table>
</div>
</body>
</html>