- Created main module file `customfeaturetab.php` to manage product tabs based on feature values. - Implemented database installation and uninstallation methods to create necessary tables. - Added admin controller files for handling redirects and admin functionalities. - Introduced AJAX functionality in `admin.js` for dynamic feature value selection based on selected features. - Included temporary query script for testing feature values. - Added language support for the module with Polish translations. - Created necessary view files and JavaScript files for module functionality. - Added logo image for the module.
57 lines
1.9 KiB
JavaScript
57 lines
1.9 KiB
JavaScript
/**
|
|
* AJAX dependent dropdown for feature values in admin form.
|
|
*/
|
|
$(document).ready(function () {
|
|
var $featureSelect = $('select[name="id_feature"]');
|
|
var $valueSelect = $('select[name="id_feature_value"]');
|
|
|
|
if (!$featureSelect.length || !$valueSelect.length) {
|
|
return;
|
|
}
|
|
|
|
// Build AJAX base URL from current page URL
|
|
var baseUrl = window.location.href.split('#')[0];
|
|
// Strip existing query noise and keep controller + token
|
|
var preselectedValue = $valueSelect.data('selected') || $valueSelect.val();
|
|
|
|
$featureSelect.on('change', function () {
|
|
var idFeature = $(this).val();
|
|
if (!idFeature) {
|
|
$valueSelect.empty().append('<option value="">--</option>');
|
|
return;
|
|
}
|
|
|
|
// Use the current page URL, append ajax params
|
|
var ajaxUrl = baseUrl + '&ajax=1&action=getFeatureValues&id_feature=' + idFeature;
|
|
|
|
$.ajax({
|
|
url: ajaxUrl,
|
|
type: 'GET',
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
$valueSelect.empty();
|
|
if (data && data.length) {
|
|
$.each(data, function (i, item) {
|
|
var selected = (item.id_feature_value == preselectedValue) ? ' selected' : '';
|
|
$valueSelect.append(
|
|
'<option value="' + item.id_feature_value + '"' + selected + '>' +
|
|
item.value +
|
|
'</option>'
|
|
);
|
|
});
|
|
preselectedValue = null;
|
|
} else {
|
|
$valueSelect.append('<option value="">--</option>');
|
|
}
|
|
},
|
|
error: function (xhr, status, error) {
|
|
console.error('[customfeaturetab] AJAX error:', status, error);
|
|
}
|
|
});
|
|
});
|
|
|
|
if ($featureSelect.val()) {
|
|
$featureSelect.trigger('change');
|
|
}
|
|
});
|