Simplify JavaScript - remove complex placeholder handling

- Remove _ensurePlaceholders() method and related complexity
- Remove DOM MutationObserver and event handlers
- Remove setTimeout and async handling
- Keep only the core functionality for date conversion
- Remove all custom placeholder manipulation code
- Use simple, standard Odoo approach for placeholders
- Focus on core Hijri calendar functionality only
This commit is contained in:
Mohamed Eltayar 2025-08-29 00:53:51 +03:00
parent 0634076837
commit 6d7b57b291
1 changed files with 0 additions and 95 deletions

View File

@ -37,9 +37,6 @@ odoo.define('web_hijri_datepicker.datepicker', function (require) {
this.$input = this.$('input.o_datepicker_input');
this.$input_hijri = this.$('input.o_hijri');
// ✅ تأكد من عرض الـ placeholder للحقل الميلادي
this._ensurePlaceholders();
// Enhanced click handler with better UX
this.$input_hijri.click(function (e) {
e.preventDefault();
@ -75,64 +72,6 @@ odoo.define('web_hijri_datepicker.datepicker', function (require) {
this._setReadonly(false);
},
/**
* دالة جديدة لضمان عرض الـ placeholder
*/
_ensurePlaceholders: function() {
var self = this;
// تأكد من عرض placeholder للحقل الميلادي
if (this.$input && this.$input.length) {
if (!this.$input.attr('placeholder')) {
this.$input.attr('placeholder', 'التاريخ الميلادي');
}
// معالج للحفاظ على الـ placeholder حتى لو تغير
this.$input.on('focus blur', function() {
if (!$(this).attr('placeholder')) {
$(this).attr('placeholder', 'التاريخ الميلادي');
}
});
}
// تأكد من عرض placeholder للحقل الهجري
if (this.$input_hijri && this.$input_hijri.length) {
if (!this.$input_hijri.attr('placeholder')) {
this.$input_hijri.attr('placeholder', 'التاريخ الهجري');
}
// معالج للحفاظ على الـ placeholder
this.$input_hijri.on('focus blur', function() {
if (!$(this).attr('placeholder')) {
$(this).attr('placeholder', 'التاريخ الهجري');
}
});
}
// ✅ معالج إضافي بعد تحميل DOM
setTimeout(function() {
self._ensurePlaceholdersAfterRender();
}, 100);
},
/**
* دالة إضافية للتأكد من الـ placeholder بعد التحميل
*/
_ensurePlaceholdersAfterRender: function() {
// البحث عن جميع حقول التاريخ في الصفحة وإضافة placeholder إذا لم يكن موجود
this.$el.find('input.o_datepicker_input').each(function() {
if (!$(this).attr('placeholder') || $(this).attr('placeholder') === '') {
$(this).attr('placeholder', 'التاريخ الميلادي');
}
});
this.$el.find('input.o_hijri').each(function() {
if (!$(this).attr('placeholder') || $(this).attr('placeholder') === '') {
$(this).attr('placeholder', 'التاريخ الهجري');
}
});
},
/**
* Get modern renderer configuration for better styling
*/
@ -248,9 +187,6 @@ odoo.define('web_hijri_datepicker.datepicker', function (require) {
} else {
this.$input_hijri.val('').addClass('o_input_placeholder');
}
// ✅ تأكد من الـ placeholder بعد تعيين القيمة
this._ensurePlaceholders();
},
destroy: function () {
@ -345,35 +281,4 @@ odoo.define('web_hijri_datepicker.datepicker', function (require) {
});
}
// ✅ معالج شامل للتأكد من الـ placeholder في جميع حقول التاريخ
$(document).ready(function() {
// مراقب DOM للحقول الجديدة
if (window.MutationObserver) {
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === 'childList') {
// البحث عن حقول تاريخ جديدة وإضافة placeholder
$(mutation.target).find('input.o_datepicker_input').each(function() {
if (!$(this).attr('placeholder')) {
$(this).attr('placeholder', 'التاريخ الميلادي');
}
});
$(mutation.target).find('input.o_hijri').each(function() {
if (!$(this).attr('placeholder')) {
$(this).attr('placeholder', 'التاريخ الهجري');
}
});
}
});
});
// مراقبة التغييرات في الصفحة
observer.observe(document.body, {
childList: true,
subtree: true
});
}
});
});