parent
96e3b3e769
commit
0fdab7d7c7
|
@ -766,17 +766,7 @@ export default defineComponent({
|
|||
* Download the currently selected files
|
||||
*/
|
||||
async downloadSelection(selection: Selection) {
|
||||
if (
|
||||
selection.size >= 100 &&
|
||||
!(await utils.confirmDestructive({
|
||||
title: this.t('memories', 'Download'),
|
||||
message: this.t('memories', 'You are about to download a large number of files.'),
|
||||
confirm: this.t('memories', 'Continue'),
|
||||
cancel: this.t('memories', 'Cancel'),
|
||||
}))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (selection.size >= 100 && !(await utils.dialogs.downloadItems(selection.size))) return;
|
||||
await dav.downloadFilesByPhotos(selection.photosNoDupFileId());
|
||||
},
|
||||
|
||||
|
@ -802,17 +792,7 @@ export default defineComponent({
|
|||
* Delete the currently selected photos
|
||||
*/
|
||||
async deleteSelection(selection: Selection) {
|
||||
if (
|
||||
selection.size >= 100 &&
|
||||
!(await utils.confirmDestructive({
|
||||
title: this.t('memories', 'Delete'),
|
||||
message: this.t('memories', 'You are about to delete a large number of files'),
|
||||
confirm: this.t('memories', 'Continue'),
|
||||
cancel: this.t('memories', 'Cancel'),
|
||||
}))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (!(await utils.dialogs.moveToTrash(selection.size))) return;
|
||||
|
||||
try {
|
||||
for await (const delIds of dav.deletePhotos(selection.photosNoDupFileId())) {
|
||||
|
@ -844,17 +824,7 @@ export default defineComponent({
|
|||
* Archive the currently selected photos
|
||||
*/
|
||||
async archiveSelection(selection: Selection) {
|
||||
if (
|
||||
selection.size >= 100 &&
|
||||
!(await utils.confirmDestructive({
|
||||
title: this.t('memories', 'Move'),
|
||||
message: this.t('memories', 'You are about to move a large number of files'),
|
||||
confirm: this.t('memories', 'Continue'),
|
||||
cancel: this.t('memories', 'Cancel'),
|
||||
}))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (selection.size >= 50 && !(await utils.dialogs.moveItems(selection.size))) return;
|
||||
|
||||
for await (let delIds of dav.archiveFilesByIds(Array.from(selection.fileids()), !this.routeIsArchive)) {
|
||||
this.deleteSelectedPhotosById(delIds, selection);
|
||||
|
|
|
@ -926,20 +926,17 @@ export default defineComponent({
|
|||
},
|
||||
|
||||
/** Key press events */
|
||||
async keydown(e: KeyboardEvent) {
|
||||
if (
|
||||
e.key === 'Delete' &&
|
||||
!this.routeIsPublic &&
|
||||
(await utils.confirmDestructive({
|
||||
title: this.t('memories', 'Are you sure you want to delete?'),
|
||||
}))
|
||||
) {
|
||||
keydown(e: KeyboardEvent) {
|
||||
if (e.key === 'Delete') {
|
||||
this.deleteCurrent();
|
||||
}
|
||||
},
|
||||
|
||||
/** Delete this photo and refresh */
|
||||
async deleteCurrent() {
|
||||
if (this.routeIsPublic) return;
|
||||
if (!(await utils.dialogs.moveToTrash(1))) return;
|
||||
|
||||
let idx = this.photoswipe!.currIndex - this.globalAnchor;
|
||||
const photo = this.list[idx];
|
||||
if (!photo) return;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { translate as t } from '@nextcloud/l10n';
|
||||
import { translate as t, translatePlural as n } from '@nextcloud/l10n';
|
||||
|
||||
// https://github.com/nextcloud/server/blob/4b7ec0a0c18d4e2007565dc28ee214814940161e/core/src/OC/dialogs.js
|
||||
const dialogs = (<any>OC).dialogs;
|
||||
const oc_dialogs = (<any>OC).dialogs;
|
||||
|
||||
type ConfirmOptions = {
|
||||
/** Title of dialog */
|
||||
|
@ -25,7 +25,7 @@ export function confirmDestructive(options: ConfirmOptions): Promise<boolean> {
|
|||
{
|
||||
title: '',
|
||||
message: '',
|
||||
type: dialogs.YES_NO_BUTTONS,
|
||||
type: oc_dialogs.YES_NO_BUTTONS,
|
||||
confirm: t('memories', 'Yes'),
|
||||
confirmClasses: 'error',
|
||||
cancel: t('memories', 'No'),
|
||||
|
@ -55,7 +55,7 @@ export function confirmDestructive(options: ConfirmOptions): Promise<boolean> {
|
|||
// Watch changes to body
|
||||
observer.observe(document.body, { childList: true });
|
||||
|
||||
return new Promise((resolve) => dialogs.confirmDestructive(opts.message, opts.title, opts, resolve));
|
||||
return new Promise((resolve) => oc_dialogs.confirmDestructive(opts.message, opts.title, opts, resolve));
|
||||
}
|
||||
|
||||
type PromptOptions = {
|
||||
|
@ -73,7 +73,7 @@ type PromptOptions = {
|
|||
|
||||
export async function prompt(opts: PromptOptions): Promise<string | null> {
|
||||
return new Promise((resolve) => {
|
||||
dialogs.prompt(
|
||||
oc_dialogs.prompt(
|
||||
opts.message ?? '',
|
||||
opts.title ?? '',
|
||||
(success: boolean, value: string) => resolve(success ? value : null),
|
||||
|
@ -83,3 +83,28 @@ export async function prompt(opts: PromptOptions): Promise<string | null> {
|
|||
);
|
||||
});
|
||||
}
|
||||
|
||||
/** Bespoke confirmation dialogs for re-use */
|
||||
export const dialogs = {
|
||||
moveToTrash: (count: number) =>
|
||||
confirmDestructive({
|
||||
title: n('memories', 'Move {count} item to trash?', 'Move {count} items to trash?', count, { count }),
|
||||
message: t('memories', 'Files in trash may be automatically deleted after a fixed period of time.'),
|
||||
}),
|
||||
|
||||
downloadItems: (count: number) =>
|
||||
confirmDestructive({
|
||||
title: t('memories', 'Download'),
|
||||
message: t('memories', 'You are about to download {count} items.', { count }),
|
||||
confirm: t('memories', 'Continue'),
|
||||
cancel: t('memories', 'Cancel'),
|
||||
}),
|
||||
|
||||
moveItems: (count: number) =>
|
||||
confirmDestructive({
|
||||
title: t('memories', 'Move'),
|
||||
message: t('memories', 'You are about to move {count} items.', { count }),
|
||||
confirm: t('memories', 'Continue'),
|
||||
cancel: t('memories', 'Cancel'),
|
||||
}),
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue