Enhanced search functionality to work in both standalone and embedded list views
- Modified _shouldAddSearchBox() to allow search in all list views - Added _applyEmbeddedSearch() for local filtering in embedded lists - Added _getEmbeddedData() to retrieve embedded list data - Added _updateEmbeddedView() to show/hide filtered rows - Enhanced _clearCustomSearch() to handle both view types - Added originalData storage for embedded lists - Improved field value handling for different field types - Local search implementation for embedded many2many/one2many fields
This commit is contained in:
parent
d2c63963e5
commit
888503204b
|
|
@ -20,7 +20,9 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
|||
originalDomain: null,
|
||||
searchInProgress: false,
|
||||
lastSearchPromise: null,
|
||||
lastSearchValue: ''
|
||||
lastSearchValue: '',
|
||||
isEmbedded: false,
|
||||
originalData: null
|
||||
};
|
||||
this._searchMutex = new concurrency.Mutex();
|
||||
},
|
||||
|
|
@ -71,14 +73,21 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
|||
return self._clearCustomSearch();
|
||||
}
|
||||
|
||||
if (!self._customSearchState.originalDomain && !self._customSearchState.isFiltered) {
|
||||
var currentState = self.model.get(self.handle);
|
||||
if (currentState && currentState.domain) {
|
||||
self._customSearchState.originalDomain = JSON.parse(JSON.stringify(currentState.domain));
|
||||
// تحديد نوع الليست (embedded أو standalone)
|
||||
var state = self.model.get(self.handle);
|
||||
if (state && state.parentID) {
|
||||
self._customSearchState.isEmbedded = true;
|
||||
return self._applyEmbeddedSearch(value);
|
||||
} else {
|
||||
self._customSearchState.isEmbedded = false;
|
||||
if (!self._customSearchState.originalDomain && !self._customSearchState.isFiltered) {
|
||||
var currentState = self.model.get(self.handle);
|
||||
if (currentState && currentState.domain) {
|
||||
self._customSearchState.originalDomain = JSON.parse(JSON.stringify(currentState.domain));
|
||||
}
|
||||
}
|
||||
return self._applyCustomSearch(value);
|
||||
}
|
||||
|
||||
return self._applyCustomSearch(value);
|
||||
}).finally(function() {
|
||||
self._customSearchState.searchInProgress = false;
|
||||
self._customSearchState.lastSearchPromise = null;
|
||||
|
|
@ -134,6 +143,103 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
|||
});
|
||||
},
|
||||
|
||||
// دالة جديدة للبحث في embedded lists
|
||||
_applyEmbeddedSearch: function(value) {
|
||||
var self = this;
|
||||
|
||||
if (self.renderer) {
|
||||
self.renderer.$('.oe_search_loading').show();
|
||||
self.renderer.$('.oe_search_count').hide();
|
||||
}
|
||||
|
||||
// حفظ البيانات الأصلية إذا لم تكن محفوظة
|
||||
if (!self._customSearchState.originalData) {
|
||||
self._customSearchState.originalData = self._getEmbeddedData();
|
||||
}
|
||||
|
||||
var searchFields = this._getCustomSearchableFields();
|
||||
var filteredData = [];
|
||||
var allData = self._customSearchState.originalData;
|
||||
|
||||
// البحث في البيانات محلياً
|
||||
allData.forEach(function(record) {
|
||||
var matchFound = false;
|
||||
searchFields.forEach(function(field) {
|
||||
if (matchFound) return;
|
||||
|
||||
var fieldValue = record[field.name];
|
||||
if (fieldValue !== null && fieldValue !== undefined) {
|
||||
var valueStr = '';
|
||||
|
||||
// معالجة أنواع الحقول المختلفة
|
||||
if (field.type === 'many2one' && Array.isArray(fieldValue)) {
|
||||
valueStr = fieldValue[1] || '';
|
||||
} else if (field.type === 'selection') {
|
||||
valueStr = fieldValue || '';
|
||||
} else {
|
||||
valueStr = String(fieldValue);
|
||||
}
|
||||
|
||||
var normalizedValue = self._normalizeText(valueStr.toLowerCase());
|
||||
var normalizedSearch = self._normalizeText(value.toLowerCase());
|
||||
|
||||
if (normalizedValue.indexOf(normalizedSearch) !== -1 ||
|
||||
valueStr.toLowerCase().indexOf(value.toLowerCase()) !== -1) {
|
||||
matchFound = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (matchFound) {
|
||||
filteredData.push(record);
|
||||
}
|
||||
});
|
||||
|
||||
// تحديث العرض
|
||||
self._updateEmbeddedView(filteredData);
|
||||
self._updateCustomSearchUI(filteredData.length);
|
||||
|
||||
self._customSearchState.isFiltered = true;
|
||||
self._customSearchState.value = value;
|
||||
self._customSearchState.filteredCount = filteredData.length;
|
||||
|
||||
if (self.renderer) {
|
||||
self.renderer.$('.oe_search_loading').hide();
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
// دالة للحصول على بيانات embedded list
|
||||
_getEmbeddedData: function() {
|
||||
var state = this.model.get(this.handle);
|
||||
if (state && state.data) {
|
||||
return JSON.parse(JSON.stringify(state.data)); // deep copy
|
||||
}
|
||||
return [];
|
||||
},
|
||||
|
||||
// دالة لتحديث العرض مع البيانات المفلترة
|
||||
_updateEmbeddedView: function(filteredData) {
|
||||
if (!this.renderer || !this.renderer.$) return;
|
||||
|
||||
var $rows = this.renderer.$el.find('tbody tr.o_data_row');
|
||||
|
||||
$rows.each(function(index, row) {
|
||||
var $row = $(row);
|
||||
var recordId = $row.data('id');
|
||||
var shouldShow = filteredData.some(function(record) {
|
||||
return record.id === recordId;
|
||||
});
|
||||
|
||||
if (shouldShow) {
|
||||
$row.show();
|
||||
} else {
|
||||
$row.hide();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_clearCustomSearch: function() {
|
||||
var self = this;
|
||||
|
||||
|
|
@ -149,6 +255,21 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
|||
this._customSearchState.filteredCount = 0;
|
||||
this._customSearchState.lastSearchValue = '';
|
||||
|
||||
// للـ embedded lists
|
||||
if (this._customSearchState.isEmbedded) {
|
||||
if (this.renderer && this.renderer.$) {
|
||||
this.renderer.$el.find('tbody tr.o_data_row').show();
|
||||
}
|
||||
this._customSearchState.originalData = null;
|
||||
|
||||
if (this.renderer) {
|
||||
this.renderer.$('.oe_search_loading').hide();
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
// للـ standalone lists
|
||||
var originalDomain = this._customSearchState.originalDomain || [];
|
||||
this._customSearchState.originalDomain = null;
|
||||
|
||||
|
|
@ -399,19 +520,9 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
|||
return false;
|
||||
}
|
||||
|
||||
// الحل الدقيق الوحيد المؤكد:
|
||||
// فحص الـ model state للـ ListRenderer
|
||||
var controller = this.getParent();
|
||||
if (controller && controller.model && controller.handle) {
|
||||
var state = controller.model.get(controller.handle);
|
||||
|
||||
// إذا كان parentID موجود، فهذا يعني أن الـ list embedded داخل relational field
|
||||
if (state && state.parentID) {
|
||||
return false; // لا نظهر البحث للـ embedded lists
|
||||
}
|
||||
}
|
||||
|
||||
return true; // نظهر البحث للـ standalone lists فقط
|
||||
// **الحل الجديد: نسمح بالبحث في كل الـ list views**
|
||||
// سواء كانت standalone أو embedded
|
||||
return true;
|
||||
},
|
||||
|
||||
_addCustomSearchBox: function() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue