-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-book.html
77 lines (71 loc) · 2.84 KB
/
add-book.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
77
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="libs/materialize/css/materialize.min.css">
<link rel="stylesheet" href="libs/materialize/css/icons.css">
<!--JQUERY-->
<script type="text/javascript" src="libs/jquery/jquery-3.2.1.min.js"></script>
<!--JSON SERIALIZER-->
<script type="text/javascript" src="libs/jquery.serializeJSON/jquery.serializejson.min.js"></script>
</head>
<body>
<div class="container">
<!--h2>Adicionar Livro</h2-->
<form action="javascript:">
<div class="input-field">
<input id="title" type="text" class="validate" name="title" required>
<label for="title">Título</label>
</div>
<div class="row">
<div class="input-field">
<input id="grade" name="grade" type="number" class="validate" required>
<label for="grade">Classe</label>
</div>
<div class="input-field">
<input id="subject" name="subject" type="text" class="validate" required>
<label for="subject">Disciplina</label>
</div>
</div>
<div class="input-field">
<input id="link" name="link" type="url" class="validate" required>
<label for="link">Link</label>
</div>
<div class="file-field input-field">
<div class="btn">
<span>Capa</span>
<input type="file" name="cover" accept="image/*" required>
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
<button class="btn waves-effect waves-light" type="submit" name="action">Adicionar Livro
<i class="material-icons right">send</i>
</button>
</form>
</div>
<script src="libs/materialize/js/materialize.min.js"></script>
<script>
function convertImageToBase64(input) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(input.files[0]);
});
}
document.forms[0].addEventListener('submit', async function() {
var data = $(this).serializeJSON();
data.grade = Number(data.grade)
var inputFile = this.querySelector('[type=file]')
data.cover = await convertImageToBase64(inputFile)
data.type = 'iframe'
parent.postMessage(data, '*')
})
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('select');
var instances = M.FormSelect.init(elems);
});
</script>
</body>
</html>