-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
187 lines (138 loc) · 4.75 KB
/
index.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<html>
<head>
<link rel="stylesheet" href="jquery-ui.css">
<link rel="stylesheet" href="style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link href='https://fonts.googleapis.com/css?family=Arimo' rel='stylesheet'>
</head>
<body>
<h1>Calendario</h1>
<hr>
<div class="wrapper">
<div class="profile">
<table id= "calendar" border="1">
<thead>
<th class="event">Event</th>
<th class="date">Date</th>
</thead>
<tbody>
</tbody>
</table> <br>
</div>
</div>
<table id= "form" border="0">
<tr><td><p>Start Date:</td> <td><input type="text" id="datep" value="2017-6-1" class="fdate"></p></td></tr>
<tr><td><p>Number of days:</td> <td><input type="number" id="numofdays" class="field"></p></td></tr>
<tr><td><p>Country code:</td> <td><input type="text" value="US" id="ccode" class="field"></p></td></tr>
</table>
<br>
<input type="hidden" id="calc" value="" class="calc">
<input type="hidden" id="year" value="" class="year">
<input type="hidden" id="month" value="" class="month">
<input type="hidden" id="gotodate" value="" class="gotodate">
<input type="hidden" id="gotodate1" value="" class="gotodate1">
<button id="load">Load</button>
<br><br>
<hr>
<div id="datepicker"></div><br><br>
<button id="clear">Clear</button>
<script>
// Date Field Conf
$( function () {
$( "#datep" ).datepicker({
dateFormat: 'yy-mm-dd',
onSelect: function (dateStr, inst) {
var nights = parseInt($('#numofdays').val());
var depart = $.datepicker.parseDate('yy-mm-dd', dateStr);
depart.setDate(depart.getDate('yy-mm-dd') + nights);
$('#calc').val(depart.toLocaleDateString() );
}
});
});
// Functions
var vdate1 = [];
var vdate2 = [];
$( "#clear" ).click(function() {
location.reload();
});
$( "#load" ).click(function() {
if ($("#datep").val() == "" || $("#numofdays").val() == "" || $("#ccode").val() == "" ) {
alert("Please Complete Fields!")
} else {
// Disable Button
$(this).prop("disabled",true);
// Get Date var
var date_data = $("#datep").val();
// Date format for redirection
var goto1 = $('#datep').val().replace(','-'-').split('-');
$('#gotodate1').val(goto1[0] + ',' + goto1[1] + ',' + goto1[2]);
var gotodate1 = $("#gotodate1").val();
$( function () {
// Refresh data
$( "#datep" ).datepicker({
dateFormat: 'yy-mm-dd',
onSelect: function (dateStr, inst) {
var nights = parseInt($('#numofdays').val());
var depart = $.datepicker.parseDate('yy-mm-dd', dateStr);
depart.setDate(depart.getDate('yy-mm-dd') + nights);
$('#calc').val(depart.toLocaleDateString() );
}
});
$('#datep').datepicker("setDate", new Date(gotodate1) );
$('.ui-datepicker-current-day').click();
});
$(function() {
// Date Format for DBs
var text2 = $('.fdate').val().split('-');
$('.year').val(text2[0]);
$('.month').val(text2[1]);
var text_value = $("#ccode").val();
var year = $("#year").val();
var month = $("#month").val();
// Get Events from JSON
$.getJSON("https://holidayapi.com/v1/holidays?key=5113a0f8-da9b-466a-bc7b-42ef7120acce&country=" + text_value + "&year=" + year + "&month=" + month + "", function(data) {
$.each(data.holidays, function(i, f) {
var tblRow = "<tr>" + "<td>" + f.name + "</td>" + "<td><input type='text' class='eventdt" + (i+1) + "' value='" + f.date + "'></td>" + "</tr>"
$(tblRow).appendTo("#calendar tbody");
// Event Format for Calendar
var text3 = $('.eventdt1').val().replace(','-'-').split('-');
$('.eventdt1').val(text3[1] + '/' + text3[2] + '/' + text3[0]);
var eventdt = $(".eventdt1").val();
var text = $('.calc').val().replace(','/'/').split('/');
$('.calc').val(text[2] + '-' + text[1] + '-' + text[0]);
var date2_calc = $("#calc").val();
// Get Range
vdate1.push(date_data);
vdate2.push(date2_calc);
var date1 = new Date(vdate1);
var date2 = new Date(vdate2);
var goto = $('#datep').val().replace(','-'-').split('-');
$('#gotodate').val(goto[1] + '/' + goto[2] + '/' + goto[0]);
var gotodate = $("#gotodate").val();
var dates = [eventdt];
$('#datepicker').datepicker({
dateFormat: 'yy-mm-dd',
defaultDate: new Date(gotodate),
beforeShowDay: show
});
function show (date) {
debugger
for (var i = 0; i < dates.length; i++) {
if (new Date(dates[i]).toString() == date.toString()) {
return [true, 'hld', "Evento"];
}
if (date >= date1 && date <= date2) {
return [true, 'ui-state-error', 'tooltipText'];
}1
}
return [false, '', '',];
}
});
});
});
$("#clear").css("display", "block");
}});
</script>
</body>
</html>