From 6c102006e791e8cb78ac9454bed7f8b728cc69ac Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 6 Nov 2023 06:42:18 -0800 Subject: [PATCH] Fixed issue #19086: Survey Theme Options - image preview does not work (#3557) --- .../views/themeOptions/options_core.php | 54 +++++++++++-------- .../themeoptions-core/themeoptions-core.js | 15 ++++++ 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/application/views/themeOptions/options_core.php b/application/views/themeOptions/options_core.php index 1f5f9890638..ab81c154acf 100644 --- a/application/views/themeOptions/options_core.php +++ b/application/views/themeOptions/options_core.php @@ -2,17 +2,13 @@ $bInherit = (!empty($aTemplateConfiguration['sid']) || !empty($aTemplateConfiguration['gsid'])); - $dropdown_options['font'] = ($bInherit ? '' : ''); - // background file $backgroundImageFile = ''; -$backgroundfileOptionsInherit = ''; $backgroundfileInheritPreview = ''; -$backgroundfileInheritFilename = ''; $optgroup = ''; foreach ($aTemplateConfiguration['imageFileList'] as $image) { if ($image['group'] != $optgroup) { @@ -24,10 +20,11 @@ } $backgroundImageFile .= ''; - if (isset($oParentOptions['backgroundimagefile']) && $oParentOptions['backgroundimagefile'] == $image['filepath']) { - $backgroundfileInheritPreview = $backgroundfileInheritPreview . $image['preview']; - $backgroundfileInheritFilename = $backgroundfileInheritFilename . $image['filename']; + + if (isset($oParentOptions['backgroundimagefile']) && ($oParentOptions['backgroundimagefile'] == $image['filepath'] || $oParentOptions['backgroundimagefile'] == $image['filepathOptions'])) { + $backgroundfileInheritPreview = $image['preview']; } + $backgroundImageFile .= ''; } @@ -35,9 +32,7 @@ // brand logo file $brandlogo = ''; -$logofileOptionsInherit = ''; $logofileInheritPreview = ''; -$logofileInheritFilename = ''; $optgroup = ''; foreach ($aTemplateConfiguration['imageFileList'] as $image) { if ($image['group'] != $optgroup) { @@ -49,10 +44,11 @@ } $brandlogo .= ''; - if ($oParentOptions['brandlogo'] == $image['filepath']) { - $logofileInheritPreview = $logofileInheritPreview . $image['preview']; - $logofileInheritFilename = $logofileInheritFilename . $image['filename']; + + if (isset($oParentOptions['brandlogofile']) && ($oParentOptions['brandlogofile'] == $image['filepath'] || $oParentOptions['brandlogofile'] == $image['filepathOptions'])) { + $logofileInheritPreview = $image['preview']; } + $brandlogo .= ''; } @@ -101,7 +97,6 @@ echo ''; } - foreach ($aOptionAttributes['optionAttributes'] as $attributeKey => $attribute) { $sParentOption = array_key_exists($attributeKey, $oParentOptions) ? $oParentOptions[$attributeKey] : ''; if ($attributeKey === 'ajaxmode') { @@ -168,17 +163,34 @@ // TODO: $aParentOptions is not loaded properly, it seems. $sParentOption = 'N/A'; } + $classes = [ + 'form-select', + 'selector_option_value_field', + 'selector_radio_childfield', + ]; + if ($category === 'Images') { + $classes[] = 'selector_image_selector'; + } + $classValue = implode(' ', $classes); echo '
- '; if ($bInherit) { - if ($attributeKey == 'backgroundimagefile') { - $inheritedValue = isset($backgroundfileInheritPreview) ? $backgroundfileInheritPreview : ''; - } elseif ($attributeKey == 'backgroundimagefile') { - $inheritedValue = isset($logofileInheritPreview) ? $logofileInheritPreview : ''; - } else { - $inheritedValue = isset($sParentOption) ? $sParentOption : ''; + + $dataAttributes = ''; + $lightboxSrc = ''; + $inheritedValue = isset($sParentOption) ? $sParentOption : ''; + + if ($attributeKey == 'backgroundimagefile' && !empty($backgroundfileInheritPreview)) { + $lightboxSrc = $backgroundfileInheritPreview; + } elseif ($attributeKey == 'brandlogofile' && !empty($logofileInheritPreview)) { + $lightboxSrc = $logofileInheritPreview; } - echo ''; + + if ($category === 'Images') { + $dataAttributes = 'data-lightbox-src="' . $lightboxSrc . '"'; + } + + echo ''; } // dropdown options from config.xml file echo $aOptionAttributes['optionAttributes'][$attributeKey]['dropdownoptions']; diff --git a/assets/packages/themeoptions-core/themeoptions-core.js b/assets/packages/themeoptions-core/themeoptions-core.js index ba4f6c6343c..e61c52ac828 100644 --- a/assets/packages/themeoptions-core/themeoptions-core.js +++ b/assets/packages/themeoptions-core/themeoptions-core.js @@ -74,6 +74,21 @@ var ThemeOptions = function () { optionObject[$(item).attr('name')] = $(item).val(); }); + globalForm.find('.selector_image_selector').each(function (i, item) { + + // disable the preview image button if the image + // selected could not be mapped to one of the images + // that actually exists within the theme + const src = $(item).find('option:selected').data('lightbox-src'); + const missing = src === ''; + const itemId = $(item).attr('id'); + const button = $(`button[data-bs-target="#${itemId}"]`); + button.prop('disabled', missing); + + // add some feedback to the user, mark field invalid + $(item).toggleClass('is-invalid', missing); + }); + globalForm.find('.selector_option_radio_field ').each(function (i, item) { //disabled items should be inherit or false if ($(item).prop('disabled')) {