-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.html
97 lines (90 loc) · 2.56 KB
/
add.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<html>
<head>
<meta charset="utf-8">
<meta name="viewport">
<link href="css/util.css" rel="stylesheet" type="text/css">
<link href="css/fonts.css" rel="stylesheet" type="text/css">
<link href="style/headers.css" rel="stylesheet" type="text/css">
<link href="style/input_areas.css" rel="stylesheet" type="text/css">
<link href="style/buttons.css" rel="stylesheet" type="text/css">
<style>
h2 {
margin-top: 1em;
}
input {
margin: 0.5em 1em;
}
</style>
<script>
function filterInt(value) {
if(/^\-?([0-9]+|Infinity)$/.test(value)) {
return Number(value);
}
return NaN;
}
function getNum(seletor, msgErro) {
var num = document.querySelector(seletor).value;
if (num) {
num = num.trim();
}
num = filterInt(num, '10');
if (!num || num <= 0) {
alert(msgErro);
return;
}
return num;
}
function adicionarPalavra() {
var palavra = document.querySelector("#palavra").value;
if (palavra) {
palavra = palavra.trim();
}
if (!palavra) {
alert("Informe o seu interesse");
return;
}
var raio = getNum("#raio", "Informe um raio válido");
if (!raio) {
return;
}
var freq = getNum("#freq", "Informe uma frequência de busca válida");
if (!freq) {
return;
}
//procurar já existente
var keywords = JSON.parse(localStorage["keywords"]);
for (var i in keywords) {
if (keywords[i].palavra == palavra) {
alert("Esse interesse já foi registrado!");
return;
}
}
keywords[keywords.length] = {
"palavra": palavra,
"raio": raio,
"freq": freq
};
localStorage["keywords"] = JSON.stringify(keywords);
console.log("Adicionado aos interesses: '"+palavra+"' com raio "+raio+" metros e frequencia "+freq+" minutos");
window.location = "keywords.html";
}
</script>
</head>
<body>
<section role="region">
<header>
<button onclick="window.location='keywords.html'"><span class="icon icon-back">back</span></button>
<h1>Adicionar Interesse</h1>
</header>
<article class="content scrollable">
<h2>Interesse</h2>
<input id="palavra" type="text" placeholder="Ex.: restaurante, cinema, etc" required="">
<h2>Raio de busca (em metros)</h2>
<input id="raio" type="text" placeholder="" required="Ex.: 200">
<h2>Frequencia de busca (em minutos)</h2>
<input id="freq" type="text" placeholder="" required="Ex.: 3">
<a class="recommend" role="button" href="javascript:adicionarPalavra()">Adicionar</a>
</article>
</section>
</body>
</html>