-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.js
More file actions
52 lines (47 loc) · 1.78 KB
/
delete.js
File metadata and controls
52 lines (47 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import GObject from 'gi://GObject';
import * as ModalDialog from 'resource:///org/gnome/shell/ui/modalDialog.js';
import * as Dialog from 'resource:///org/gnome/shell/ui/dialog.js';
import Clutter from 'gi://Clutter';
import {gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';
export const DeleteConfirmationDialog = GObject.registerClass(
class DeleteConfirmationDialog extends ModalDialog.ModalDialog {
_init(article, api, notifications, refreshCallback) {
super._init({
styleClass: 'delete-confirmation-dialog',
});
this._article = article;
this._api = api;
this._notifications = notifications;
this._refreshCallback = refreshCallback;
const content = new Dialog.MessageDialogContent({
title: _('Delete confirmation'),
description: `Permanently Delete "${this._article.title}"?\n\nThis action cannot be undone.`,
});
this.contentLayout.add_child(content);
this.setButtons([
{
label: _('Cancel'),
action: () => this.close(),
key: Clutter.KEY_Escape,
},
{
label: _('Delete'),
action: () => this._delete(),
default: true,
},
]);
}
_delete() {
this.close();
this._api.deleteArticle(this._article.id)
.then(() => {
this._notifications.showInfo(_('Article deleted successfully'));
if (this._refreshCallback)
this._refreshCallback();
})
.catch(e => {
console.error('Failed to delete article:', e);
this._notifications.showError(_('Failed to delete article'));
});
}
});