Merge pull request #4396 from expsa/revert-4395-eltayar

Revert "🔧 Fix jQuery Calendars Library Loading Error - إصلاح خطأ تحميل مكتبة التقويم"
This commit is contained in:
Mohamed Eltayar 2025-08-29 01:25:29 +03:00 committed by GitHub
commit 65d61bc45b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 73 additions and 134 deletions

View File

@ -55,30 +55,20 @@ This module automatically adds Hijri date picker functionality below every stand
],
'assets': {
'web.assets_backend': [
# ✅ CSS files first
'web_hijri_datepicker/static/src/scss/hijri_modern.css',
'web_hijri_datepicker/static/src/scss/web_hijri_date.scss',
# ✅ jQuery Plugin base - only once
('prepend', 'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.plugin.js'),
# ✅ jQuery Calendars core libraries in correct order
('prepend', 'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.calendars.js'),
('prepend', 'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.calendars.all.js'),
('prepend', 'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.calendars.plus.js'),
# ✅ Islamic calendar specific files
('prepend', 'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.calendars.islamic.js'),
('prepend', 'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.calendars.islamic-ar.js'),
('prepend', 'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.calendars.islamic-fa.js'),
# ✅ Picker functionality
('prepend', 'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.calendars.picker.js'),
# ✅ Time entry files (optional - only CSS needed)
'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.plugin.js',
'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.calendars.js',
'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.calendars.all.js',
'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.calendars.plus.js',
'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.calendars.picker.js',
'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.calendars.islamic.js',
'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.calendars.islamic-ar.js',
'web_hijri_datepicker/static/lib/jquery.calendars.package-2.2.0/jquery.calendars.islamic-fa.js',
'web_hijri_datepicker/static/lib/jquery.timeentry.package-2.0.1/jquery.timeentry.css',
# ✅ Our custom JavaScript LAST to ensure libraries are loaded
'web_hijri_datepicker/static/lib/jquery.timeentry.package-2.0.1/jquery.plugin.js',
'web_hijri_datepicker/static/lib/jquery.timeentry.package-2.0.1/jquery.timeentry.js',
'web_hijri_datepicker/static/lib/jquery.timeentry.package-2.0.1/jquery.timeentry-ar.js',
'web_hijri_datepicker/static/src/js/web_hijri_date.js',
],
},
@ -107,4 +97,4 @@ This module automatically adds Hijri date picker functionality below every stand
'live_test_url': 'https://demo.yourcompany.com',
'demo': [],
'test': [],
}
}

View File

