Vertrauen Sie tausenden zufriedenen Kunden – Echtheit garantiert!
-
Blitzschnelle Lieferung
-
Sichere Zahlung
-
Zufriedenheitsgarantie
-
30 Tage Rückgaberecht
-
Startseite
if (!this.fulltextSearch) {
return this.dynamicItems;
}
return this.dynamicItems.filter(item =>
SmileAttributeFilter.isItemMatchingSearch(item.label, this.fulltextSearch)
);
},
isItemVisible(index, label) {
// Always check search first
if (this.fulltextSearch) {
return SmileAttributeFilter.isItemMatchingSearch(label, this.fulltextSearch);
}
if (this.options?.filterCode === 'marka' || this.options?.filterCode === 'model') {
return true;
}
// If no search, apply pagination rules
return this.expanded ? true : index < 10;
},
get shouldBeScrollable() {
const totalItems = this.allItems.length;
// Make marka always scrollable
if (this.options?.filterCode === 'marka' || this.options?.filterCode === 'model') {
return true;
}
return !this.options.hasMoreItems && totalItems > 10;
},
get shouldShowMoreButton() {
if (this.options?.filterCode === 'marka' || this.options?.filterCode === 'model') {
return false;
}
return this.options.hasMoreItems || (!this.expanded && this.allItems.length > 10);
},
get shouldShowSearch() {
// Make marka always show search
if (this.options?.filterCode === 'marka' || this.options?.filterCode === 'model') {
return true;
}
return this.initialSearchVisible || this.allItems.length > 10;
},
onSearchChange(event) {
this.fulltextSearch = event.target.value.trim() || null;
},
onSearchFocusOut(event) {
this.fulltextSearch = event.target.value.trim() || null;
},
sortItems(items) {
return [...items].sort((a, b) => {
// First sort by selected status
if (a.is_selected !== b.is_selected) {
return b.is_selected - a.is_selected;
}
// Then sort alphabetically
return a.label.localeCompare(b.label);
});
},
async onShowMore() {
if (this.isLoading) return;
if (!this.options.hasMoreItems) {
this.expanded = true;
return;
}
this.isLoading = true;
try {
const response = await fetch(this.options.ajaxLoadUrl, {
method: 'GET',
headers: { 'X-Requested-With': 'XMLHttpRequest' }
});
if (!response.ok) throw new Error('Network response was not ok');
const data = await response.json();
// Combine all items and sort them
const allItemsCombined = [...this.options.items, ...this.dynamicItems, ...data];
// Remove duplicates based on label
const uniqueItems = Array.from(
new Map(allItemsCombined.map(item => [item.label, item])).values()
);
// Sort all items
const sortedItems = this.sortItems(uniqueItems);
// Update the items arrays
this.allItems = sortedItems;
this.dynamicItems = sortedItems.filter(item =>
!this.options.items.some(originalItem =>
originalItem.label === item.label
)
);
this.options.hasMoreItems = false;
this.expanded = true;
} catch (error) {
console.error('Error loading additional items:', error);
} finally {
this.isLoading = false;
}
},
onShowLess() {
this.expanded = false;
this.dynamicItems = [];
this.allItems = [...this.options.items];
this.fulltextSearch = null;
},
hasSearchResult() {
if (!this.fulltextSearch) return true;
return this.allItems.some(item =>
SmileAttributeFilter.isItemMatchingSearch(item.label, this.fulltextSearch)
);
},
getSearchResultMessage() {
return this.translations.noSearchResultLabel.replace('%s', this.fulltextSearch);
},
getFulltextSearch() {
return this.fulltextSearch;
}
};
}
};