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

View File

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