-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodule.js
More file actions
83 lines (70 loc) · 2.16 KB
/
module.js
File metadata and controls
83 lines (70 loc) · 2.16 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
// Module JavaScript for UI elements
// Variables
var maxSysStations = 9;
var minReqStations = 1;
// Sub Functions
function htmlTemplate(n) {
var html = '<p class="stationRow additional">'+
'<span class="num">'+
' <input type="hidden" name="stationNum[]" value="' + n +'">' + n +
'</span>'+
'<span>'+
' <input id="stationLabel' + n +'" type="text" name="stationLabel[]" placeholder="Station Label" class="stationLabel" Value="Station '+n+'" required>'+
' <input id="stationICAO' + n +'" type="text" name="stationICAO[]" placeholder="ICAO" class="stationICAO" required>'+
'</span>'+
'<a href="#" class="removeStation" title="Remove this station"><i class="icon-minus-sign"></i></a>'+
'</p>';
return html;
}
function updateStationCount(n) {
if (n == 1) {
$('#stationCount').html(n + ' Station'); // singular
} else {
$('#stationCount').html(n + ' Stations'); // plural
}
}
function checkMaxStation(currentStations, sysMax) {
if (currentStations >= sysMax) {
alert("Sorry, but you cannot add anymore stations because you already have the maximum number of stations the system will allow.");
return false;
}
return true;
}
function checkMinStation(currentStations, minStations) {
if (currentStations <= minStations) {
alert("Sorry, but you cannot remove any more stations because this system requires a minimum of " + minStations + " station(s).");
return false;
}
return true;
}
// Main Scripts
$(window).load(function() {
$(function() {
var stationsDiv = $('#stationsWrap');
var i = $('#stationsWrap p').size();
updateStationCount(i);
$('.addStation').live('click', function(e) {
e.preventDefault();
if (checkMaxStation(i, maxSysStations)) {
i++;
$(htmlTemplate(i)).appendTo(stationsDiv);
updateStationCount(i);
}
return false;
});
$('.removeStation').live('click', function(e) {
e.preventDefault();
if (checkMinStation(i, minReqStations)) {
$(this).parents('p').remove();
i--;
updateStationCount(i);
}
return false;
});
$('#removeDefault').live('click', function(e) {
e.preventDefault();
$('.defaultStation').prop('checked', false);
$('.radio span').removeClass('checked');
});
});
}); //]]>