fix: [genericTemplates:indexFilter] Correct usage of confirmFunction

pull/41/head
mokaddem 2021-03-23 10:04:06 +01:00
parent ff1b9bfe8d
commit 61f3701d14
2 changed files with 19 additions and 17 deletions

View File

@ -30,7 +30,7 @@ echo $this->Bootstrap->modal([
'type' => 'confirm', 'type' => 'confirm',
'bodyHtml' => $filteringForm, 'bodyHtml' => $filteringForm,
'confirmText' => __('Filter'), 'confirmText' => __('Filter'),
'confirmFunction' => 'filterIndex(clicked)' 'confirmFunction' => 'filterIndex'
]); ]);
?> ?>
@ -40,11 +40,10 @@ echo $this->Bootstrap->modal([
initFilteringTable($filteringTable) initFilteringTable($filteringTable)
}) })
function filterIndex(clicked) { function filterIndex(modalObject, tmpApi) {
const controller = '<?= $this->request->getParam('controller') ?>'; const controller = '<?= $this->request->getParam('controller') ?>';
const action = 'index'; const action = 'index';
const $clicked = $(clicked) const $tbody = modalObject.$modal.find('table.indexFilteringTable tbody')
const $tbody = $clicked.closest('div.modal-content').find('table.indexFilteringTable tbody')
const $rows = $tbody.find('tr:not(#controlRow)') const $rows = $tbody.find('tr:not(#controlRow)')
const activeFilters = {} const activeFilters = {}
$rows.each(function() { $rows.each(function() {

View File

@ -704,19 +704,22 @@ class ModalFactory {
if ($submitButton.data('confirmfunction') !== undefined && $submitButton.data('confirmfunction') !== '') { if ($submitButton.data('confirmfunction') !== undefined && $submitButton.data('confirmfunction') !== '') {
const clickHandler = window[$submitButton.data('confirmfunction')] const clickHandler = window[$submitButton.data('confirmfunction')]
this.options.APIConfirm = (tmpApi) => { this.options.APIConfirm = (tmpApi) => {
return clickHandler(this, tmpApi) let clickResult = clickHandler(this, tmpApi)
.then((data) => { if (clickResult !== undefined) {
if (data.success) { return clickResult
this.options.POSTSuccessCallback(data) .then((data) => {
} else { // Validation error if (data.success) {
this.injectFormValidationFeedback(form, data.errors) this.options.POSTSuccessCallback(data)
return Promise.reject('Validation error'); } else { // Validation error
} this.injectFormValidationFeedback(form, data.errors)
}) return Promise.reject('Validation error');
.catch((errorMessage) => { }
this.options.POSTFailCallback(errorMessage) })
return Promise.reject(errorMessage); .catch((errorMessage) => {
}) this.options.POSTFailCallback(errorMessage)
return Promise.reject(errorMessage);
})
}
} }
} else { } else {
$submitButton[0].removeAttribute('onclick') $submitButton[0].removeAttribute('onclick')