mphb.js diff for global locked date

Created Diff never expires
"use strict";
"use strict";


(function ($) {
(function ($) {
$(function () {
$(function () {
MPHB.DateRules = can.Construct.extend({}, {
MPHB.DateRules = can.Construct.extend({}, {
dates: {},
dates: {},
init: function init(dates) {
init: function init(dates) {
this.dates = dates;
this.dates = dates;
},
},


/**
/**
*
*
* @param {Date} date
* @param {Date} date
* @returns {Boolean}
* @returns {Boolean}
*/
*/
canCheckIn: function canCheckIn(date) {
canCheckIn: function canCheckIn(date) {
var formattedDate = this.formatDate(date);
var formattedDate = this.formatDate(date);


if (!this.dates.hasOwnProperty(formattedDate)) {
if (!this.dates.hasOwnProperty(formattedDate)) {
return true;
return true;
}
}


return !this.dates[formattedDate].not_check_in && !this.dates[formattedDate].not_stay_in;
return !this.dates[formattedDate].not_check_in && !this.dates[formattedDate].not_stay_in;
},
},


/**
/**
*
*
* @param {Date} date
* @param {Date} date
* @returns {Boolean}
* @returns {Boolean}
*/
*/
canCheckOut: function canCheckOut(date) {
canCheckOut: function canCheckOut(date) {
var formattedDate = this.formatDate(date);
var formattedDate = this.formatDate(date);


if (!this.dates.hasOwnProperty(formattedDate)) {
if (!this.dates.hasOwnProperty(formattedDate)) {
return true;
return true;
}
}


return !this.dates[formattedDate].not_check_out;
return !this.dates[formattedDate].not_check_out;
},
},


/**
/**
*
*
* @param {Date} date
* @param {Date} date
* @returns {Boolean}
* @returns {Boolean}
*/
*/
canStayIn: function canStayIn(date) {
canStayIn: function canStayIn(date) {
var formattedDate = this.formatDate(date);
var formattedDate = this.formatDate(date);


if (!this.dates.hasOwnProperty(formattedDate)) {
if (!this.dates.hasOwnProperty(formattedDate)) {
return true;
return true;
}
}


return !this.dates[formattedDate].not_stay_in;
return !this.dates[formattedDate].not_stay_in;
},
},


/**
/**
*
*
* @param {Date} dateFrom
* @param {Date} dateFrom
* @param {Date} stopDate
* @param {Date} stopDate
* @returns {Date}
* @returns {Date}
*/
*/
getNearestNotStayInDate: function getNearestNotStayInDate(dateFrom, stopDate) {
getNearestNotStayInDate: function getNearestNotStayInDate(dateFrom, stopDate) {
var nearestDate = MPHB.Utils.cloneDate(stopDate);
var nearestDate = MPHB.Utils.cloneDate(stopDate);
var dateFromFormatted = $.datepick.formatDate('yyyy-mm-dd', dateFrom);
var dateFromFormatted = $.datepick.formatDate('yyyy-mm-dd', dateFrom);
var stopDateFormatted = $.datepick.formatDate('yyyy-mm-dd', stopDate);
var stopDateFormatted = $.datepick.formatDate('yyyy-mm-dd', stopDate);
$.each(this.dates, function (ruleDate, rule) {
$.each(this.dates, function (ruleDate, rule) {
if (ruleDate > stopDateFormatted) {
if (ruleDate > stopDateFormatted) {
return false;
return false;
}
}


if (dateFromFormatted > ruleDate) {
if (dateFromFormatted > ruleDate) {
return true;
return true;
}
}


if (rule.not_stay_in) {
if (rule.not_stay_in) {
nearestDate = $.datepick.parseDate('yyyy-mm-dd', ruleDate);
nearestDate = $.datepick.parseDate('yyyy-mm-dd', ruleDate);
return false;
return false;
}
}
});
});
return nearestDate;
return nearestDate;
},
},


/**
/**
*
*
* @param {Date} date
* @param {Date} date
* @returns {string}
* @returns {string}
*/
*/
formatDate: function formatDate(date) {
formatDate: function formatDate(date) {
return $.datepick.formatDate('yyyy-mm-dd', date);
return $.datepick.formatDate('yyyy-mm-dd', date);
}
}
});
});
/**
/**
* @class MPHB.Datepicker
* @class MPHB.Datepicker
*/
*/


can.Control('MPHB.Datepicker', {}, {
can.Control('MPHB.Datepicker', {}, {
form: null,
form: null,
hiddenElement: null,
hiddenElement: null,
roomTypeId: null,
roomTypeId: null,
init: function init(el, args) {
init: function init(el, args) {
this.form = args.form;
this.form = args.form;
this.roomTypeId = args.hasOwnProperty('roomTypeId') ? args.roomTypeId : 0;
this.roomTypeId = args.hasOwnProperty('roomTypeId') ? args.roomTypeId : 0;
this.setupHiddenElement();
this.setupHiddenElement();
this.initDatepick();
this.initDatepick();
},
},
setupHiddenElement: function setupHiddenElement() {
setupHiddenElement: function setupHiddenElement() {
var hiddenElementId = this.element.attr('id') + '-hidden';
var hiddenElementId = this.element.attr('id') + '-hidden';
this.hiddenElement = $('#' + hiddenElementId); // fix date
this.hiddenElement = $('#' + hiddenElementId); // fix date


if (!this.hiddenElement.val()) {// this.element.val( '' );
if (!this.hiddenElement.val()) {// this.element.val( '' );
} else {
} else {
var date = $.datepick.parseDate(MPHB._data.settings.dateTransferFormat, this.hiddenElement.val());
var date = $.datepick.parseDate(MPHB._data.settings.dateTransferFormat, this.hiddenElement.val());
var fixedValue = $.datepick.formatDate(MPHB._data.settings.dateFormat, date);
var fixedValue = $.datepick.formatDate(MPHB._data.settings.dateFormat, date);
this.element.val(fixedValue);
this.element.val(fixedValue);
}
}
},
},
initDatepick: function initDatepick() {
initDatepick: function initDatepick() {
var defaultSettings = {
var defaultSettings = {
dateFormat: MPHB._data.settings.dateFormat,
dateFormat: MPHB._data.settings.dateFormat,
altFormat: MPHB._data.settings.dateTransferFormat,
altFormat: MPHB._data.settings.dateTransferFormat,
altField: this.hiddenElement,
altField: this.hiddenElement,
minDate: MPHB.HotelDataManager.myThis.today,
minDate: MPHB.HotelDataManager.myThis.today,
monthsToShow: MPHB._data.settings.numberOfMonthDatepicker,
monthsToShow: MPHB._data.settings.numberOfMonthDatepicker,
firstDay: MPHB._data.settings.firstDay,
firstDay: MPHB._data.settings.firstDay,
pickerClass: MPHB._data.settings.datepickerClass,
pickerClass: MPHB._data.settings.datepickerClass,
useMouseWheel: false
useMouseWheel: false
};
};
var datepickSettings = $.extend(defaultSettings, this.getDatepickSettings());
var datepickSettings = $.extend(defaultSettings, this.getDatepickSettings());
this.element.datepick(datepickSettings);
this.element.datepick(datepickSettings);
},
},


/**
/**
*
*
* @returns {Object}
* @returns {Object}
*/
*/
getDatepickSettings: function getDatepickSettings() {
getDatepickSettings: function getDatepickSettings() {
return {};
return {};
},
},


/**
/**
* @return {Date|null}
* @return {Date|null}
*/
*/
getDate: function getDate() {
getDate: function getDate() {
var dateStr = this.element.val();
var dateStr = this.element.val();
var date = null;
var date = null;


try {
try {
date = $.datepick.parseDate(MPHB._data.settings.dateFormat, dateStr);
date = $.datepick.parseDate(MPHB._data.settings.dateFormat, dateStr);
} catch (e) {
} catch (e) {
date = null;
date = null;
}
}


return date;
return date;
},
},


/**
/**
*
*
* @param {string} format Optional. Datepicker format by default.
* @param {string} format Optional. Datepicker format by default.
* @returns {String} Date string or empty string.
* @returns {String} Date string or empty string.
*/
*/
getFormattedDate: function getFormattedDate(format) {
getFormattedDate: function getFormattedDate(format) {
if (typeof format === 'undefined') {
if (typeof format === 'undefined') {
format = MPHB._data.settings.dateFormat;
format = MPHB._data.settings.dateFormat;
}
}


var date = this.getDate();
var date = this.getDate();
return date ? $.datepick.formatDate(format, date) : '';
return date ? $.datepick.formatDate(format, date) : '';
},
},


/**
/**
* @param {Date} date
* @param {Date} date
*/
*/
setDate: function setDate(date) {
setDate: function setDate(date) {
this.element.datepick('setDate', date);
this.element.datepick('setDate', date);
},
},


/**
/**
* @param {string} option
* @param {string} option
*/
*/
getOption: function getOption(option) {
getOption: function getOption(option) {
return this.element.datepick('option', option);
return this.element.datepick('option', option);
},
},


/**
/**
* @param {string} option
* @param {string} option
* @param {mixed} value
* @param {mixed} value
*/
*/
setOption: function setOption(option, value) {
setOption: function setOption(option, value) {
this.element.datepick('option', option, value);
this.element.datepick('option', option, value);
},
},


/**
/**
*
*
* @returns {Date|null}
* @returns {Date|null}
*/
*/
getMinDate: function getMinDate() {
getMinDate: function getMinDate() {
var minDate = this.getOption('minDate');
var minDate = this.getOption('minDate');
return minDate !== null && minDate !== '' ? MPHB.Utils.cloneDate(minDate) : null;
return minDate !== null && minDate !== '' ? MPHB.Utils.cloneDate(minDate) : null;
},
},


/**
/**
*
*
* @returns {Date|null}
* @returns {Date|null}
*/
*/
getMaxDate: function getMaxDate() {
getMaxDate: function getMaxDate() {
var maxDate = this.getOption('maxDate');
var maxDate = this.getOption('maxDate');
return maxDate !== null && maxDate !== '' ? MPHB.Utils.cloneDate(maxDate) : null;
return maxDate !== null && maxDate !== '' ? MPHB.Utils.cloneDate(maxDate) : null;
},
},


/**
/**
*
*
* @returns {Date|null}
* @returns {Date|null}
*/
*/
getMaxAdvanceDate: function getMaxAdvanceDate() {
getMaxAdvanceDate: function getMaxAdvanceDate() {
var maxAdvanceDate = this.getOption('maxAdvanceDate');
var maxAdvanceDate = this.getOption('maxAdvanceDate');
return maxAdvanceDate ? MPHB.Utils.cloneDate(maxAdvanceDate) : null;
return maxAdvanceDate ? MPHB.Utils.cloneDate(maxAdvanceDate) : null;
},
},


/**
/**
*
*
* @returns {undefined}
* @returns {undefined}
*/
*/
clear: function clear() {
clear: function clear() {
this.element.datepick('clear');
this.element.datepick('clear');
},
},


/**
/**
* @param {Date} date
* @param {Date} date
* @param {string} format Optional. Default 'yyyy-mm-dd'.
* @param {string} format Optional. Default 'yyyy-mm-dd'.
*/
*/
formatDate: function formatDate(date, format) {
formatDate: function formatDate(date, format) {
format = typeof format !== 'undefined' ? format : 'yyyy-mm-dd';
format = typeof format !== 'undefined' ? format : 'yyyy-mm-dd';
return $.datepick.formatDate(format, date);
return $.datepick.formatDate(format, date);
},
},


/**
/**
*
*
* @returns {undefined}
* @returns {undefined}
*/
*/
refresh: function refresh() {
refresh: function refresh() {
$.datepick._update(this.element[0], true);
$.datepick._update(this.element[0], true);


$.datepick._updateInput(this.element[0], false);
$.datepick._updateInput(this.element[0], false);
}
}
});
});
MPHB.FlexsliderGallery = can.Control.extend({}, {
MPHB.FlexsliderGallery = can.Control.extend({}, {
sliderEl: null,
sliderEl: null,
navSliderEl: null,
navSliderEl: null,
groupId: null,
groupId: null,
init: function init(sliderEl, args) {
init: function init(sliderEl, args) {
this.sliderEl = sliderEl;
this.sliderEl = sliderEl;
this.groupId = sliderEl.data('group');
this.groupId = sliderEl.data('group');
var navSliderEl = $('.mphb-gallery-thumbnail-slider[data-group="' + this.groupId + '"]');
var navSliderEl = $('.mphb-gallery-thumbnail-slider[data-group="' + this.groupId + '"]');


if (navSliderEl.length) {
if (navSliderEl.length) {
this.navSliderEl = navSliderEl;
this.navSliderEl = navSliderEl;
}
}


var self = this;
var self = this;
$(window).on('load', function () {
$(window).on('load', function () {
self.initSliders();
self.initSliders();
}); // Load immediately is the window already loaded
}); // Load immediately is the window already loaded


if (document.readyState == 'complete') {
if (document.readyState == 'complete') {
this.initSliders();
this.initSliders();
}
}
},
},
initSliders: function initSliders() {
initSliders: function initSliders() {
if (this.slidersLoaded) {
if (this.slidersLoaded) {
return;
return;
}
}


var sliderAtts = this.sliderEl.data('flexslider-atts');
var sliderAtts = this.sliderEl.data('flexslider-atts');


if (this.navSliderEl) {
if (this.navSliderEl) {
var navSliderAtts = this.navSliderEl.data('flexslider-atts');
var navSliderAtts = this.navSliderEl.data('flexslider-atts');
navSliderAtts['asNavFor'] = '.mphb-flexslider-gallery-wrapper[data-group="' + this.groupId + '"]';
navSliderAtts['asNavFor'] = '.mphb-flexslider-gallery-wrapper[data-group="' + this.groupId + '"]';
navSliderAtts['itemWidth'] = this.navSliderEl.find('ul > li img').width();
navSliderAtts['itemWidth'] = this.navSliderEl.find('ul > li img').width();
sliderAtts['sync'] = '.mphb-gallery-thumbnail-slider[data-group="' + this.groupId + '"]'; // The slider being synced must be initialized first
sliderAtts['sync'] = '.mphb-gallery-thumbnail-slider[data-group="' + this.groupId + '"]'; // The slider being synced must be initialized first


this.navSliderEl.addClass('flexslider mphb-flexslider mphb-gallery-thumbnails-slider').flexslider(navSliderAtts);
this.navSliderEl.addClass('flexslider mphb-flexslider mphb-gallery-thumbnails-slider').flexslider(navSliderAtts);
}
}


this.sliderEl.addClass('flexslider mphb-flexslider mphb-gallery-slider').flexslider(sliderAtts);
this.sliderEl.addClass('flexslider mphb-flexslider mphb-gallery-slider').flexslider(sliderAtts);
this.slidersLoaded = true;
this.slidersLoaded = true;
}
}
});
});
/**
/**
* @see MPHB.format_price() in admin/admin.js
* @see MPHB.format_price() in admin/admin.js
*/
*/


MPHB.format_price = function (price, atts) {
MPHB.format_price = function (price, atts) {
atts = atts || {};
atts = atts || {};
var defaultAtts = MPHB._data.settings.currency;
var defaultAtts = MPHB._data.settings.currency;
atts = $.extend({
atts = $.extend({
'trim_zeros': false
'trim_zeros': false
}, defaultAtts, atts);
}, defaultAtts, atts);
price = MPHB.number_format(price, atts['decimals'], atts['decimal_separator'], atts['thousand_separator']);
price = MPHB.number_format(price, atts['decimals'], atts['decimal_separator'], atts['thousand_separator']);
var formattedPrice = atts['price_format'].replace('%s', price);
var formattedPrice = atts['price_format'].replace('%s', price);


if (atts['trim_zeros']) {
if (atts['trim_zeros']) {
var regex = new RegExp('\\' + atts['decimal_separator'] + '0+$|(\\' + atts['decimal_separator'] + '\\d*[1-9])0+$');
var regex = new RegExp('\\' + atts['decimal_separator'] + '0+$|(\\' + atts['decimal_separator'] + '\\d*[1-9])0+$');
formattedPrice = formattedPrice.replace(regex, '$1');
formattedPrice = formattedPrice.replace(regex, '$1');
}
}


var priceHtml = '<span class="mphb-price">' + formattedPrice + '</span>';
var priceHtml = '<span class="mphb-price">' + formattedPrice + '</span>';
return priceHtml;
return priceHtml;
};
};
/**
/**
* @see MPHB.number_format() in admin/admin.js
* @see MPHB.number_format() in admin/admin.js
*/
*/




MPHB.number_format = function (number, decimals, dec_point, thousands_sep) {
MPHB.number_format = function (number, decimals, dec_point, thousands_sep) {
// + Original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// + Original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// + Improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + Improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + Bugfix by: Michael White (http://crestidg.com)
// + Bugfix by: Michael White (http://crestidg.com)
var sign = '',
var sign = '',
i,
i,
j,
j,
kw,
kw,
kd,
kd,
km; // Input sanitation & defaults
km; // Input sanitation & defaults


decimals = decimals || 0;
decimals = decimals || 0;
dec_point = dec_point || '.';
dec_point = dec_point || '.';
thousands_sep = thousands_sep || ',';
thousands_sep = thousands_sep || ',';


if (number < 0) {
if (number < 0) {
sign = '-';
sign = '-';
number *= -1;
number *= -1;
}
}


i = parseInt(number = (+number || 0).toFixed(decimals)) + '';
i = parseInt(number = (+number || 0).toFixed(decimals)) + '';


if ((j = i.length) > 3) {
if ((j = i.length) > 3) {
j = j % 3;
j = j % 3;
} else {
} else {
j = 0;
j = 0;
}
}


km = j ? i.substr(0, j) + thousands_sep : '';
km = j ? i.substr(0, j) + thousands_sep : '';
kw = i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousands_sep);
kw = i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousands_sep);
kd = decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : '';
kd = decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : '';
return sign + km + kw + kd;
return sign + km + kw + kd;
};
};
/**
/**
* @param {String} action Action name (without prefix "mphb_").
* @param {String} action Action name (without prefix "mphb_").
* @param {Object} data
* @param {Object} data
* @param {Object} callbacks "success", "error", "complete".
* @param {Object} callbacks "success", "error", "complete".
* @returns {Object} The jQuery XMLHttpRequest object.
* @returns {Object} The jQuery XMLHttpRequest object.
*
*
* @since 3.6.0
* @since 3.6.0
*/
*/




MPHB.post = function (action, data, callbacks) {
MPHB.post = function (action, data, callbacks) {
action = 'mphb_' + action;
action = 'mphb_' + action;
data = $.extend({
data = $.extend({
action: action,
action: action,
mphb_nonce: MPHB._data.nonces[action],
mphb_nonce: MPHB._data.nonces[action],
lang: MPHB._data.settings.currentLanguage
lang: MPHB._data.settings.currentLanguage
}, data);
}, data);
var ajaxArgs = $.extend({
var ajaxArgs = $.extend({
url: MPHB._data.ajaxUrl,
url: MPHB._data.ajaxUrl,
type: 'POST',
type: 'POST',
dataType: 'json',
dataType: 'json',
data: data
data: data
}, callbacks);
}, callbacks);
return $.ajax(ajaxArgs);
return $.ajax(ajaxArgs);
};
};
/**
/**
* @class MPHB.Season
* @class MPHB.Season
*/
*/




can.Construct('MPHB.Season', {}, {
can.Construct('MPHB.Season', {}, {
/**
/**
* @var {Date}
* @var {Date}
*/
*/
startDate: null,
startDate: null,


/**
/**
* @var {Date}
* @var {Date}
*/
*/
endDate: null,
endDate: null,


/**
/**
* @var {number[]}
* @var {number[]}
*/
*/
allowedDays: [],
allowedDays: [],


/**
/**
*
*
* @param {{start_date: string, end_date: string, allowed_days: Array}} data
* @param {{start_date: string, end_date: string, allowed_days: Array}} data
*/
*/
init: function init(data) {
init: function init(data) {
var dateFormat = MPHB._data.settings.dateTransferFormat;
var dateFormat = MPHB._data.settings.dateTransferFormat;
this.startDate = $.datepick.parseDate(dateFormat, data.start_date);
this.startDate = $.datepick.parseDate(dateFormat, data.start_date);
this.endDate = $.datepick.parseDate(dateFormat, data.end_date);
this.endDate = $.datepick.parseDate(dateFormat, data.end_date);
this.allowedDays = data.allowed_days;
this.allowedDays = data.allowed_days;
},
},


/**
/**
* Check is season contain date
* Check is season contain date
*
*
* @param {Date} date
* @param {Date} date
* @return {boolean}
* @return {boolean}
*/
*/
isContainDate: function isContainDate(date) {
isContainDate: function isContainDate(date) {
return date >= this.startDate && date <= this.endDate && MPHB.Utils.inArray(date.getDay(), this.allowedDays);
return date >= this.startDate && date <= this.endDate && MPHB.Utils.inArray(date.getDay(), this.allowedDays);
}
}
});
});
MPHB.ReservationRulesChecker = can.Construct.extend({
MPHB.ReservationRulesChecker = can.Construct.extend({
myThis: null
myThis: null
}, {
}, {
rules: {
rules: {
checkInDays: {},
checkInDays: {},
checkOutDays: {},
checkOutDays: {},
minStay: {},
minStay: {},
maxStay: {},
maxStay: {},
minAdvance: {},
minAdvance: {},
maxAdvance: {}
maxAdvance: {}
},
},
init: function init(rulesByTypes) {
init: function init(rulesByTypes) {
this.rules.checkInDays = $.map(rulesByTypes['check_in_days'], function (ruleDetails) {
this.rules.checkInDays = $.map(rulesByTypes['check_in_days'], function (ruleDetails) {
return new MPHB.Rules.CheckInDayRule(ruleDetails);
return new MPHB.Rules.CheckInDayRule(ruleDetails);
});
});
this.rules.checkOutDays = $.map(rulesByTypes['check_out_days'], function (ruleDetails) {
this.rules.checkOutDays = $.map(rulesByTypes['check_out_days'], function (ruleDetails) {
return new MPHB.Rules.CheckOutDayRule(ruleDetails);
return new MPHB.Rules.CheckOutDayRule(ruleDetails);
});
});
this.rules.minStay = $.map(rulesByTypes['min_stay_length'], function (ruleDetails) {
this.rules.minStay = $.map(rulesByTypes['min_stay_length'], function (ruleDetails) {
return new MPHB.Rules.MinDaysRule(ruleDetails);
return new MPHB.Rules.MinDaysRule(ruleDetails);
});
});
this.rules.maxStay = $.map(rulesByTypes['max_stay_length'], function (ruleDetails) {
this.rules.maxStay = $.map(rulesByTypes['max_stay_length'], function (ruleDetails) {
return new MPHB.Rules.MaxDaysRule(ruleDetails);
return new MPHB.Rules.MaxDaysRule(ruleDetails);
});
});
this.rules.minAdvance = $.map(rulesByTypes['min_advance_reservation'], function (ruleDetails) {
this.rules.minAdvance = $.map(rulesByTypes['min_advance_reservation'], function (ruleDetails) {
return new MPHB.Rules.MinAdvanceDaysRule(ruleDetails);
return new MPHB.Rules.MinAdvanceDaysRule(ruleDetails);
});
});
this.rules.maxAdvance = $.map(rulesByTypes['max_advance_reservation'], function (ruleDetails) {
this.rules.maxAdvance = $.map(rulesByTypes['max_advance_reservation'], function (ruleDetails) {
return new MPHB.Rules.MaxAdvanceDaysRule(ruleDetails);
return new MPHB.Rules.MaxAdvanceDaysRule(ruleDetails);
});
});
},
},


/**
/**
*
*
* @param {string} type
* @param {string} type
* @param {Date} date
* @param {Date} date
* @param {int} roomTypeId
* @param {int} roomTypeId
* @return {*}
* @return {*}
*/
*/
getActualRule: function getActualRule(type, date, roomTypeId) {
getActualRule: function getActualRule(type, date, roomTypeId) {
var actualRule = null;
var actualRule = null;
$.each(this.rules[type], function (index, rule) {
$.each(this.rules[type], function (index, rule) {
if (rule.isActualRule(date, roomTypeId)) {
if (rule.isActualRule(date, roomTypeId)) {
actualRule = rule;
actualRule = rule;
return false; // break;
return false; // break;
}
}
});
});
return actualRule;
return actualRule;
},
},
getActualCombinedRule: function getActualCombinedRule(type, date) {
getActualCombinedRule: function getActualCombinedRule(type, date) {
var processedRoomTypes = [];
var processedRoomTypes = [];
var actualRules = [];
var actualRules = [];
$.each(this.rules[type], function (index, rule) {
$.each(this.rules[type], function (index, rule) {
var roomTypes = MPHB.Utils.arrayDiff(rule.roomTypeIds, processedRoomTypes);
var roomTypes = MPHB.Utils.arrayDiff(rule.roomTypeIds, processedRoomTypes);


if (!roomTypes.length) {
if (!roomTypes.length) {
return; // continue
return; // continue
}
}


if (!rule.isActualForDate(date)) {
if (!rule.isActualForDate(date)) {
return; // continue
return; // continue
}
}


actualRules.push(rule);
actualRules.push(rule);
processedRoomTypes = processedRoomTypes.concat(roomTypes);
processedRoomTypes = processedRoomTypes.concat(roomTypes);


if (rule.isAllRoomTypeRule()) {
if (rule.isAllRoomTypeRule()) {
return false; // break
return false; // break
} // All Room Processed
} // All Room Processed




if (!MPHB.Utils.arrayDiff(MPHB._data.allRoomTypeIds, processedRoomTypes).length) {
if (!MPHB.Utils.arrayDiff(MPHB._data.allRoomTypeIds, processedRoomTypes).length) {
return false; // break
return false; // break
}
}
});
});
return this.combineRules(type, actualRules);
return this.combineRules(type, actualRules);
},
},
combineRules: function combineRules(type, rules) {
combineRules: function combineRules(type, rules) {
var rule;
var rule;


switch (type) {
switch (type) {
case 'checkInDays':
case 'checkInDays':
var days = [];
var days = [];
$.each(rules, function (index, rule) {
$.each(rules, function (index, rule) {
days = days.concat(rule.days);
days = days.concat(rule.days);
});
});
days = MPHB.Utils.arrayUnique(days);
days = MPHB.Utils.arrayUnique(days);
rule = new MPHB.Rules.CheckInDayRule({
rule = new MPHB.Rules.CheckInDayRule({
season_ids: [0],
season_ids: [0],
room_type_ids: [0],
room_type_ids: [0],
check_in_days: days
check_in_days: days
});
});
break;
break;


case 'checkOutDays':
case 'checkOutDays':
var days = [];
var days = [];
$.each(rules, function (index, rule) {
$.each(rules, function (index, rule) {
days = days.concat(rule.days);
days = days.concat(rule.days);
});
});
days = MPHB.Utils.arrayUnique(days);
days = MPHB.Utils.arrayUnique(days);
rule = new MPHB.Rules.CheckOutDayRule({
rule = new MPHB.Rules.CheckOutDayRule({
season_ids: [0],
season_ids: [0],
room_type_ids: [0],
room_type_ids: [0],
check_out_days: days
check_out_days: days
});
});
break;
break;


case 'minStay':
case 'minStay':
var softRule = MPHB.Utils.arrayMin($.map(rules, function (rule) {
var softRule = MPHB.Utils.arrayMin($.map(rules, function (rule) {
return rule.min;
return rule.min;
}));
}));
rule = new MPHB.Rules.MinDaysRule({
rule = new MPHB.Rules.MinDaysRule({
season_ids: [0],
season_ids: [0],
room_type_ids: [0],
room_type_ids: [0],
min_stay_length: softRule
min_stay_length: softRule
});
});
break;
break;


case 'maxStay':
case 'maxStay':
var softRule = MPHB.Utils.arrayMax($.map(rules, function (rule) {
var softRule = MPHB.Utils.arrayMax($.map(rules, function (rule) {
return rule.max;
return rule.max;
}));
}));
rule = new MPHB.Rules.MaxDaysRule({
rule = new MPHB.Rules.MaxDaysRule({
season_ids: [0],
season_ids: [0],
room_type_ids: [0],
room_type_ids: [0],
max_stay_length: softRule
max_stay_length: softRule
});
});
break;
break;


case 'minAdvance':
case 'minAdvance':
var softRule = MPHB.Utils.arrayMin($.map(rules, function (rule) {
var softRule = MPHB.Utils.arrayMin($.map(rules, function (rule) {
return rule.min;
return rule.min;
}));
}));
rule = new MPHB.Rules.MinAdvanceDaysRule({
rule = new MPHB.Rules.MinAdvanceDaysRule({
season_ids: [0],
season_ids: [0],
room_type_ids: [0],
room_type_ids: [0],
min_advance_reservation: softRule
min_advance_reservation: softRule
});
});
break;
break;


case 'maxAdvance':
case 'maxAdvance':
var softRule = MPHB.Utils.arrayMax($.map(rules, function (rule) {
var softRule = MPHB.Utils.arrayMax($.map(rules, function (rule) {
return rule.max;
return rule.max;
}));
}));
rule = new MPHB.Rules.MaxAdvanceDaysRule({
rule = new MPHB.Rules.MaxAdvanceDaysRule({
season_ids: [0],
season_ids: [0],
room_type_ids: [0],
room_type_ids: [0],
max_advance_reservation: softRule
max_advance_reservation: softRule
});
});
break;
break;
}
}


return rule;
return rule;
},
},


/**
/**
*
*
* @param {Date} date
* @param {Date} date
* @param {int} roomTypeId
* @param {int} roomTypeId
* @return {Boolean}
* @return {Boolean}
*/
*/
isCheckInSatisfy: function isCheckInSatisfy(date, roomTypeId) {
isCheckInSatisfy: function isCheckInSatisfy(date, roomTypeId) {
var isSatisfy = false;
var isSatisfy = false;


if (roomTypeId) {
if (roomTypeId) {
isSatisfy = this.getActualRule('checkInDays', date, roomTypeId).verify(date);
isSatisfy = this.getActualRule('checkInDays', date, roomTypeId).verify(date);
} else {
} else {
isSatisfy = this.getActualCombinedRule('checkInDays', date).verify(date);
isSatisfy = this.getActualCombinedRule('checkInDays', date).verify(date);
}
}


return isSatisfy;
return isSatisfy;
},
},


/**
/**
*
*
* @param {Date} checkInDate
* @param {Date} checkInDate
* @param {Date} checkOutDate
* @param {Date} checkOutDate
* @param {number} [roomTypeId]
* @param {number} [roomTypeId]
* @return {boolean}
* @return {boolean}
*/
*/
isCheckOutSatisfy: function isCheckOutSatisfy(checkInDate, checkOutDate, roomTypeId) {
isCheckOutSatisfy: function isCheckOutSatisfy(checkInDate, checkOutDate, roomTypeId) {
var isSatisfy = false;
var isSatisfy = false;


if (roomTypeId) {
if (roomTypeId) {
isSatisfy = this.getActualRule('checkOutDays', checkInDate, roomTypeId).verify(checkInDate, checkOutDate);
isSatisfy = this.getActualRule('checkOutDays', checkInDate, roomTypeId).verify(checkInDate, checkOutDate);
} else {
} else {
isSatisfy = this.getActualCombinedRule('checkOutDays', checkInDate).verify(checkInDate, checkOutDate);
isSatisfy = this.getActualCombinedRule('checkOutDays', checkInDate).verify(checkInDate, checkOutDate);
}
}


return isSatisfy;
return isSatisfy;
},
},


/**
/**
*
*
* @param {Date} checkInDate
* @param {Date} checkInDate
* @param {number} roomTypeId
* @param {number} roomTypeId
* @return {number}
* @return {number}
*/
*/
getMinStay: function getMinStay(checkInDate, roomTypeId) {
getMinStay: function getMinStay(checkInDate, roomTypeId) {
var minStay;
var minStay;


if (roomTypeId) {
if (roomTypeId) {
minStay = this.getActualRule('minStay', checkInDate, roomTypeId).min;
minStay = this.getActualRule('minStay', checkInDate, roomTypeId).min;
} else {
} else {
minStay = this.getActualCombinedRule('minStay', checkInDate).min;
minStay = this.getActualCombinedRule('minStay', checkInDate).min;
}
}


return minStay;
return minStay;
},
},


/**
/**
*
*
* @param {Date} checkInDate
* @param {Date} checkInDate
* @param {number} roomTypeId
* @param {number} roomTypeId
* @return {number}
* @return {number}
*/
*/
getMaxStay: function getMaxStay(checkInDate, roomTypeId) {
getMaxStay: function getMaxStay(checkInDate, roomTypeId) {
var maxStay;
var maxStay;


if (roomTypeId) {
if (roomTypeId) {
maxStay = this.getActualRule('maxStay', checkInDate, roomTypeId).max;
maxStay = this.getActualRule('maxStay', checkInDate, roomTypeId).max;
} else {
} else {
maxStay = this.getActualCombinedRule('maxStay', checkInDate).max;
maxStay = this.getActualCombinedRule('maxStay', checkInDate).max;
}
}


return maxStay;
return maxStay;
},
},


/**
/**
* @returns {Date}
* @returns {Date}
*
*
* @since 3.8.7
* @since 3.8.7
*/
*/
getToday: function getToday() {
getToday: function getToday() {
return MPHB.HotelDataManager.myThis.today;
return MPHB.HotelDataManager.myThis.today;
},
},


/**
/**
*
*
* @param {number} roomTypeId
* @param {number} roomTypeId
* @return {number}
* @return {number}
*/
*/
getMinAdvance: function getMinAdvance(roomTypeId) {
getMinAdvance: function getMinAdvance(roomTypeId) {
var minAdvance;
var minAdvance;


if (roomTypeId) {
if (roomTypeId) {
minAdvance = this.getActualRule('minAdvance', this.getToday(), roomTypeId).min;
minAdvance = this.getActualRule('minAdvance', this.getToday(), roomTypeId).min;
} else {
} else {
minAdvance = this.getActualCombinedRule('minAdvance', this.getToday()).min;
minAdvance = this.getActualCombinedRule('minAdvance', this.getToday()).min;
}
}


return minAdvance;
return minAdvance;
},
},


/**
/**
*
*
* @param {number} roomTypeId
* @param {number} roomTypeId
* @return {number}
* @return {number}
*/
*/
getMaxAdvance: function getMaxAdvance(roomTypeId) {
getMaxAdvance: function getMaxAdvance(roomTypeId) {
var maxAdvance;
var maxAdvance;


if (roomTypeId) {
if (roomTypeId) {
maxAdvance = this.getActualRule('maxAdvance', this.getToday(), roomTypeId).max;
maxAdvance = this.getActualRule('maxAdvance', this.getToday(), roomTypeId).max;
} else {
} else {
maxAdvance = this.getActualCombinedRule('maxAdvance', this.getToday()).max;
maxAdvance = this.getActualCombinedRule('maxAdvance', this.getToday()).max;
}
}


return maxAdvance;
return maxAdvance;
},
},


/**
/**
*
*
* @returns {Date}
* @returns {Date}
*/
*/
getMinCheckInDate: function getMinCheckInDate(roomTypeId) {
getMinCheckInDate: function getMinCheckInDate(roomTypeId) {
var minAdvance = this.getMinAdvance(roomTypeId);
var minAdvance = this.getMinAdvance(roomTypeId);


if (minAdvance > 0) {
if (minAdvance > 0) {
return $.datepick.add(MPHB.Utils.cloneDate(this.getToday()), minAdvance, 'd');
return $.datepick.add(MPHB.Utils.cloneDate(this.getToday()), minAdvance, 'd');
}
}


return MPHB.Utils.cloneDate(this.getToday());
return MPHB.Utils.cloneDate(this.getToday());
},
},


/**
/**
*
*
* @returns {Date}
* @returns {Date}
*/
*/
getMaxAdvanceDate: function getMaxAdvanceDate(roomTypeId) {
getMaxAdvanceDate: function getMaxAdvanceDate(roomTypeId) {
var maxAdvance = this.getMaxAdvance(roomTypeId);
var maxAdvance = this.getMaxAdvance(roomTypeId);


if (maxAdvance > 0) {
if (maxAdvance > 0) {
return $.datepick.add(MPHB.Utils.cloneDate(this.getToday()), maxAdvance, 'd');
return $.datepick.add(MPHB.Utils.cloneDate(this.getToday()), maxAdvance, 'd');
}
}


return null;
return null;
},
},


/**
/**
*
*
* @param {Date} checkInDate
* @param {Date} checkInDate
* @returns {Date}
* @returns {Date}
*/
*/
getMinCheckOutDate: function getMinCheckOutDate(checkInDate, roomTypeId) {
getMinCheckOutDate: function getMinCheckOutDate(checkInDate, roomTypeId) {
var minDays = this.getMinStay(checkInDate, roomTypeId);
var minDays = this.getMinStay(checkInDate, roomTypeId);
return $.datepick.add(MPHB.Utils.cloneDate(checkInDate), minDays, 'd');
return $.datepick.add(MPHB.Utils.cloneDate(checkInDate), minDays, 'd');
},
},


/**
/**
*
*
* @param {Date} checkInDate
* @param {Date} checkInDate
* @returns {Date}
* @returns {Date}
*/
*/
getMaxCheckOutDate: function getMaxCheckOutDate(checkInDate, roomTypeId) {
getMaxCheckOutDate: function getMaxCheckOutDate(checkInDate, roomTypeId) {
var maxDays = this.getMaxStay(checkInDate, roomTypeId);
var maxDays = this.getMaxStay(checkInDate, roomTypeId);
return $.datepick.add(MPHB.Utils.cloneDate(checkInDate), maxDays, 'd');
return $.datepick.add(MPHB.Utils.cloneDate(checkInDate), maxDays, 'd');
}
}
});
});
MPHB.Rules = {};
MPHB.Rules = {};
MPHB.Rules.BasicRule = can.Construct.extend({}, {
MPHB.Rules.BasicRule = can.Construct.extend({}, {
/**
/**
* @var {number[]}
* @var {number[]}
*/
*/
seasonIds: [],
seasonIds: [],


/**
/**
* @var {number[]}
* @var {number[]}
*/
*/
roomTypeIds: [],
roomTypeIds: [],


/**
/**
*
*
* @param {{season_ids: number[], room_type_ids: number[]}} data
* @param {{season_ids: number[], room_type_ids: number[]}} data
*/
*/
init: function init(data) {
init: function init(data) {
this.seasonIds = data.season_ids;
this.seasonIds = data.season_ids;
this.roomTypeIds = data.room_type_ids;
this.roomTypeIds = data.room_type_ids;
},
},


/**
/**
*
*
* @param {Date} checkInDate
* @param {Date} checkInDate
* @param {number} roomTypeId
* @param {number} roomTypeId
* @return {boolean}
* @return {boolean}
*/
*/
isActualRule: function isActualRule(checkInDate, roomTypeId) {
isActualRule: function isActualRule(checkInDate, roomTypeId) {
return this.isActualForRoomType(roomTypeId) && this.isActualForDate(checkInDate);
return this.isActualForRoomType(roomTypeId) && this.isActualForDate(checkInDate);
},
},


/**
/**
*
*
* @param {number} roomTypeId
* @param {number} roomTypeId
* @return {boolean}
* @return {boolean}
*/
*/
isActualForRoomType: function isActualForRoomType(roomTypeId) {
isActualForRoomType: function isActualForRoomType(roomTypeId) {
return MPHB.Utils.inArray(roomTypeId, this.roomTypeIds) || MPHB.Utils.inArray(0, this.roomTypeIds);
return MPHB.Utils.inArray(roomTypeId, this.roomTypeIds) || MPHB.Utils.inArray(0, this.roomTypeIds);
},
},


/**
/**
*
*
* @param {Date} date
* @param {Date} date
* @return {boolean}
* @return {boolean}
*/
*/
isActualForDate: function isActualForDate(date) {
isActualForDate: function isActualForDate(date) {
if (this.isAllSeasonRule()) {
if (this.isAllSeasonRule()) {
return true;
return true;
}
}


var seasonValid = false;
var seasonValid = false;
$.each(this.seasonIds, function (index, seasonId) {
$.each(this.seasonIds, function (index, seasonId) {
if (MPHB.HotelDataManager.myThis.seasons[seasonId] && MPHB.HotelDataManager.myThis.seasons[seasonId].isContainDate(date)) {
if (MPHB.HotelDataManager.myThis.seasons[seasonId] && MPHB.HotelDataManager.myThis.seasons[seasonId].isContainDate(date)) {
seasonValid = true;
seasonValid = true;
return false; // break
return false; // break
}
}
});
});
return seasonValid;
return seasonValid;
},
},


/**
/**
*
*
* @param {Date} checkInDate
* @param {Date} checkInDate
* @param {Date} checkOutDate
* @param {Date} checkOutDate
* @return {boolean}
* @return {boolean}
*/
*/
verify: function verify(checkInDate, checkOutDate) {
verify: function verify(checkInDate, checkOutDate) {
return true;
return true;
},
},


/**
/**
*
*
* @return {boolean}
* @return {boolean}
*/
*/
isAllSeasonRule: function isAllSeasonRule() {
isAllSeasonRule: function isAllSeasonRule() {
return MPHB.Utils.inArray(0, this.seasonIds);
return MPHB.Utils.inArray(0, this.seasonIds);
},
},


/**
/**
*
*
* @return {boolean}
* @return {boolean}
*/
*/
isAllRoomTypeRule: function isAllRoomTypeRule() {
isAllRoomTypeRule: function isAllRoomTypeRule() {
return MPHB.Utils.inArray(0, this.roomTypeIds);
return MPHB.Utils.inArray(0, this.roomTypeIds);
},
},


/**
/**
*
*
* @return {boolean}
* @return {boolean}
*/
*/
isGlobalRule: function isGlobalRule() {
isGlobalRule: function isGlobalRule() {
return this.isAllSeasonRule() && this.isAllRoomTypeRule();
return this.isAllSeasonRule() && this.isAllRoomTypeRule();
}
}
});
});
/**
/**
* @requires ./basic-rule.js
* @requires ./basic-rule.js
*/
*/


/**
/**
* @class MPHB.Rules.CheckInDayRule
* @class MPHB.Rules.CheckInDayRule
*/
*/


MPHB.Rules.BasicRule('MPHB.Rules.CheckInDayRule', {}, {
MPHB.Rules.BasicRule('MPHB.Rules.CheckInDayRule', {}, {
days: [],
days: [],


/**
/**
*
*
* @param {{season_ids: number[], room_type_ids: number[], check_in_days: number[]}} data
* @param {{season_ids: number[], room_type_ids: number[], check_in_days: number[]}} data
*/
*/
init: function init(data) {
init: function init(data) {
this._super(data);
this._super(data);


this.days = data.check_in_days;
this.days = data.check_in_days;
},
},


/**
/**
*
*
* @param {Date} checkInDate
* @param {Date} checkInDate
* @param {Date} [checkOutDate]
* @param {Date} [checkOutDate]
* @return {boolean}
* @return {boolean}
*/
*/
verify: function verify(checkInDate, checkOutDate) {
verify: function verify(checkInDate, checkOutDate) {
return MPHB.Utils.inArray(checkInDate.getDay(), this.days);
return MPHB.Utils.inArray(checkInDate.getDay(), this.days);
}
}
});
});
/**
/**
* @requires ./basic-rule.js
* @requires ./basic-rule.js
*/
*/


/**
/**
* @class MPHB.Rules.CheckOutDayRule
* @class MPHB.Rules.CheckOutDayRule
*/
*/


MPHB.Rules.BasicRule('MPHB.Rules.CheckOutDayRule', {}, {
MPHB.Rules.BasicRule('MPHB.Rules.CheckOutDayRule', {}, {
days: [],
days: [],


/**
/**
*
*
* @param {{season_ids: number[], room_type_ids: number[], check_out_days: number[]}} data
* @param {{season_ids: number[], room_type_ids: number[], check_out_days: number[]}} data
*/
*/
init: function init(data) {
init: function init(data) {
this._super(data);
this._super(data);


this.days = data.check_out_days;
this.days = data.check_out_days;
},
},


/**
/**
*
*
* @param {Date} checkInDate
* @param {Date} checkInDate
* @param {Date} checkOutDate
* @param {Date} checkOutDate
* @return {boolean}
* @return {boolean}
*/
*/
verify: func
verify: func