Final Fix: Remove interference with default datepicker behavior - Use unique event namespaces
This commit is contained in:
parent
98c767a7f3
commit
b6ab4599a4
|
|
@ -93,48 +93,34 @@ odoo.define('web_hijri_datepicker.datepicker', function (require) {
|
||||||
this._outsideClickHandler = function(e) {
|
this._outsideClickHandler = function(e) {
|
||||||
var $target = $(e.target);
|
var $target = $(e.target);
|
||||||
|
|
||||||
var shouldIgnore = $target.closest('.calendars-popup').length ||
|
var isClickingOnThisWidget = $target.closest(self.$el).length;
|
||||||
|
var isHijriElement = $target.closest('.calendars-popup').length ||
|
||||||
$target.closest('.o_hijri').length ||
|
$target.closest('.o_hijri').length ||
|
||||||
$target.hasClass('o_hijri') ||
|
$target.hasClass('o_hijri') ||
|
||||||
$target.closest('.calendars').length ||
|
$target.closest('.calendars').length;
|
||||||
$target.closest('.bootstrap-datetimepicker-widget').length ||
|
|
||||||
$target.closest('.datepicker').length ||
|
|
||||||
$target.hasClass('o_datepicker_input') ||
|
|
||||||
$target.hasClass('o_datepicker_button') ||
|
|
||||||
$target.closest('.datetimepicker').length ||
|
|
||||||
$target.closest('.datetimepicker-dropdown').length;
|
|
||||||
|
|
||||||
if (!shouldIgnore) {
|
if (!isClickingOnThisWidget && !isHijriElement) {
|
||||||
self._hideAllCalendars();
|
if (self.$input_hijri && self.$input_hijri.calendarsPicker) {
|
||||||
|
self.$input_hijri.calendarsPicker('hide');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this._keydownHandler = function(e) {
|
this._keydownHandler = function(e) {
|
||||||
if (e.keyCode === 27) {
|
if (e.keyCode === 27) {
|
||||||
self._hideAllCalendars();
|
if (self.$input_hijri && self.$input_hijri.calendarsPicker) {
|
||||||
|
self.$input_hijri.calendarsPicker('hide');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document).on('click.hijri_calendar', this._outsideClickHandler);
|
$(document).on('click.hijri_calendar_' + this.cid, this._outsideClickHandler);
|
||||||
$(document).on('keydown.hijri_calendar', this._keydownHandler);
|
$(document).on('keydown.hijri_calendar_' + this.cid, this._keydownHandler);
|
||||||
},
|
},
|
||||||
|
|
||||||
_removeOutsideClickHandler: function() {
|
_removeOutsideClickHandler: function() {
|
||||||
$(document).off('click.hijri_calendar');
|
$(document).off('click.hijri_calendar_' + this.cid);
|
||||||
$(document).off('keydown.hijri_calendar');
|
$(document).off('keydown.hijri_calendar_' + this.cid);
|
||||||
},
|
|
||||||
|
|
||||||
_hideAllCalendars: function() {
|
|
||||||
if (this.$input_hijri && this.$input_hijri.calendarsPicker) {
|
|
||||||
this.$input_hijri.calendarsPicker('hide');
|
|
||||||
}
|
|
||||||
if (this.$el && this.$el.data('DateTimePicker')) {
|
|
||||||
this.$el.data('DateTimePicker').hide();
|
|
||||||
} else if (this.$el && this.$el.datetimepicker) {
|
|
||||||
try {
|
|
||||||
this.$el.datetimepicker('hide');
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
changeDatetime: function () {
|
changeDatetime: function () {
|
||||||
|
|
@ -177,7 +163,9 @@ odoo.define('web_hijri_datepicker.datepicker', function (require) {
|
||||||
var date_value = moment(time.str_to_date(formatted_date)).add(1, 'days');
|
var date_value = moment(time.str_to_date(formatted_date)).add(1, 'days');
|
||||||
this.setValue(this._parseClient(date_value));
|
this.setValue(this._parseClient(date_value));
|
||||||
this.trigger("datetime_changed");
|
this.trigger("datetime_changed");
|
||||||
this._hideAllCalendars();
|
if (this.$input_hijri && this.$input_hijri.calendarsPicker) {
|
||||||
|
this.$input_hijri.calendarsPicker('hide');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_parseDate: function (v) {
|
_parseDate: function (v) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue