/
html.go
73 lines (67 loc) · 2.9 KB
/
html.go
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
package template
var (
HTMLWEB = `<!DOCTYPE html>
<html>
<head>
<title>{{title .Alias}} {{title .Type}}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">
{{title .Alias}} {{title .Type}}
</a>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-8">
<h1>{{title .Alias}} {{title .Type}}</h1>
<form class="{{.Alias}}">
<div class="form-group">
<label>Enter your name</label>
<input type=text class="form-control" id="name" name="name" placeholder="John">
</div>
<button class="btn btn-default">Submit</button>
</form>
</div>
</div>
<div class="row">
<div class="col-md-8">
<div class="message"></div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<!-- You may want to store this in a separate file -->
<script type="text/javascript">
$(".{{.Alias}}").submit(function(e) {
e.preventDefault();
var url = window.location.href.replace(/\/$/, "") + "/{{.Alias}}/call";
var data = $(this).serializeArray()[0];
var name = data.value;
if (name.length == 0) {
name = "John";
};
$.ajax({
method: "POST",
dataType: "json",
contentType: "application/json",
url: url,
data: JSON.stringify({name: name}),
success: function(data) {
$('.message').html('<h3>'+data.msg+'</h3>');
},
});
});
</script>
</body>
</html>
`
)