-
Notifications
You must be signed in to change notification settings - Fork 4
/
adminfile
88 lines (77 loc) · 3.47 KB
/
adminfile
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
86
87
88
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Private URL shortener</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// used only to allow local serving of files
$.ajaxSetup({
beforeSend: function(xhr) {
if (xhr.overrideMimeType) {
xhr.overrideMimeType("application/json");
}
}
});
$('#url_input').focus(); // set initial focus
$('form#submit').submit(function(event) {
$('#url_input_submit').prop('disabled', true);
// process the form
$.ajax({
type : 'POST',
url : '/create',
data : JSON.stringify({ 'long_url' : $('#url_input').val(), 'cdn_prefix': window.location.hostname }),
contentType : 'application/json; charset=utf-8',
dataType : 'json',
encode : true
})
.done(function(data,textStatus, jqXHR) {
$('#url_input_submit').prop('disabled', false);
if (data.error) {
$('#url-group').addClass('has-error'); // add the error class to show red input
$('#url-error').show().text(data.error); // add the actual error message under our input
} else {
$('form#submit').hide(); // hide initial submit form
$('form#result').show(); // and show the one used to display the results
$('#long_url').text(data.long_url);
$('#short_id').val(data.short_id).focus().select();
}
})
.fail(function(_, _, errorThrown) {
$('#url_input_submit').prop('disabled', false);
$('#url-group').addClass('has-error'); // add the error class to show red input
$('#url-error').show().text("Server error: "+errorThrown); // add the actual error message under our input
});
// stop the form from submitting the normal way and refreshing the page
event.preventDefault();
});
$('form#result').submit(function(event) {
location.reload();
});
});
</script>
</head>
<body>
<div class="col-sm-8 col-sm-offset-1">
<h1>Private URL shortener</h1>
<br/>
<form id="submit">
<div id="url-group" class="form-group">
<input type="url" required class="form-control" name="url" placeholder="Paste here the long URL here" id="url_input">
<div class="help-block" style="display: none" id="url-error"></div>
</div>
<button type="submit" class="btn btn-success" id="url_input_submit">Shorten</button>
</form>
<form id="result" style="display: none">
<div class="alert alert-success">Successfully shortened: <br/><span id="long_url"></span></div>
<div class="form-group">
<label for="name">You can now copy/paste the short URL</label>
<input type="text" class="form-control" name="url" readonly="readonly" id="short_id">
</div><button type="submit" class="btn btn-success" id="page_reload">New URL</button><div>
</div>
</form>
</div>
</body>
</html>