Fix tree view selection and add entity-specific sort options

- Fix validation mixin not being merged in _core.js which broke tree item selection
- Add data-entities attribute to sort options for entity-specific filtering
- Improve event handlers and filter panel updates

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-31 18:10:18 +00:00
parent af5066dd26
commit 743e9c8020
9 changed files with 316 additions and 31 deletions

View File

@@ -209,6 +209,11 @@
$.extend(instance, mixins.tree);
}
// Merge validation mixin
if (mixins.validation) {
$.extend(instance, mixins.validation);
}
return instance;
}

View File

@@ -32,14 +32,22 @@
html += '<i class="icon-square-o"></i> ' + (trans.clear || 'Clear') + ' <kbd>Ctrl+D</kbd>';
html += '</button>';
// Sort controls
// Sort controls - options with data-entities attribute for entity-specific filtering
html += '<div class="sort-controls">';
html += '<select class="sort-field-select" title="Sort by">';
// Universal options (all entities)
html += '<option value="name">' + (trans.sort_name || 'Name') + '</option>';
html += '<option value="id">' + (trans.sort_id || 'ID') + '</option>';
html += '<option value="position">' + (trans.sort_position || 'Position') + '</option>';
html += '<option value="popularity">' + (trans.sort_popularity || 'Popularity') + '</option>';
html += '<option value="selected">' + (trans.sort_selected || 'Selected') + '</option>';
// Product-specific
html += '<option value="price" data-entities="products">' + (trans.sort_price || 'Price') + '</option>';
html += '<option value="stock" data-entities="products">' + (trans.sort_stock || 'Stock') + '</option>';
html += '<option value="popularity" data-entities="products">' + (trans.sort_popularity || 'Sales') + '</option>';
html += '<option value="reference" data-entities="products">' + (trans.sort_reference || 'Reference') + '</option>';
// Position-based entities (categories, cms, cms_categories, attributes)
html += '<option value="position" data-entities="categories,cms,cms_categories,attributes">' + (trans.sort_position || 'Position') + '</option>';
// Product count (categories, manufacturers, suppliers)
html += '<option value="product_count" data-entities="categories,manufacturers,suppliers">' + (trans.sort_product_count || 'Products') + '</option>';
html += '</select>';
html += '<button type="button" class="btn-sort-dir" data-dir="ASC" title="Sort direction">';
html += '<i class="icon-sort-alpha-asc"></i>';

View File

@@ -1302,7 +1302,9 @@
var name = $item.data('name');
var isSelected = $item.hasClass('selected');
if (!self.activeGroup) return;
if (!self.activeGroup) {
return;
}
if (!self.pendingSelections) self.pendingSelections = [];
var $allItems = self.$dropdown.find('.tree-item');

View File

@@ -132,6 +132,53 @@
this.$dropdown.find('.view-mode-select').val('list');
this.$dropdown.removeClass('view-tree view-cols-2 view-cols-3 view-cols-4 view-cols-5 view-cols-6 view-cols-7 view-cols-8').addClass('view-list');
}
// Update sort options for entity type
this.updateSortOptionsForEntity(entityType);
},
/**
* Show/hide sort options based on entity type
* Options with data-entities attribute are only shown for matching entities
*/
updateSortOptionsForEntity: function(entityType) {
if (!this.$dropdown) {
return;
}
var $select = this.$dropdown.find('.sort-field-select');
var currentValue = $select.val();
var hasCurrentOption = false;
$select.find('option').each(function() {
var $option = $(this);
var entities = $option.data('entities');
// Options without data-entities are universal (always shown)
if (!entities) {
$option.show();
if ($option.val() === currentValue) {
hasCurrentOption = true;
}
return;
}
// Check if this entity type is in the allowed list
var allowedEntities = entities.split(',');
var isAllowed = allowedEntities.indexOf(entityType) !== -1;
$option.toggle(isAllowed);
if (isAllowed && $option.val() === currentValue) {
hasCurrentOption = true;
}
});
// If current sort field is not available for this entity, reset to 'name'
if (!hasCurrentOption) {
$select.val('name');
this.currentSort.field = 'name';
}
},
loadFilterableData: function() {