replace confirm
This commit is contained in:
parent
f1c35be539
commit
48695b94be
|
|
@ -311,6 +311,15 @@ function noteApp() {
|
||||||
renameFolderOldName: '',
|
renameFolderOldName: '',
|
||||||
renameFolderInput: '',
|
renameFolderInput: '',
|
||||||
|
|
||||||
|
// Generic confirm dialog (replaces window.confirm)
|
||||||
|
showConfirmModal: false,
|
||||||
|
confirmModalTitle: '',
|
||||||
|
confirmModalMessage: '',
|
||||||
|
confirmModalDanger: true,
|
||||||
|
confirmModalConfirmLabel: '',
|
||||||
|
confirmModalCancelLabel: '',
|
||||||
|
_confirmModalResolve: null,
|
||||||
|
|
||||||
// Share state
|
// Share state
|
||||||
showShareModal: false,
|
showShareModal: false,
|
||||||
shareInfo: null,
|
shareInfo: null,
|
||||||
|
|
@ -2689,7 +2698,10 @@ function noteApp() {
|
||||||
// Delete a media file (image, audio, video, PDF)
|
// Delete a media file (image, audio, video, PDF)
|
||||||
async deleteMedia(mediaPath) {
|
async deleteMedia(mediaPath) {
|
||||||
const filename = mediaPath.split('/').pop();
|
const filename = mediaPath.split('/').pop();
|
||||||
if (!confirm(this.t('media.confirm_delete', { name: filename }))) return;
|
const ok = await this.confirmModalAsk({
|
||||||
|
message: this.t('media.confirm_delete', { name: filename }),
|
||||||
|
});
|
||||||
|
if (!ok) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/notes/${encodeURIComponent(mediaPath)}`, {
|
const response = await fetch(`/api/notes/${encodeURIComponent(mediaPath)}`, {
|
||||||
|
|
@ -2777,9 +2789,15 @@ function noteApp() {
|
||||||
setTimeout(() => this.scrollToAnchor(anchor), 100);
|
setTimeout(() => this.scrollToAnchor(anchor), 100);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (confirm(this.t('notes.create_from_link', { path: notePath }))) {
|
} else {
|
||||||
// Note doesn't exist - create it (reuses createNote with duplicate check)
|
this.confirmModalAsk({
|
||||||
this.createNote(null, notePath);
|
message: this.t('notes.create_from_link', { path: notePath }),
|
||||||
|
danger: false,
|
||||||
|
title: this.t('sidebar.new_note'),
|
||||||
|
confirmLabel: this.t('common.create'),
|
||||||
|
}).then((ok) => {
|
||||||
|
if (ok) this.createNote(null, notePath);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -3558,6 +3576,42 @@ function noteApp() {
|
||||||
this.closeRenameFolderModal();
|
this.closeRenameFolderModal();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Theme-styled confirm dialog (replaces window.confirm).
|
||||||
|
* @param {{ message: string, title?: string, danger?: boolean, confirmLabel?: string, cancelLabel?: string }} options
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
|
*/
|
||||||
|
confirmModalAsk(options = {}) {
|
||||||
|
const { message, title, danger = true, confirmLabel, cancelLabel } = options;
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
this.confirmModalTitle = title || this.t('common.confirm_title');
|
||||||
|
this.confirmModalMessage = message || '';
|
||||||
|
this.confirmModalDanger = danger;
|
||||||
|
this.confirmModalConfirmLabel = confirmLabel
|
||||||
|
|| (danger ? this.t('common.delete') : this.t('common.ok'));
|
||||||
|
this.confirmModalCancelLabel = cancelLabel || this.t('common.cancel');
|
||||||
|
this._confirmModalResolve = resolve;
|
||||||
|
this.showConfirmModal = true;
|
||||||
|
this.mobileSidebarOpen = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
confirmModalConfirm() {
|
||||||
|
this._confirmModalFinish(true);
|
||||||
|
},
|
||||||
|
|
||||||
|
confirmModalCancel() {
|
||||||
|
this._confirmModalFinish(false);
|
||||||
|
},
|
||||||
|
|
||||||
|
_confirmModalFinish(ok) {
|
||||||
|
if (!this._confirmModalResolve) return;
|
||||||
|
this.showConfirmModal = false;
|
||||||
|
const fn = this._confirmModalResolve;
|
||||||
|
this._confirmModalResolve = null;
|
||||||
|
fn(!!ok);
|
||||||
|
},
|
||||||
|
|
||||||
async submitRenameFolderModal() {
|
async submitRenameFolderModal() {
|
||||||
const folderPath = this.renameFolderPath;
|
const folderPath = this.renameFolderPath;
|
||||||
const currentName = this.renameFolderOldName;
|
const currentName = this.renameFolderOldName;
|
||||||
|
|
@ -3630,9 +3684,10 @@ function noteApp() {
|
||||||
|
|
||||||
// Delete folder
|
// Delete folder
|
||||||
async deleteFolder(folderPath, folderName) {
|
async deleteFolder(folderPath, folderName) {
|
||||||
const confirmation = confirm(this.t('folders.confirm_delete', { name: folderName }));
|
const ok = await this.confirmModalAsk({
|
||||||
|
message: this.t('folders.confirm_delete', { name: folderName }),
|
||||||
if (!confirmation) return;
|
});
|
||||||
|
if (!ok) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/folders/${encodeURIComponent(folderPath)}`, {
|
const response = await fetch(`/api/folders/${encodeURIComponent(folderPath)}`, {
|
||||||
|
|
@ -4128,7 +4183,10 @@ function noteApp() {
|
||||||
|
|
||||||
// Delete any note from sidebar
|
// Delete any note from sidebar
|
||||||
async deleteNote(notePath, noteName) {
|
async deleteNote(notePath, noteName) {
|
||||||
if (!confirm(this.t('notes.confirm_delete', { name: noteName }))) return;
|
const ok = await this.confirmModalAsk({
|
||||||
|
message: this.t('notes.confirm_delete', { name: noteName }),
|
||||||
|
});
|
||||||
|
if (!ok) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/notes/${notePath}`, {
|
const response = await fetch(`/api/notes/${notePath}`, {
|
||||||
|
|
@ -5647,7 +5705,12 @@ function noteApp() {
|
||||||
async revokeShareLink() {
|
async revokeShareLink() {
|
||||||
if (!this.currentNote) return;
|
if (!this.currentNote) return;
|
||||||
|
|
||||||
if (!confirm(this.t('share.confirm_revoke'))) return;
|
const ok = await this.confirmModalAsk({
|
||||||
|
message: this.t('share.confirm_revoke'),
|
||||||
|
danger: false,
|
||||||
|
confirmLabel: this.t('common.yes'),
|
||||||
|
});
|
||||||
|
if (!ok) return;
|
||||||
|
|
||||||
this.shareLoading = true;
|
this.shareLoading = true;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3300,6 +3300,45 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Confirm dialog (replaces window.confirm) -->
|
||||||
|
<div x-show="showConfirmModal"
|
||||||
|
@click.self="confirmModalCancel()"
|
||||||
|
@keydown.escape.window="showConfirmModal && confirmModalCancel()"
|
||||||
|
class="fixed inset-0 flex items-center justify-center p-4"
|
||||||
|
style="background-color: rgba(0, 0, 0, 0.5); z-index: 1250;"
|
||||||
|
x-cloak>
|
||||||
|
<div class="rounded-lg shadow-xl p-6 max-w-lg w-full mx-auto max-h-[90vh] overflow-y-auto"
|
||||||
|
style="background-color: var(--bg-secondary); color: var(--text-primary);"
|
||||||
|
@click.stop
|
||||||
|
role="alertdialog"
|
||||||
|
aria-modal="true"
|
||||||
|
:aria-labelledby="'confirm-modal-title'"
|
||||||
|
:aria-describedby="'confirm-modal-desc'">
|
||||||
|
<h2 id="confirm-modal-title" class="text-xl font-bold mb-3" style="color: var(--text-primary);" x-text="confirmModalTitle"></h2>
|
||||||
|
<p id="confirm-modal-desc" class="text-sm mb-6 whitespace-pre-line leading-relaxed" style="color: var(--text-secondary);" x-text="confirmModalMessage"></p>
|
||||||
|
<div class="flex flex-col-reverse sm:flex-row gap-2 sm:justify-end">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
@click="confirmModalCancel()"
|
||||||
|
class="w-full sm:w-auto px-4 py-2.5 rounded font-medium transition-colors"
|
||||||
|
style="background-color: var(--bg-tertiary); color: var(--text-primary);"
|
||||||
|
onmouseover="this.style.backgroundColor='var(--bg-hover)'"
|
||||||
|
onmouseout="this.style.backgroundColor='var(--bg-tertiary)'"
|
||||||
|
x-text="confirmModalCancelLabel"
|
||||||
|
></button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
@click="confirmModalConfirm()"
|
||||||
|
class="w-full sm:w-auto px-4 py-2.5 rounded font-medium text-white transition-colors"
|
||||||
|
:style="confirmModalDanger ? 'background-color: var(--error);' : 'background-color: var(--accent-primary);'"
|
||||||
|
@mouseenter="$el.style.backgroundColor = confirmModalDanger ? '#dc2626' : 'var(--accent-hover)'"
|
||||||
|
@mouseleave="$el.style.backgroundColor = confirmModalDanger ? 'var(--error)' : 'var(--accent-primary)'"
|
||||||
|
x-text="confirmModalConfirmLabel"
|
||||||
|
></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Quick Switcher Modal (Ctrl+K) -->
|
<!-- Quick Switcher Modal (Ctrl+K) -->
|
||||||
<div x-show="showQuickSwitcher"
|
<div x-show="showQuickSwitcher"
|
||||||
@click.self="closeQuickSwitcher()"
|
@click.self="closeQuickSwitcher()"
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
"rename": "Umbenennen",
|
"rename": "Umbenennen",
|
||||||
"create": "Erstellen",
|
"create": "Erstellen",
|
||||||
"close": "Schließen",
|
"close": "Schließen",
|
||||||
|
"confirm_title": "Bestätigen",
|
||||||
"yes": "✓ Ja",
|
"yes": "✓ Ja",
|
||||||
"no": "✗ Nein",
|
"no": "✗ Nein",
|
||||||
"ok": "OK",
|
"ok": "OK",
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
"rename": "Rename",
|
"rename": "Rename",
|
||||||
"create": "Create",
|
"create": "Create",
|
||||||
"close": "Close",
|
"close": "Close",
|
||||||
|
"confirm_title": "Confirm",
|
||||||
"yes": "✓ Yes",
|
"yes": "✓ Yes",
|
||||||
"no": "✗ No",
|
"no": "✗ No",
|
||||||
"ok": "OK",
|
"ok": "OK",
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
"rename": "Rename",
|
"rename": "Rename",
|
||||||
"create": "Create",
|
"create": "Create",
|
||||||
"close": "Close",
|
"close": "Close",
|
||||||
|
"confirm_title": "Confirm",
|
||||||
"yes": "✓ Yes",
|
"yes": "✓ Yes",
|
||||||
"no": "✗ No",
|
"no": "✗ No",
|
||||||
"ok": "OK",
|
"ok": "OK",
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
"rename": "Renombrar",
|
"rename": "Renombrar",
|
||||||
"create": "Crear",
|
"create": "Crear",
|
||||||
"close": "Cerrar",
|
"close": "Cerrar",
|
||||||
|
"confirm_title": "Confirmar",
|
||||||
"yes": "✓ Sí",
|
"yes": "✓ Sí",
|
||||||
"no": "✗ No",
|
"no": "✗ No",
|
||||||
"ok": "Aceptar",
|
"ok": "Aceptar",
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
"rename": "Renommer",
|
"rename": "Renommer",
|
||||||
"create": "Créer",
|
"create": "Créer",
|
||||||
"close": "Fermer",
|
"close": "Fermer",
|
||||||
|
"confirm_title": "Confirmer",
|
||||||
"yes": "✓ Oui",
|
"yes": "✓ Oui",
|
||||||
"no": "✗ Non",
|
"no": "✗ Non",
|
||||||
"ok": "OK",
|
"ok": "OK",
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
"rename": "Átnevez",
|
"rename": "Átnevez",
|
||||||
"create": "Létrehoz",
|
"create": "Létrehoz",
|
||||||
"close": "Bezár",
|
"close": "Bezár",
|
||||||
|
"confirm_title": "Megerősítés",
|
||||||
"yes": "✓ Igen",
|
"yes": "✓ Igen",
|
||||||
"no": "✗ Nem",
|
"no": "✗ Nem",
|
||||||
"ok": "OK",
|
"ok": "OK",
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
"rename": "Rinomina",
|
"rename": "Rinomina",
|
||||||
"create": "Crea",
|
"create": "Crea",
|
||||||
"close": "Chiudi",
|
"close": "Chiudi",
|
||||||
|
"confirm_title": "Conferma",
|
||||||
"yes": "✓ Sì",
|
"yes": "✓ Sì",
|
||||||
"no": "✗ No",
|
"no": "✗ No",
|
||||||
"ok": "OK",
|
"ok": "OK",
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
"rename": "名前変更",
|
"rename": "名前変更",
|
||||||
"create": "作成",
|
"create": "作成",
|
||||||
"close": "閉じる",
|
"close": "閉じる",
|
||||||
|
"confirm_title": "確認",
|
||||||
"yes": "✓ はい",
|
"yes": "✓ はい",
|
||||||
"no": "✗ いいえ",
|
"no": "✗ いいえ",
|
||||||
"ok": "OK",
|
"ok": "OK",
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
"rename": "Переименовать",
|
"rename": "Переименовать",
|
||||||
"create": "Создать",
|
"create": "Создать",
|
||||||
"close": "Закрыть",
|
"close": "Закрыть",
|
||||||
|
"confirm_title": "Подтвердить",
|
||||||
"yes": "✓ Да",
|
"yes": "✓ Да",
|
||||||
"no": "✗ Нет",
|
"no": "✗ Нет",
|
||||||
"ok": "ОК",
|
"ok": "ОК",
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
"rename": "Preimenuj",
|
"rename": "Preimenuj",
|
||||||
"create": "Ustvari",
|
"create": "Ustvari",
|
||||||
"close": "Zapri",
|
"close": "Zapri",
|
||||||
|
"confirm_title": "Potrdi",
|
||||||
"yes": "✓ Da",
|
"yes": "✓ Da",
|
||||||
"no": "✗ Ne",
|
"no": "✗ Ne",
|
||||||
"ok": "V redu",
|
"ok": "V redu",
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
"rename": "重命名",
|
"rename": "重命名",
|
||||||
"create": "创建",
|
"create": "创建",
|
||||||
"close": "关闭",
|
"close": "关闭",
|
||||||
|
"confirm_title": "确认",
|
||||||
"yes": "✓ 是",
|
"yes": "✓ 是",
|
||||||
"no": "✗ 否",
|
"no": "✗ 否",
|
||||||
"ok": "确定",
|
"ok": "确定",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue