Skip to content

Commit

Permalink
Fixed issue #18894: Not able to add theme option text input (#3354)
Browse files Browse the repository at this point in the history
Co-authored-by: lapiudevgit <devgit@lapiu.biz>
  • Loading branch information
gabrieljenik and lapiudevgit committed Nov 20, 2023
1 parent c9c131a commit 03594f8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
10 changes: 7 additions & 3 deletions application/controllers/admin/Themes.php
Expand Up @@ -174,7 +174,11 @@ public function upload()
App()->getController()->forward("/surveyAdministration/uploadimagefile/");
App()->end();
}
$sTemplateName = trim(App()->request->getPost('templatename'));
$sTemplateName = trim(App()->request->getPost('templatename', ''));
// This controller has several actions. Even actions that manage multiple subactions.
// In case you are uploading a template, the templatename does not exist in the POST.
// It's not going to fail, but it's checking for a permission with an empty templatename.
// Surely it works as expected, but it would be nice if the code was clearer.
if (Permission::model()->hasGlobalPermission('templates', 'import') || Permission::model()->hasTemplatePermission($sTemplateName)) {
App()->loadHelper('admin/template');
// NB: lid = label id
Expand Down Expand Up @@ -616,7 +620,7 @@ public function index(string $editfile = '', string $screenname = 'welcome', str
public function templatefiledelete()
{
if (Permission::model()->hasGlobalPermission('templates', 'update')) {
$sTemplateName = Template::templateNameFilter(trim(App()->request->getPost('templatename')));
$sTemplateName = Template::templateNameFilter(trim(App()->request->getPost('templatename', '')));
$oEditedTemplate = Template::getInstance($sTemplateName);
$templatedir = $oEditedTemplate->viewPath;
$sPostedFiletype = CHtml::decode(App()->request->getPost('filetype'));
Expand Down Expand Up @@ -887,7 +891,7 @@ public function templatesavechanges()
$action = returnGlobal('action');
$editfile = returnGlobal('editfile');
$relativePathEditfile = returnGlobal('relativePathEditfile');
$sTemplateName = Template::templateNameFilter(trim(App()->request->getPost('templatename')));
$sTemplateName = Template::templateNameFilter(trim(App()->request->getPost('templatename', '')));
$screenname = returnGlobal('screenname');
$oEditedTemplate = Template::model()->getTemplateConfiguration($sTemplateName, null, null, true)->prepareTemplateRendering($sTemplateName);

Expand Down
7 changes: 5 additions & 2 deletions application/views/themeOptions/options_core.php
Expand Up @@ -271,10 +271,13 @@
</i> )
</div>
</div>';
} elseif ($attribute['type'] == 'input') {
} elseif ($attribute['type'] == 'text') {
echo '<div class="col-12">
<input type="text" class="form-control selector-text-input selector_text_option_value_field" data-parent="' . $attribute['parent'] . '" id="simple_edit_options_' . $attributeKey . '" name="' . $attributeKey . '" title="' . gT("inherited value:") . ' ' . $sParentOption . '" />
</div>';
} elseif ($attribute['type'] == 'duration') {
echo '<div class="col-12">
<input type="text" class="form-control selector-numerical-input selector_option_value_field selector_radio_childfield" data-parent="' . $attribute['parent'] . '" id="simple_edit_options_' . $attributeKey . '" name="' . $attributeKey . '" title="' . gT("inherited value:") . ' ' . $sParentOption . '" />
<input type="text" class="form-control selector-numerical-input selector_text_option_value_field selector_radio_childfield" data-parent="' . $attribute['parent'] . '" id="simple_edit_options_' . $attributeKey . '" name="' . $attributeKey . '" title="' . gT("inherited value:") . ' ' . $sParentOption . '" />
</div>';
}

Expand Down
23 changes: 21 additions & 2 deletions assets/packages/themeoptions-core/themeoptions-core.js
Expand Up @@ -103,6 +103,15 @@ var ThemeOptions = function () {

});

globalForm.find('.selector_text_option_value_field').each(function (i, item) {
//disabled items should be inherit or false
if ($(item).prop('disabled')) {
$(item).val((inheritPossible ? 'inherit' : false));
}

optionObject[$(item).attr('name')] = $(item).val();
});

var newOptionObject = $.extend(true, {}, optionObject);
delete newOptionObject.general_inherit;

Expand Down Expand Up @@ -153,7 +162,7 @@ var ThemeOptions = function () {

//Parses the option value for an item
var parseOptionValue = function (item, fallbackValue) {
fallbackValue = fallbackValue || false;
if (fallbackValue == undefined) fallbackValue = false;
// If general inherit, then the value of the dropdown is inherit, else it's the value defined in advanced options
var itemValue = generalInherit() ? 'inherit' : optionObject[$(item).attr('name')];

Expand All @@ -178,6 +187,7 @@ var ThemeOptions = function () {

// Update values in the form to the template options
// selector_option_value_field are the select dropdown (like variations and fonts)
// TODO: This seems to be designed for select fields only, but it is also used for other input types. Should be reviewed.
var prepareSelectField = function () {
globalForm.find('.selector_option_value_field').each(function (i, item) {
var itemValue = parseOptionValue(item);
Expand Down Expand Up @@ -235,6 +245,14 @@ var ThemeOptions = function () {

};

// Update values of 'text' options in the form
var prepareTextField = function () {
globalForm.find('.selector_text_option_value_field').each(function (i, item) {
var itemValue = parseOptionValue(item, "");
$(item).val(itemValue);
});
};

// updates the disabled status of a child field
// based on the parent element
// NOTE:
Expand Down Expand Up @@ -294,7 +312,7 @@ var ThemeOptions = function () {
// hotswapping the fields
var hotSwapFields = function () {

globalForm.find('.selector_option_value_field').on('change', function (evt) {
globalForm.find('.selector_option_value_field, .selector_text_option_value_field').on('change', function (evt) {
updateFieldSettings();
parseNumeric(this);
});
Expand Down Expand Up @@ -494,6 +512,7 @@ var ThemeOptions = function () {
startupGeneralInherit();

prepareSelectField();
prepareTextField();
parseParentSwitchFields();
prepareFontField();
prepareFruityThemeField();
Expand Down

0 comments on commit 03594f8

Please sign in to comment.