Skip to content

Commit

Permalink
Fix URLs and configurable keyName for editing (joomla#42346)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedik authored Nov 18, 2023
1 parent 84585cc commit c8ea946
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const setupField = (container) => {
// Extract the data
const action = button.dataset.buttonAction;
const dialogConfig = button.dataset.modalConfig ? JSON.parse(button.dataset.modalConfig) : {};
const keyName = container.dataset.keyName || 'id';

// Handle requested action
let handle;
Expand All @@ -123,7 +124,7 @@ const setupField = (container) => {
case 'edit': {
// Update current value in the URL
const url = dialogConfig.src.indexOf('http') === 0 ? new URL(dialogConfig.src) : new URL(dialogConfig.src, window.location.origin);
url.searchParams.set('id', inputValue.value);
url.searchParams.set(keyName, inputValue.value);
dialogConfig.src = url.toString();

handle = doSelect(inputValue, inputTitle, dialogConfig);
Expand All @@ -142,7 +143,7 @@ const setupField = (container) => {
const chckUrl = button.dataset.checkinUrl;
const url = chckUrl.indexOf('http') === 0 ? new URL(chckUrl) : new URL(chckUrl, window.location.origin);
// Add value to request
url.searchParams.set('id', inputValue.value);
url.searchParams.set(keyName, inputValue.value);
url.searchParams.set('cid[]', inputValue.value);
// Also add value to POST, because Controller may expect it from there
const data = new FormData();
Expand Down
15 changes: 8 additions & 7 deletions layouts/joomla/form/field/modal-select/buttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
defined('_JEXEC') or die;

use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;

extract($displayData);

Expand Down Expand Up @@ -52,17 +53,17 @@
// Prepare options for each Modal
$modalSelect = [
'popupType' => 'iframe',
'src' => $urls['select'] ?? '',
'src' => empty($urls['select']) ? '' : Route::_($urls['select'], false),
'textHeader' => $modalTitles['select'] ?? Text::_('JSELECT'),
];
$modalNew = [
'popupType' => 'iframe',
'src' => $urls['new'] ?? '',
'src' => empty($urls['new']) ? '' : Route::_($urls['new'], false),
'textHeader' => $modalTitles['new'] ?? Text::_('JACTION_CREATE'),
];
$modalEdit = [
'popupType' => 'iframe',
'src' => $urls['edit'] ?? '',
'src' => empty($urls['edit']) ? '' : Route::_($urls['edit'], false),
'textHeader' => $modalTitles['edit'] ?? Text::_('JACTION_EDIT'),
];

Expand All @@ -73,24 +74,24 @@
<?php if ($modalSelect['src'] && $canDo['select'] ?? true) : ?>
<button type="button" class="btn btn-primary" <?php echo $value && !$isSelectAlways ? 'hidden' : ''; ?>
data-button-action="select" <?php echo !$isSelectAlways ? 'data-show-when-value=""' : ''; ?>
data-modal-config="<?php echo $this->escape(json_encode($modalSelect)); ?>">
data-modal-config="<?php echo $this->escape(json_encode($modalSelect, JSON_UNESCAPED_SLASHES)); ?>">
<span class="<?php echo !empty($buttonIcons['select']) ? $buttonIcons['select'] : 'icon-file'; ?>" aria-hidden="true"></span> <?php echo Text::_('JSELECT'); ?>
</button>
<?php endif; ?>

<?php if ($modalNew['src'] && $canDo['new'] ?? false) : ?>
<button type="button" class="btn btn-secondary" <?php echo $value ? 'hidden' : ''; ?>
data-button-action="create" data-show-when-value=""
data-modal-config="<?php echo $this->escape(json_encode($modalNew)); ?>">
data-modal-config="<?php echo $this->escape(json_encode($modalNew, JSON_UNESCAPED_SLASHES)); ?>">
<span class="icon-plus" aria-hidden="true"></span> <?php echo Text::_('JACTION_CREATE'); ?>
</button>
<?php endif; ?>

<?php if ($modalEdit['src'] && $canDo['edit'] ?? false) : ?>
<button type="button" class="btn btn-primary" <?php echo $value ? '' : 'hidden'; ?>
data-button-action="edit" data-show-when-value="1"
data-modal-config="<?php echo $this->escape(json_encode($modalEdit)); ?>"
data-checkin-url="<?php echo $this->escape($urls['checkin'] ?? ''); ?>">
data-modal-config="<?php echo $this->escape(json_encode($modalEdit, JSON_UNESCAPED_SLASHES)); ?>"
data-checkin-url="<?php echo empty($urls['checkin']) ? '' : Route::_($urls['checkin']); ?>">
<span class="icon-pen-square" aria-hidden="true"></span> <?php echo Text::_('JACTION_EDIT'); ?>
</button>
<?php endif; ?>
Expand Down

0 comments on commit c8ea946

Please sign in to comment.