init
This commit is contained in:
1 parent
a419700c3d
commit
9ed30aff11
63 files changed
+2924
No files matched your search
Executable
+115
@@ -0,0 +1,115 @@
|
||||
//jQuery(document).ready(function ($) {
|
||||
(function ($, drupalSettings) {
|
||||
|
||||
'use strict';
|
||||
var allowedHours = drupalSettings.reservations.reservation_add.allowedHours;
|
||||
var reservationsObj = drupalSettings.reservations.reservation_add.reservations;
|
||||
var reservations =reservationsObj;
|
||||
// for(var x in reservationsObj){
|
||||
//// console.log(x);
|
||||
// console.log(reservationsObj[x]);
|
||||
// reservations[x]=reservationsObj[x];
|
||||
// }
|
||||
var currentdate = new Date();
|
||||
console.log(allowedHours);
|
||||
function getAllowedHours(currentDateTime) {
|
||||
var selected_court = $('#court').val();
|
||||
if(!selected_court){
|
||||
return [];
|
||||
}
|
||||
selected_court = "'"+selected_court + "'";
|
||||
var week_day = currentDateTime.getDay();
|
||||
week_day = "'"+week_day+"'";
|
||||
var curr_day = currentDateTime.getDate();
|
||||
console.log((""+curr_day).length);
|
||||
curr_day = ((""+curr_day).length>1)?curr_day:"0"+curr_day;
|
||||
var curr_month = currentDateTime.getMonth() + 1;
|
||||
curr_month = ((""+curr_month).length>1)?curr_month:"0"+curr_month;
|
||||
var curr_year = currentDateTime.getFullYear();
|
||||
var curr_date = "'" + curr_day + '.' + curr_month + '.' + curr_year + "'";
|
||||
var _array = [];
|
||||
// console.log(reservations);
|
||||
// console.log(reservations[curr_date]);
|
||||
// console.log(curr_date);
|
||||
console.log(curr_date);
|
||||
//
|
||||
// // change array if saturday(different working hours)
|
||||
_array = allowedHours[selected_court][week_day];
|
||||
// if (week_day == 6) {
|
||||
// remove_hours = ['09:30', '09:45', '18:00', '18:15', '18:30', '18:45'];
|
||||
// _array = allowedHours.filter(function (i) {
|
||||
// return !(remove_hours.indexOf(i) > -1);
|
||||
// })
|
||||
// } else {
|
||||
// _array = allowedHours;
|
||||
// }
|
||||
// z console.log(curr_date);
|
||||
// _array = JSON.parse("[" + _array + "]")
|
||||
console.log(_array);
|
||||
_array = _array.split(',');
|
||||
console.log(reservations[selected_court]);
|
||||
if (typeof reservations[selected_court] != "undefined" && typeof reservations[selected_court][curr_date] != "undefined") {
|
||||
_array = _array.filter(function (i) {
|
||||
return !(reservations[selected_court][curr_date].indexOf(i) > -1);
|
||||
});
|
||||
}
|
||||
console.log(_array);
|
||||
console.log("aaaa");
|
||||
// console.log(_array);
|
||||
return _array;
|
||||
}
|
||||
// var datetimepicker ;
|
||||
// function setObject(ct){
|
||||
// console.log(datetimepicker);
|
||||
// datetimepicker = this;
|
||||
// }
|
||||
function reloadHours(currentDateTime, $input) {
|
||||
var new_arr = getAllowedHours(currentDateTime);
|
||||
//console.log(new_arr);
|
||||
//console.log(["10:00", "15:00"]);
|
||||
// console.log(currentDateTime.getMonth());
|
||||
// console.log(currentDateTime.getDay());
|
||||
// console.log(currentDateTime.getDate());
|
||||
jQuery('#datetimepicker').datetimepicker({allowTimes: new_arr});
|
||||
|
||||
// $.datetimepicker.setOptions({
|
||||
// allowTimes: new_arr
|
||||
// });
|
||||
}
|
||||
|
||||
jQuery('#datetimepicker').datetimepicker({
|
||||
format: 'd.m.Y H:i',
|
||||
inline: true,
|
||||
lang: 'bg',
|
||||
// onShow: setObject,
|
||||
// onShow: function(ct){/*datetimepicker = this;*/alert('aaaaa')},
|
||||
// disabledWeekDays: [0],
|
||||
minDate: 0,
|
||||
// minTime: '12:00',
|
||||
allowTimes: getAllowedHours(currentdate),
|
||||
// allowTimes: [
|
||||
// '09:00',
|
||||
// '11:15',
|
||||
// '12:00',
|
||||
// '15:00',
|
||||
// '21:00'
|
||||
// ],
|
||||
step: 60,
|
||||
defaultDate: new Date(),
|
||||
dayOfWeekStart: 1,
|
||||
onSelectDate: reloadHours
|
||||
// theme:'dark'
|
||||
});
|
||||
$.datetimepicker.setLocale('bg');
|
||||
|
||||
$('#court').change(function(){
|
||||
if($(this).val()){
|
||||
$('#datetimepicker').parent().css("display", "block");
|
||||
reloadHours(currentdate);
|
||||
}else{
|
||||
$('#datetimepicker').parent().css("display", "none");
|
||||
}
|
||||
})
|
||||
|
||||
})(jQuery, drupalSettings);
|
||||
|
||||
Reference in new issue
Block a user