chg: [genericTemplate:confirm] Usage of BootstrapHelper\Modal

develop-unstable
Sami Mokaddem 2022-12-02 09:48:09 +01:00
parent f1c84ff834
commit bdcf057608
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 39 additions and 28 deletions

View File

@ -1,28 +1,39 @@
<div class="modal-dialog" role="document"> <?php
<div class="modal-content"> /**
<div class="modal-header"> * Supported parameters:
<h5 class="modal-title"><?= h($title) ?></h5> * - title: The title of the modal
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"> * - question: The content of the modal's body.
</button> * - actionName: The text of the confirm button. Basically what the confirmation will do
</div> * - modalOptions: Additional options to be passed to the modal
<div class="modal-body"> */
<p><?= h($question) ?></p>
</div> $form = $this->element('genericElements/Form/genericForm', [
<div class="modal-footer"> 'entity' => null,
<?= $this->Form->postLink( 'ajax' => false,
h($actionName), 'raw' => true,
$path, 'data' => [
['class' => 'btn btn-primary button-execute', 'id' => 'submitButton'] 'fields' => [
) ],
?> 'submit' => [
<button type="button" class="btn btn-secondary cancel-button" data-bs-dismiss="modal"><?= __('Cancel') ?></button> 'action' => $this->request->getParam('action')
</div> ]
</div> ]
</div> ]);
<script type="text/javascript"> $formHTML = sprintf('<div class="d-none">%s</div>', $form);
$(document).keydown(function(e) { $bodyMessage = h($question ?? '');
if(e.which === 13 && e.ctrlKey) { $bodyHTML = sprintf('%s%s', $formHTML, $bodyMessage);
$('.button-execute').click();
} $defaultOptions = [
}); 'size' => 'lg',
</script> 'title' => isset($title) ? h($title) : __('Confirm'),
'type' => 'confirm',
'confirmButton' => [
'text' => !empty($actionName) ? h($actionName) : __('Confirm'),
'variant' => 'primary',
],
];
$modalOptions = array_merge($defaultOptions, $modalOptions ?? []);
$modalOptions['bodyHtml'] = $bodyHTML;
echo $this->Bootstrap->modal($modalOptions);
?>