@ -42,16 +42,40 @@ odoo.define('web_hijri_datepicker.datepicker', function (require) {
this.$input.attr('placeholder', 'التاريخ الميلادي');
}
// ✅ فحص توفر مكتبة jQuery Calendars قبل الاستخدام
if (typeof $ !== 'undefined' && $.calendars) {
this._initHijriCalendar();
} else {
console.warn('jQuery Calendars library not loaded properly. Hijri calendar disabled.');
// إخفاء الحقل الهجري إذا لم تكن المكتبة متوفرة
if (this.$input_hijri) {
this.$input_hijri.hide();
// Enhanced click handler with better UX
this.$input_hijri.click(function (e) {
e.preventDefault();
e.stopPropagation();
self.$input_hijri.calendarsPicker('show');
});
// ✅ Modern configuration with enhanced features and fixed navigation
this.$input_hijri.calendarsPicker({
calendar: $.calendars.instance('islamic', this.options.locale || 'ar'),
dateFormat: 'M d, yyyy',
showAnim: 'slideDown',
showSpeed: 'fast',
showOnFocus: false,
closeOnDateSelect: true,
yearRange: 'c-100:c+50',
changeMonth: true,
changeYear: true,
showOtherMonths: true,
selectOtherMonths: true,
localNumbers: true,
renderer: this._getModernRenderer(),
onSelect: this._convertDateToHijri.bind(this),
onShow: function() {
// Add modern CSS class for styling
$('.calendars-popup').addClass('hijri-modern-popup');
// ✅ إصلاح أزرار التنقل بعد ظهور التقويم
setTimeout(function() {
$('.calendars-prev').html('').attr('title', 'الشهر السابق');
$('.calendars-next').html('').attr('title', 'الشهر التالي');
}, 10);
}
}
});
this.__libInput++;
this.$el.datetimepicker(this.options);
@ -66,65 +90,10 @@ odoo.define('web_hijri_datepicker.datepicker', function (require) {
}, 50);
},
// ✅ دالة منفصلة لتهيئة التقويم الهجري
_initHijriCalendar: function() {
var self = this;
// Enhanced click handler with better UX
this.$input_hijri.click(function (e) {
e.preventDefault();
e.stopPropagation();
if ($.calendars && self.$input_hijri.hasClass('hasCalendarsPicker')) {
self.$input_hijri.calendarsPicker('show');
}
});
try {
// ✅ Modern configuration with enhanced features and fixed navigation
this.$input_hijri.calendarsPicker({
calendar: $.calendars.instance('islamic', this.options.locale || 'ar'),
dateFormat: 'M d, yyyy',
showAnim: 'slideDown',
showSpeed: 'fast',
showOnFocus: false,
closeOnDateSelect: true,
yearRange: 'c-100:c+50',
changeMonth: true,
changeYear: true,
showOtherMonths: true,
selectOtherMonths: true,
localNumbers: true,
renderer: this._getModernRenderer(),
onSelect: this._convertDateToHijri.bind(this),
onShow: function() {
// Add modern CSS class for styling
$('.calendars-popup').addClass('hijri-modern-popup');
// ✅ إصلاح أزرار التنقل بعد ظهور التقويم
setTimeout(function() {
$('.calendars-prev').html('').attr('title', 'الشهر السابق');
$('.calendars-next').html('').attr('title', 'الشهر التالي');
}, 10);
}
});
} catch (error) {
console.error('Error initializing Hijri calendar:', error);
// إخفاء الحقل الهجري في حالة فشل التهيئة
if (this.$input_hijri) {
this.$input_hijri.hide();
}
}
},
/**
* Get modern renderer configuration with fixed navigation buttons
*/
_getModernRenderer: function() {
// التحقق من توفر المكتبة قبل الاستخدام
if (!$.calendarsPicker || !$.calendarsPicker.defaultRenderer) {
return {};
}
return $.extend({}, $.calendarsPicker.defaultRenderer, {
picker: '<div class="calendars">{months}</div>',
monthRow: '<div class="calendars-month-row">{months}</div>',
@ -158,47 +127,37 @@ odoo.define('web_hijri_datepicker.datepicker', function (require) {
},
_convertGregorianToHijri: function (date) {
// التحقق من توفر المكتبة
if (!$.calendars) {
return null;
}
var year, month, day, jd, formatted_date;
var calendar = $.calendars.instance('islamic');
if (date && !_.isUndefined(date)) {
try {
date = moment(date).locale('en');
month = parseInt(date.format('M'));
day = parseInt(date.format('D'));
year = parseInt(date.format('YYYY'));
jd = $.calendars.instance('gregorian').toJD(year, month, day);
formatted_date = calendar.fromJD(jd);
var hijriMonth = calendar.formatDate('MM', formatted_date);
var hijriDate = calendar.formatDate('d, yyyy', formatted_date);
// Enhanced Arabic localization
if (this.options.locale === 'ar' || !this.options.locale) {
hijriDate = hijriDate.fromDigits();
// Find Arabic month name
var arabicMonth = _.find(hijriMonths, function (value, key) {
return key === hijriMonth;
});
hijriMonth = arabicMonth || hijriMonth;
}
return _.str.sprintf("%s %s", hijriMonth, hijriDate);
} catch (error) {
console.error('Error converting Gregorian to Hijri:', error);
return null;
date = moment(date).locale('en');
month = parseInt(date.format('M'));
day = parseInt(date.format('D'));
year = parseInt(date.format('YYYY'));
jd = $.calendars.instance('gregorian').toJD(year, month, day);
formatted_date = calendar.fromJD(jd);
var hijriMonth = calendar.formatDate('MM', formatted_date);
var hijriDate = calendar.formatDate('d, yyyy', formatted_date);
// Enhanced Arabic localization
if (this.options.locale === 'ar' || !this.options.locale) {
hijriDate = hijriDate.fromDigits();
// Find Arabic month name
var arabicMonth = _.find(hijriMonths, function (value, key) {
return key === hijriMonth;
});
hijriMonth = arabicMonth || hijriMonth;
}
return _.str.sprintf("%s %s", hijriMonth, hijriDate);
}
},
_convertDateToHijri: function (date) {
if (!date || date.length === 0 || !$.calendars) {
if (!date || date.length === 0) {
return false;
}
@ -224,12 +183,10 @@ odoo.define('web_hijri_datepicker.datepicker', function (require) {
this.trigger("datetime_changed");
// Hide the popup after selection for better UX
if (this.$input_hijri && this.$input_hijri.hasClass('hasCalendarsPicker')) {
this.$input_hijri.calendarsPicker('hide');
}
this.$input_hijri.calendarsPicker('hide');
} catch (error) {
console.error('Hijri date conversion error:', error);
console.warn('Hijri date conversion error:', error);
}
},
@ -244,13 +201,9 @@ odoo.define('web_hijri_datepicker.datepicker', function (require) {
// Enhanced placeholder handling
if (hijri_value) {
if (this.$input_hijri && this.$input_hijri.length) {
this.$input_hijri.val(hijri_value).removeClass('o_input_placeholder');
}
this.$input_hijri.val(hijri_value).removeClass('o_input_placeholder');
} else {
if (this.$input_hijri && this.$input_hijri.length) {
this.$input_hijri.val('').addClass('o_input_placeholder');
}
this.$input_hijri.val('').addClass('o_input_placeholder');
}
},
@ -259,11 +212,7 @@ odoo.define('web_hijri_datepicker.datepicker', function (require) {
$(document).off('click.calendars');
if (this.$input_hijri && this.$input_hijri.hasClass('hasCalendarsPicker')) {
try {
this.$input_hijri.calendarsPicker('destroy');
} catch (error) {
console.warn('Error destroying calendars picker:', error);
}
this.$input_hijri.calendarsPicker('destroy');
}
if (this.$el) {
@ -326,7 +275,7 @@ odoo.define('web_hijri_datepicker.datepicker', function (require) {
// Enhanced integration with Odoo's form validation
if ($.validator) {
$.validator.addMethod('hijriDate', function(value, element) {
if (!value || !$.calendars) return true;
if (!value) return true;
try {
var calendar = $.calendars.instance('islamic');