-
Notifications
You must be signed in to change notification settings - Fork 0
/
datepicker.html
153 lines (120 loc) · 4.71 KB
/
datepicker.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
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
<!DOCTYPE html>
<!--
start a web server at 8000:
python -m SimpleHTTPServer 8000
-->
<html>
<head>
<title>datepicker test</title>
<script src="http://www.travelcostarica.nu/media/jui/js/jquery.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.11.3/jquery-ui.js" type="text/javascript"></script>
<script src="http://www.travelcostarica.nu/libraries/cegcore/assets/jquery/jquery.js" type="text/javascript"></script>
<link href="http://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var cars = [];
var highSeasonStart = new Date("January 01, 2015 00:00:00");
highSeasonStart.getTimezoneOffset();
highSeasonStart.setMonth(0);
highSeasonStart.setDate(1);
var highSeasonEnd = new Date("June 11, 2015 00:00:00");
highSeasonEnd.getTimezoneOffset();
highSeasonEnd.setMonth(5);
highSeasonEnd.setDate(11);
jQuery(document).ready(function(jQuery) {
jQuery('#from').datepicker({
dateFormat: 'dd-mm-yy',
defaultDate: '+1w',
changeMonth: true,
numberOfMonths: 3,
onClose: function(selectedDate) {
jQuery('#to').datepicker('option', 'minDate', selectedDate);
}
});
jQuery('#to').datepicker({
dateFormat: 'dd-mm-yy',
defaultDate: '+1w',
changeMonth: true,
numberOfMonths: 3,
onClose: function(selectedDate) {
jQuery('#from').datepicker('option', 'maxDate', selectedDate);
}
});
$.getJSON( "cars.json", function( data ) {
$.each( data, function( key, val ) {
cars.push(val);
});
});
// initialize options from cars and add onchange event handler
$( "#car_type, #from, #to" ).change(function() {
if($(this).val().length !== 0){
displayVals();
}
});
});
function displayVals() {
// display rental dates and calculate rental days
var rentalFrom = $('#from').datepicker('getDate');
var rentalFromPlainText = $('#from').val();
var rentalTo = $('#to').datepicker('getDate');
var rentalDays = Math.floor((rentalTo.getTime() - rentalFrom.getTime()) / 86400000);
//set high season
rentalFrom >= highSeasonStart && rentalFrom <=highSeasonEnd ? highSeason = true : highSeason = false ;
var Car = function(name, baseRate, weeklyRate) {
this.Name = name;
this.BaseRate = baseRate; // [highSeason, LowSeason]
this.WeeklyRate = weeklyRate; // [highSeason, LowSeason]
};
var model;
for (index = 0; index < cars.length; index++) {
if (cars[index].Name == $('#car_type').val())
{
model = new Car(cars[index].Name, cars[index].BaseRate, cars[index].WeeklyRate );
}
}
// calculate price
Car.prototype.TotalPrice = function() {
var appliedRate = (rentalDays >= 7) ? this.WeeklyRate : this.BaseRate;
if(highSeason){
return appliedRate[0] * rentalDays;
} else {
return appliedRate[1] * rentalDays;
}
};
var appliedRateOutside = model.TotalPrice() / rentalDays ;
$('.rentalPeriodFrom').text(rentalFrom);
$('.rentalPeriodTo').text(rentalTo);
$('.fromTestPlain').text(rentalFromPlainText);
$('.daysAmount').text(rentalDays);
$('.totalCost').text(model.TotalPrice());
$('.rentalRate').text(appliedRateOutside);
$('.rentalModel').text(model.Name);
$(".seasonTest").text(highSeason);
alert(highSeason);
};
</script>
</head>
<body>
<input name="from_date" id="from" type="text" size="8" class="validate['required']" placeholder="date" />
<label for="from_date" class="sub-label">from <span style="color:#ff0000; font-size:12px; vertical-align:top;">*</span></label>
<input name="to_date" id="to" type="text" size="8" class="validate['required']" placeholder="date" />
<label for="to_date" class="sub-label">to <span style="color:#ff0000; font-size:12px; vertical-align:top;">*</span></label>
<div style="clear:both"></div>
<label for="car_type" class="label-left topmargin10">Car Type/Model</label>
<select id="car_type" name="car_type">
<option value="Daihatsu Bego">Daihatsu Bego</option>
<option value="Suzuki Gran Vitara II" selected>Suzuki Gran Vitara II</option>
<option value="Hyundai Tucson">Hyundai Tucson</option>
</select>
<p><b>Is it high season?</b> <span class="seasonTest"></span></p>
<p><b>Rental From:</b> <span class="rentalPeriodFrom"></span></p>
<p><b>Rental To:</b> <span class="rentalPeriodTo"></span></p>
<p>(Plain Text Rental From: <span class="fromTestPlain"></span>)</p>
<p><b>Amount of Days:</b> <span class="daysAmount"></span></p>
<p><b>Total Price: USD</b> <span class="totalCost"></span>$</p>
<p>(<span class="rentalRate"></span>$ per day)</p>
<p><b>Model:</b> <span class="rentalModel"></p>
<label for="newlist" class="label-left topmargin10">New List</label>
<select id="newlist" name="newlist">
<option value="Daihatsu Bego">hello</option>
</select>
</body>