refactor: replace hardcoded categories with Directus-powered category tree and translations
This commit is contained in:
@@ -21,7 +21,7 @@ class PageCreate extends HTMLElement {
|
||||
this.formData = this.loadDraft() || this.getEmptyFormData()
|
||||
this.imageFiles = []
|
||||
this.imagePreviews = []
|
||||
this.categories = []
|
||||
this.categoryTree = []
|
||||
this.submitting = false
|
||||
this.isNewAccount = true
|
||||
}
|
||||
@@ -183,10 +183,10 @@ class PageCreate extends HTMLElement {
|
||||
|
||||
async loadCategories() {
|
||||
try {
|
||||
this.categories = await categoriesService.getAll()
|
||||
this.categoryTree = await categoriesService.getTree()
|
||||
} catch (e) {
|
||||
console.error('Failed to load categories:', e)
|
||||
this.categories = []
|
||||
this.categoryTree = []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,10 +238,14 @@ class PageCreate extends HTMLElement {
|
||||
<label class="label" for="category">${t('create.category')}</label>
|
||||
<select class="input" id="category" name="category" required>
|
||||
<option value="">${t('create.selectCategory')}</option>
|
||||
${this.categories.map(cat => `
|
||||
<option value="${cat.id}" ${this.formData.category === cat.id ? 'selected' : ''}>
|
||||
${t(`categories.${cat.slug}`) || cat.name}
|
||||
</option>
|
||||
${(this.categoryTree || []).map(cat => `
|
||||
<optgroup label="${categoriesService.getTranslatedName(cat)}">
|
||||
${(cat.children || []).map(sub => `
|
||||
<option value="${sub.id}" ${this.formData.category === sub.id ? 'selected' : ''}>
|
||||
${categoriesService.getTranslatedName(sub)}
|
||||
</option>
|
||||
`).join('')}
|
||||
</optgroup>
|
||||
`).join('')}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user