إصلاح مشكلة فقدان قيمة حقل البحث عند الـ reload
المشكلة: كان حقل البحث يفقد قيمته وعداد السجلات يختفي بعد تنفيذ البحث الحل: - حفظ حالة البحث في الـ Controller - استعادة القيمة والعداد عند إعادة رسم الـ Renderer - إضافة دالة _restoreSearchState للحفاظ على القيم - تعديل _addCustomSearchBox لاستخدام القيم المحفوظة - منع فقدان البيانات عند reload
This commit is contained in:
parent
c1b42c7a51
commit
052761c7b2
|
|
@ -170,7 +170,8 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
|||
self._customSearchState.isFiltered = true;
|
||||
self._customSearchState.value = value;
|
||||
|
||||
// Trigger update to renderer
|
||||
// Trigger update to renderer WITHOUT reload
|
||||
// This maintains the search box value
|
||||
return self.update({}, {reload: false});
|
||||
}).then(function() {
|
||||
console.log('Search applied successfully');
|
||||
|
|
@ -509,11 +510,39 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
|||
if (self._shouldAddSearchBox()) {
|
||||
self._addCustomSearchBox();
|
||||
self._customSearchReady = true;
|
||||
|
||||
// Restore search state after render
|
||||
self._restoreSearchState();
|
||||
}
|
||||
return result;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Restore search state after render
|
||||
*/
|
||||
_restoreSearchState: function() {
|
||||
var controller = this.getParent();
|
||||
if (controller && controller._customSearchState) {
|
||||
var state = controller._customSearchState;
|
||||
|
||||
// Restore search input value
|
||||
if (state.value) {
|
||||
this.$('.oe_search_input').val(state.value);
|
||||
this.$('.oe_clear_search').show();
|
||||
}
|
||||
|
||||
// Restore count display
|
||||
if (state.isFiltered && state.filteredCount >= 0) {
|
||||
var message = _t('Found: ') + state.filteredCount + _t(' records');
|
||||
this.$('.oe_search_count')
|
||||
.text(message)
|
||||
.removeClass('text-danger')
|
||||
.show();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if we should add search box
|
||||
*/
|
||||
|
|
@ -529,16 +558,31 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
|||
* Add search box UI
|
||||
*/
|
||||
_addCustomSearchBox: function() {
|
||||
// Check if already exists or if we have a saved state
|
||||
var controller = this.getParent();
|
||||
var savedValue = '';
|
||||
var savedCount = 0;
|
||||
var isFiltered = false;
|
||||
|
||||
if (controller && controller._customSearchState) {
|
||||
savedValue = controller._customSearchState.value || '';
|
||||
savedCount = controller._customSearchState.filteredCount || 0;
|
||||
isFiltered = controller._customSearchState.isFiltered || false;
|
||||
}
|
||||
|
||||
var html =
|
||||
'<div class="oe_search_container" style="display: flex; align-items: center; margin: 8px; background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%); padding: 12px; border-radius: 6px; border: 1px solid #dee2e6; box-shadow: 0 1px 3px rgba(0,0,0,0.1);">' +
|
||||
'<input type="text" class="oe_search_input form-control" ' +
|
||||
'placeholder="' + _t('Search in all visible columns...') + '" ' +
|
||||
'value="' + _.escape(savedValue) + '" ' +
|
||||
'style="flex: 1; border: 1px solid #ced4da; height: 36px; padding: 0 12px; border-radius: 4px; font-size: 14px;" ' +
|
||||
'autocomplete="off">' +
|
||||
'<button class="btn btn-secondary oe_clear_search ml-2" style="display: none; min-width: 70px;">' +
|
||||
'<button class="btn btn-secondary oe_clear_search ml-2" style="display: ' + (savedValue ? 'inline-block' : 'none') + '; min-width: 70px;">' +
|
||||
'<i class="fa fa-times mr-1"></i>' + _t('Clear') +
|
||||
'</button>' +
|
||||
'<span class="oe_search_count badge badge-success ml-2" style="display: none; padding: 6px 10px; font-size: 0.9em;"></span>' +
|
||||
'<span class="oe_search_count badge badge-success ml-2" style="display: ' + (isFiltered ? 'inline-block' : 'none') + '; padding: 6px 10px; font-size: 0.9em;">' +
|
||||
(isFiltered ? _t('Found: ') + savedCount + _t(' records') : '') +
|
||||
'</span>' +
|
||||
'<span class="oe_search_loading ml-2" style="display: none; color: #007bff;">' +
|
||||
'<i class="fa fa-spinner fa-spin"></i>' +
|
||||
'</span>' +
|
||||
|
|
@ -546,8 +590,10 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
|||
|
||||
this.$el.prepend($(html));
|
||||
|
||||
// Focus on search input
|
||||
this.$('.oe_search_input').focus();
|
||||
// Focus on search input if it has value
|
||||
if (savedValue) {
|
||||
this.$('.oe_search_input').focus();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue