Revert "Enhanced search functionality to work in both standalone and embedded…"
This commit is contained in:
parent
8df9afca5e
commit
24f105d8ec
|
|
@ -20,9 +20,7 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
||||||
originalDomain: null,
|
originalDomain: null,
|
||||||
searchInProgress: false,
|
searchInProgress: false,
|
||||||
lastSearchPromise: null,
|
lastSearchPromise: null,
|
||||||
lastSearchValue: '',
|
lastSearchValue: ''
|
||||||
isEmbedded: false,
|
|
||||||
originalData: null
|
|
||||||
};
|
};
|
||||||
this._searchMutex = new concurrency.Mutex();
|
this._searchMutex = new concurrency.Mutex();
|
||||||
},
|
},
|
||||||
|
|
@ -73,21 +71,14 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
||||||
return self._clearCustomSearch();
|
return self._clearCustomSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
// تحديد نوع الليست (embedded أو standalone)
|
if (!self._customSearchState.originalDomain && !self._customSearchState.isFiltered) {
|
||||||
var state = self.model.get(self.handle);
|
var currentState = self.model.get(self.handle);
|
||||||
if (state && state.parentID) {
|
if (currentState && currentState.domain) {
|
||||||
self._customSearchState.isEmbedded = true;
|
self._customSearchState.originalDomain = JSON.parse(JSON.stringify(currentState.domain));
|
||||||
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() {
|
}).finally(function() {
|
||||||
self._customSearchState.searchInProgress = false;
|
self._customSearchState.searchInProgress = false;
|
||||||
self._customSearchState.lastSearchPromise = null;
|
self._customSearchState.lastSearchPromise = null;
|
||||||
|
|
@ -143,103 +134,6 @@ 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() {
|
_clearCustomSearch: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|
@ -255,21 +149,6 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
||||||
this._customSearchState.filteredCount = 0;
|
this._customSearchState.filteredCount = 0;
|
||||||
this._customSearchState.lastSearchValue = '';
|
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 || [];
|
var originalDomain = this._customSearchState.originalDomain || [];
|
||||||
this._customSearchState.originalDomain = null;
|
this._customSearchState.originalDomain = null;
|
||||||
|
|
||||||
|
|
@ -520,9 +399,19 @@ odoo.define('fims_general_search_tree_view.list_search', function (require) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// **الحل الجديد: نسمح بالبحث في كل الـ list views**
|
// الحل الدقيق الوحيد المؤكد:
|
||||||
// سواء كانت standalone أو embedded
|
// فحص الـ model state للـ ListRenderer
|
||||||
return true;
|
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 فقط
|
||||||
},
|
},
|
||||||
|
|
||||||
_addCustomSearchBox: function() {
|
_addCustomSearchBox: function() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue