parent
a3d31c5cc3
commit
a94549f4c5
4 changed files with 49 additions and 39 deletions
30
frontend/templatetags/datecalc.py
Normal file
30
frontend/templatetags/datecalc.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
from django import template
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def seconds_from_date(date, seconds):
|
||||||
|
return date + timedelta(seconds=seconds)
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def hours_from_date(date, hours):
|
||||||
|
return date + timedelta(hours=hours)
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def days_from_date(date, days):
|
||||||
|
return date + timedelta(days=days)
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def seconds_from_now(seconds):
|
||||||
|
return seconds_from_date(timezone.now(), seconds)
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def hours_from_now(hours):
|
||||||
|
return hours_from_date(timezone.now(), hours)
|
||||||
|
|
||||||
|
@register.simple_tag
|
||||||
|
def days_from_now(days):
|
||||||
|
return days_from_date(timezone.now(), days)
|
|
@ -2,45 +2,23 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// Cache Selectors
|
$('.dpd1').each(function() {
|
||||||
var date1 =$('.dpd1'),
|
|
||||||
date2 =$('.dpd2'),
|
|
||||||
date3 =$('.dpd3');
|
|
||||||
|
|
||||||
|
var mindate = new Date($(this).attr("data-mindate"));
|
||||||
|
mindate = new Date(mindate.getFullYear(), mindate.getMonth(), mindate.getDate(), 0, 0, 0, 0)
|
||||||
|
|
||||||
//Date Picker//
|
var maxdate = new Date($(this).attr("data-maxdate"));
|
||||||
var nowTemp = new Date();
|
maxdate = new Date(maxdate.getFullYear(), maxdate.getMonth(), maxdate.getDate(), 0, 0, 0, 0)
|
||||||
var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
|
|
||||||
|
|
||||||
var checkin = date1.datepicker({
|
var checkin = $(this).datepicker({
|
||||||
format: 'dd.mm.yyyy',
|
format: 'dd.mm.yyyy',
|
||||||
onRender: function(date) {
|
onRender: function(date) {
|
||||||
return date.valueOf() < now.valueOf() ? 'disabled' : '';
|
return ((date.valueOf() < mindate.valueOf()) || (date.valueOf() > maxdate.valueOf())) ? 'disabled' : '';
|
||||||
}
|
}
|
||||||
}).on('changeDate', function(ev) {
|
}).on('changeDate', function(ev) {
|
||||||
if (ev.date.valueOf() > checkout.date.valueOf()) {
|
checkin.hide();
|
||||||
var newDate = new Date(ev.date)
|
}).data('datepicker');
|
||||||
newDate.setDate(newDate.getDate() + 1);
|
|
||||||
checkout.setValue(newDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
checkin.hide();
|
|
||||||
date2[0].focus();
|
|
||||||
|
|
||||||
}).data('datepicker');
|
|
||||||
|
|
||||||
var checkout = date2.datepicker({
|
|
||||||
format: 'dd.mm.yyyy',
|
|
||||||
onRender: function(date) {
|
|
||||||
return date.valueOf() <= checkin.date.valueOf() ? 'disabled' : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
}).on('changeDate', function(ev) {
|
|
||||||
checkout.hide();
|
|
||||||
}).data('datepicker');
|
|
||||||
|
|
||||||
date3.datepicker({
|
|
||||||
format: 'dd.mm.yyyy'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
|
@ -4,6 +4,7 @@
|
||||||
{% load mapimage %}
|
{% load mapimage %}
|
||||||
{% load dbsetting %}
|
{% load dbsetting %}
|
||||||
{% load mathfilters %}
|
{% load mathfilters %}
|
||||||
|
{% load datecalc %}
|
||||||
{% block "content" %}
|
{% block "content" %}
|
||||||
<!--================== PAGE-COVER ================-->
|
<!--================== PAGE-COVER ================-->
|
||||||
<section class="page-cover" id="cover-hotel-booking">
|
<section class="page-cover" id="cover-hotel-booking">
|
||||||
|
@ -130,7 +131,7 @@
|
||||||
<div class="form-group left-icon">
|
<div class="form-group left-icon">
|
||||||
<label>{% trans "Abreise" %}</label>
|
<label>{% trans "Abreise" %}</label>
|
||||||
<i class="fa fa-calendar"></i>
|
<i class="fa fa-calendar"></i>
|
||||||
<input id="id_departure" name="departure" type="text" class="form-control dpd1" required placeholder="{% trans "Abreise" %}" >
|
<input id="id_departure" data-mindate="{% days_from_date inquiry.arrival 1 %}" name="departure" type="text" class="form-control dpd1" required placeholder="{% trans "Abreise" %}" >
|
||||||
</div>
|
</div>
|
||||||
</div><!-- end columns -->
|
</div><!-- end columns -->
|
||||||
</div><!-- end row -->
|
</div><!-- end row -->
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
{% load testimonials %}
|
{% load testimonials %}
|
||||||
{% load dbsetting %}
|
{% load dbsetting %}
|
||||||
{% load offeroptions %}
|
{% load offeroptions %}
|
||||||
|
{% load datecalc %}
|
||||||
{% block "styles" %}
|
{% block "styles" %}
|
||||||
<link rel="stylesheet" href="{% static "vendor/css/jquery-ui.css" %}">
|
<link rel="stylesheet" href="{% static "vendor/css/jquery-ui.css" %}">
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -79,7 +80,7 @@
|
||||||
|
|
||||||
<div class="col-6 col-md-6 col-lg-6">
|
<div class="col-6 col-md-6 col-lg-6">
|
||||||
<div class="form-group left-icon">
|
<div class="form-group left-icon">
|
||||||
<input id="id_arrival" name="arrival" type="text" class="form-control dpd1" required placeholder="{% trans "Anreise" %}" >
|
<input id="id_arrival" data-mindate="{% hours_from_now 24 %}" name="arrival" type="text" class="form-control dpd1" required placeholder="{% trans "Anreise" %}" >
|
||||||
<i class="fa fa-calendar"></i>
|
<i class="fa fa-calendar"></i>
|
||||||
</div>
|
</div>
|
||||||
</div><!-- end columns -->
|
</div><!-- end columns -->
|
||||||
|
|
Loading…
Reference in a new issue