Last active
April 22, 2021 18:45
-
-
Save madcatgith/eacc30eab601e11090ce8ea04597659a to your computer and use it in GitHub Desktop.
Блокировка календаря выбора даты доставки bitrix. Добавление дополнительных свойств в шаблон. Блокирует все выходные дни, дает возможность выбрать 3 дня со следующего от даты доставки. Компонент sale.order.ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$arTemplateParameters = array( | |
/*блок параметров компонента*/ | |
/*...*/ | |
"HOLIDAYS" => array( | |
"NAME" => "Праздники", | |
"TYPE" => "STRING", | |
"DEFAULT" => "", | |
"PARENT" => "ADDITIONAL_SETTINGS" | |
), | |
"WORK_DAYS" => array( | |
"NAME" => "Рабочие дни", | |
"TYPE" => "STRING", | |
"DEFAULT" => "", | |
"PARENT" => "ADDITIONAL_SETTINGS" | |
), | |
/*...*/ | |
/*блок параметров компонента*/ | |
); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------------------------------------------------------------ | |
alterDateProperty: function(settings, inputText) | |
{ | |
var parentNode = BX.findParent(inputText, {tagName: 'DIV'}), | |
addon; | |
BX.addClass(parentNode, 'input-group'); | |
addon = BX.create('DIV', { | |
props: {className: 'input-group-addon'}, | |
children: [BX.create('I', {props: {className: 'bx-calendar'}})] | |
}); | |
BX.insertAfter(addon, inputText); | |
BX.remove(parentNode.querySelector('input[type=button]')); | |
BX.bind(addon, 'click', BX.delegate(function(e){ | |
var target = e.target || e.srcElement, | |
parentNode = BX.findParent(target, {tagName: 'DIV', className: 'input-group'}); | |
BX.calendar({ | |
node: parentNode.querySelector('.input-group-addon'), | |
field: parentNode.querySelector('input[type=text]').name, | |
form: '', | |
bTime: settings.TIME == 'Y', | |
bHideTime: false | |
}); | |
this.blockDates(); //Добавляем блокировку на событие открытия календаря | |
}, this)); | |
}, | |
//Функция блокировки дат в календаре | |
blockDates: function() | |
{ var today = false; | |
var dt = new Date(); | |
var time = dt.getHours(); | |
var holidays_stamps = []; | |
var work_stamps = []; | |
var tommorow = false; | |
if (time>16){ | |
tommorow = true; | |
} | |
//Празничные дни | |
var holidays_list = $("#holiday_list").val().split(","); //Достаем из скрытого input шаблона | |
$.each(holidays_list,function(index,item){ | |
var h = item.split("."); | |
var h_date = dt.getFullYear()+'-'+('0'+h[1]).slice(-2)+'-'+('0'+h[0]).slice(-2)+'T00:00:00+00:00'; | |
var h_timestamp = Date.parse(h_date); | |
holidays_stamps.push(h_timestamp); | |
}); | |
//Рабочие дни выпадающие на выходные | |
var work_list = $("#work_list").val().split(","); //Достаем из скрытого input шаблона | |
$.each(work_list,function(index,item){ | |
var w = item.split("."); | |
var w_date = dt.getFullYear()+'-'+('0'+w[1]).slice(-2)+'-'+('0'+w[0]).slice(-2)+'T00:00:00+00:00'; | |
var w_timestamp = Date.parse(w_date); | |
work_stamps.push(w_timestamp); | |
}); | |
var date = dt.getFullYear()+'-'+('0'+(dt.getMonth()+1)).slice(-2)+'-'+('0'+dt.getDate()).slice(-2)+'T00:00:00+00:00'; | |
var timestamp = Date.parse(date); | |
var i=0; | |
var xx=new Date(); | |
var k = 3; | |
var delivery_days=[]; | |
if (tommorow){i++;k++;} | |
while (i<k){ | |
i++; | |
var delivery_day = timestamp+(86400000*i); | |
if ($.inArray(delivery_day,work_stamps)==-1){ | |
xx.setTime(delivery_day); | |
if (xx.getDay()==6||xx.getDay()==0||($.inArray(delivery_day,holidays_stamps)>-1)){ | |
k++; | |
} | |
else{ | |
delivery_days.push(delivery_day); | |
} | |
} | |
else{ | |
delivery_days.push(delivery_day); | |
} | |
} | |
$('.bx-calendar-cell').each(function(){ | |
if ($.inArray($(this).data('date'),work_stamps)>-1){ | |
$(this).removeClass('bx-calendar-weekend'); | |
} | |
if ($.inArray($(this).data('date'),holidays_stamps)>-1){ | |
$(this).addClass('bx-calendar-weekend'); | |
} | |
if ($.inArray($(this).data('date'),delivery_days)==-1){ | |
if (today&&($(this).data('date')==timestamp)){ | |
}else{ | |
$(this).addClass("bx-calendar-date-hidden"); | |
$(this).click(function(){return false;}).dblclick(function(){return false;});} | |
} | |
else{ | |
$(this).addClass("bx-calendar-delivery"); | |
} | |
}); | |
$('.bx-calendar-weekend').click(function(){ | |
return false; | |
}).dblclick(function(){return false;}); | |
$('.bx-calendar-top-year').off().click(function(){return false;}).dblclick(function(){return false;}); | |
$('.bx-calendar-top-month').off().click(function(){return false;}).dblclick(function(){return false;}); | |
}, | |
//--------------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CALLENDAR */ | |
.bx-calendar-range .bx-calendar-delivery{ | |
background-color: #d4ffb8 | |
} | |
.bx-calendar-range .bx-calendar-active{ | |
background-color: #dce3ea; | |
} | |
.bx-calendar-right-arrow, .bx-calendar-left-arrow{ | |
display:none; | |
} | |
.bx-calendar-header-content{ | |
width:100%; | |
} | |
.bx-calendar-top-month, .bx-calendar-top-year{ | |
background: none; | |
padding-right: 5px; | |
} | |
.bx-calendar-top-month:hover, .bx-calendar-top-year:hover{ | |
background-color:#fff; | |
} | |
.bx-calendar-date-hidden:hover{ | |
/*cursor:default;*/ | |
background-color: #fff; | |
} | |
.bx-calendar-top-year, .bx-calendar-top-month{ | |
cursor:default; | |
} | |
.bx-calendar-weekend.bx-calendar-date-hidden{ | |
color: #d25050; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*...*/ | |
<input type="hidden" id="holiday_list" value="<?=$arParams["HOLIDAYS"]?>"> | |
<input type="hidden" id="work_list" value="<?=$arParams["WORK_DAYS"]?>"> | |
/*...*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment