-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimulate.php
More file actions
166 lines (146 loc) · 4.52 KB
/
simulate.php
File metadata and controls
166 lines (146 loc) · 4.52 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
$pageTitle = 'Simulate';
include('settings_begin.inc.php') ?>
<script src="js/triggers.js?v=<?php echo filemtime(__DIR__ . "/js/triggers.js") ?>" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function() {
// Load modes and sources
$('#modeTd').append(makeDynamicSelect('mode', modes));
$('#sourceTd').append(makeDynamicSelect('source', sources));
$('.selectpicker').selectpicker('render');
$('input').keydown(function() {
changeSpot();
});
$('select').change(function() {
changeSpot();
});
$(document).keypress(function(e) {
if (e.which == 13) {
sendSpot();
}
});
});
function changeSpot() {
$('#spotSent').hide();
}
function sendSpot() {
$('#spotSent').hide();
$('#spotAlert').hide();
var spot = {
fullCallsign: $('#fullCallsign').val(),
frequency: $('#frequency').val(),
summitRef: $('#summitRef').val(),
mode: $('#mode').val(),
source: $('#source').val(),
spotter: $('#spotter').val(),
comment: $('#comment').val()
};
if (!spot.fullCallsign || !spot.frequency || !spot.mode || !spot.source || !spot.spotter) {
$('#fillInFieldsAlert').show();
return;
}
$('#fillInFieldsAlert').hide();
$.post({
url: 'ajax/simulateSpot',
data: JSON.stringify({spot: spot}),
contentType: "application/json",
success: function(response) {
if (response.success) {
$('#spotSent').show();
} else {
var errorsHtml = response.errors.map(function(error) {
return "<li>" + htmlEscape(error) + "</li>";
});
$('#spotAlert').html('Could not send spot. Errors: <ul>' + errorsHtml.join("") + "</ul>");
$('#spotAlert').show();
}
},
error: function(xhr, textStatus, errorThrown) {
alert('Sending spot failed. Error: ' + xhr.responseText);
}
});
}
function makeDynamicSelect(name, map) {
var select = $('<select>', {
id: name,
class: 'selectpicker',
'data-width': 'auto',
'data-live-search': 'true'
});
select.append($('<option>', {
text: "",
value: ""
}));
$.each(map, function(key, value) {
select.append($('<option>', {
text: value,
value: key
}));
});
return select;
}
</script>
<style type="text/css" media="screen">
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
/* display: none; <- Crashes Chrome on hover */
-webkit-appearance: none;
margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
}
</style>
<h1 class="page-header">Simulate</h1>
<div class="alert alert-info" role="alert">
Use this page to simulate spots and test your triggers and alert destinations.
Spots sent from this page will be processed according to your triggers, and alerts will be sent.
Limits do not apply for simulated spots, and alerts will only be sent to you and not to other users.
</div>
<div id="spotSent" class="alert alert-success" role="alert" style="display: none">
Spot sent successfully.
</div>
<div id="fillInFieldsAlert" class="alert alert-danger" role="alert" style="display: none">
Please fill in all required fields.
</div>
<div id="spotAlert" class="alert alert-danger" role="alert" style="display: none"></div>
<form id="simulateForm">
<table class="table table-rounded table-condensed table-responsive editorConditionsTable">
<tbody>
<tr>
<th>Full callsign</th>
<td><input type="text" class="form-control" id="fullCallsign" placeholder="Full callsign" /></td>
</tr>
<tr>
<th>Frequency</th>
<td>
<div class="input-group">
<input type="number" step="any" class="form-control" id="frequency" placeholder="14.060" />
<div class="input-group-addon">MHz</div>
</div>
</td>
</tr>
<tr>
<th>Summit reference</th>
<td><input type="text" class="form-control" id="summitRef" placeholder="XX/YY-000" style="text-transform: uppercase" />
<p class="help-block">optional</p></td>
</tr>
<tr>
<th>Mode</th>
<td id="modeTd"></td>
</tr>
<tr>
<th>Source</th>
<td id="sourceTd"></td>
</tr>
<tr>
<th>Spotter</th>
<td><input type="text" class="form-control" id="spotter" placeholder="Spotter" /></td>
</tr>
<tr>
<th>Comment</th>
<td><input type="text" class="form-control" id="comment" placeholder="" />
<p class="help-block">The comment field is parsed for WWFF, POTA and SOTA references.</p></td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-primary" onclick="sendSpot(); return false" style="margin-top: 1em">Send</button>
</form>
<?php include('settings_end.inc.php') ?>