Skip to content

Commit 0535630

Browse files
committed
Confirm before trashing pages
1 parent d9cfcc7 commit 0535630

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

DashboardPanelCollection.module

100755100644
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ class DashboardPanelCollection extends DashboardPanel
285285
{
286286
parent::setup();
287287

288+
$this->wire()->modules->get('JqueryUI')->use('vex');
289+
288290
$this->editUrl = $this->config->urls->admin.'page/edit/';
289291
$this->addUrl = $this->config->urls->admin.'page/add/';
290292
$this->listUrl = $this->config->urls->admin.'page/list/';
@@ -307,6 +309,8 @@ class DashboardPanelCollection extends DashboardPanel
307309
$this->editMode = $this->data['editMode'] ?? self::windowModeBlank;
308310
$this->viewMode = $this->data['viewMode'] ?? self::windowModeBlank;
309311
$this->addUrlParams = $this->data['addUrlParams'] ?? [];
312+
$this->confirmTrash = $this->data['confirmTrash'] ?? true;
313+
$this->confirmTrashMessage = $this->data['confirmTrashMessage'] ?? $this->_('Are you sure?');
310314

311315
if (is_string($this->collection)) {
312316
$this->collection = $this->pages->find($this->collection);
@@ -504,7 +508,9 @@ class DashboardPanelCollection extends DashboardPanel
504508
'attributes' => [
505509
'data-action' => "[trash][{$page}]",
506510
'data-action-value' => "1",
507-
],
511+
] + ($this->confirmTrash ? [
512+
'data-action-confirm' => $this->confirmTrashMessage,
513+
] : []),
508514
];
509515
}
510516
}

src/DashboardPanelCollection.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
/* global $ */
22

33
function initPanel($panel) {
4+
5+
const submitParamsAndReload = (params) => {
6+
$panel.trigger('reload', { animate: false, params });
7+
};
8+
49
const $reloadlinks = $panel.find('.pw-modal[data-reload-on-close]');
510
if ($reloadlinks.length) {
611
const page = $panel.data('page') || 1;
@@ -16,9 +21,8 @@ function initPanel($panel) {
1621
event.preventDefault();
1722
const url = event.currentTarget.href;
1823
const page = (url.match(/\d+$/) || [])[0] || 1;
19-
const params = { page };
2024
$panel.data('page', page);
21-
$panel.trigger('reload', { animate: false, params });
25+
submitParamsAndReload({ page });
2226
});
2327
}
2428

@@ -27,10 +31,16 @@ function initPanel($panel) {
2731
$actionButtons.on('click', (event) => {
2832
event.preventDefault();
2933
const action = event.currentTarget.dataset.action;
34+
const confirm = event.currentTarget.dataset.actionConfirm;
3035
const key = `actions${action}`
3136
const value = event.currentTarget.dataset.actionValue;
3237
const params = { [key]: value };
33-
$panel.trigger('reload', { animate: false, params });
38+
console.log(confirm);
39+
if (confirm) {
40+
ProcessWire.confirm(confirm, () => submitParamsAndReload(params));
41+
} else {
42+
submitParamsAndReload(params);
43+
}
3444
});
3545
}
3646

@@ -42,7 +52,7 @@ function initPanel($panel) {
4252
const checked = event.target.checked;
4353
const value = checked ? 1 : '';
4454
const params = { [name]: value };
45-
$panel.trigger('reload', { animate: false, params });
55+
submitParamsAndReload(params);
4656
});
4757
}
4858
}

0 commit comments

Comments
 (0)