From e3e559da6fd114ba096e356306b720dd2547d7dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 31 Oct 2019 12:54:21 +0100 Subject: [PATCH] MOBILE-3157 utils: Add shortcut for delete confirmations --- src/addon/calendar/pages/event/event.ts | 5 +---- src/addon/messages/pages/discussion/discussion.ts | 2 +- src/addon/mod/choice/components/index/index.ts | 2 +- src/addon/mod/data/providers/helper.ts | 2 +- .../mod/workshop/pages/submission/submission.ts | 2 +- src/addon/notes/components/list/list.ts | 6 ++---- src/components/attachments/attachments.ts | 2 +- src/components/local-file/local-file.ts | 4 ++-- src/core/comments/pages/viewer/viewer.ts | 4 ++-- src/core/course/providers/helper.ts | 2 +- src/core/login/pages/sites/sites.ts | 4 +--- src/providers/utils/dom.ts | 13 +++++++++++++ 12 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/addon/calendar/pages/event/event.ts b/src/addon/calendar/pages/event/event.ts index 9d12d644b..4eae82b39 100644 --- a/src/addon/calendar/pages/event/event.ts +++ b/src/addon/calendar/pages/event/event.ts @@ -347,10 +347,7 @@ export class AddonCalendarEventPage implements OnDestroy { e.preventDefault(); e.stopPropagation(); - const message = this.translate.instant('core.areyousure'); - const okText = this.translate.instant('core.delete'); - - this.domUtils.showConfirm(message, undefined, okText).then(() => { + this.domUtils.showDeleteConfirm().then(() => { const modal = this.domUtils.showModalLoading('core.deleting', true); this.calendarProvider.deleteEventReminder(id).then(() => { this.calendarProvider.getEventReminders(this.eventId).then((reminders) => { diff --git a/src/addon/messages/pages/discussion/discussion.ts b/src/addon/messages/pages/discussion/discussion.ts index 41013c2ac..3a56f49c6 100644 --- a/src/addon/messages/pages/discussion/discussion.ts +++ b/src/addon/messages/pages/discussion/discussion.ts @@ -1276,7 +1276,7 @@ export class AddonMessagesDiscussionPage implements OnDestroy { deleteConversation(done?: () => void): void { const confirmMessage = 'addon.messages.' + (this.isSelf ? 'deleteallselfconfirm' : 'deleteallconfirm'); - this.domUtils.showConfirm(this.translate.instant(confirmMessage)).then(() => { + this.domUtils.showDeleteConfirm(confirmMessage).then(() => { this.deleteIcon = 'spinner'; return this.messagesProvider.deleteConversation(this.conversation.id).then(() => { diff --git a/src/addon/mod/choice/components/index/index.ts b/src/addon/mod/choice/components/index/index.ts index 66ed10c60..6423f5439 100644 --- a/src/addon/mod/choice/components/index/index.ts +++ b/src/addon/mod/choice/components/index/index.ts @@ -372,7 +372,7 @@ export class AddonModChoiceIndexComponent extends CoreCourseModuleMainActivityCo * Delete options selected. */ delete(): void { - this.domUtils.showConfirm(this.translate.instant('core.areyousure')).then(() => { + this.domUtils.showDeleteConfirm().then(() => { const modal = this.domUtils.showModalLoading('core.sending', true); this.choiceProvider.deleteResponses(this.choice.id, this.choice.name, this.courseId).then(() => { this.domUtils.scrollToTop(this.content); diff --git a/src/addon/mod/data/providers/helper.ts b/src/addon/mod/data/providers/helper.ts index 9381d2c6b..f59e62e5d 100644 --- a/src/addon/mod/data/providers/helper.ts +++ b/src/addon/mod/data/providers/helper.ts @@ -645,7 +645,7 @@ export class AddonModDataHelperProvider { showDeleteEntryModal(dataId: number, entryId: number, courseId?: number, siteId?: string): void { siteId = siteId || this.sitesProvider.getCurrentSiteId(); - this.domUtils.showConfirm(this.translate.instant('addon.mod_data.confirmdeleterecord')).then(() => { + this.domUtils.showDeleteConfirm('addon.mod_data.confirmdeleterecord').then(() => { const modal = this.domUtils.showModalLoading(); return this.getActivityCourseIdIfNotSet(dataId, courseId, siteId).then((courseId) => { diff --git a/src/addon/mod/workshop/pages/submission/submission.ts b/src/addon/mod/workshop/pages/submission/submission.ts index db25df347..464b2e3e3 100644 --- a/src/addon/mod/workshop/pages/submission/submission.ts +++ b/src/addon/mod/workshop/pages/submission/submission.ts @@ -461,7 +461,7 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy { * Perform the submission delete action. */ deleteSubmission(): void { - this.domUtils.showConfirm(this.translate.instant('addon.mod_workshop.submissiondeleteconfirm')).then(() => { + this.domUtils.showDeleteConfirm('addon.mod_workshop.submissiondeleteconfirm').then(() => { const modal = this.domUtils.showModalLoading('core.deleting', true); let success = false; this.workshopProvider.deleteSubmission(this.workshopId, this.submissionId, this.courseId).then(() => { diff --git a/src/addon/notes/components/list/list.ts b/src/addon/notes/components/list/list.ts index 843ff1c39..f242bcc31 100644 --- a/src/addon/notes/components/list/list.ts +++ b/src/addon/notes/components/list/list.ts @@ -14,7 +14,6 @@ import { Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { Content, ModalController } from 'ionic-angular'; -import { TranslateService } from '@ngx-translate/core'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreEventsProvider } from '@providers/events'; import { CoreSitesProvider } from '@providers/sites'; @@ -55,8 +54,7 @@ export class AddonNotesListComponent implements OnInit, OnDestroy { constructor(private domUtils: CoreDomUtilsProvider, private textUtils: CoreTextUtilsProvider, sitesProvider: CoreSitesProvider, eventsProvider: CoreEventsProvider, private modalCtrl: ModalController, private notesProvider: AddonNotesProvider, private notesSync: AddonNotesSyncProvider, - private userProvider: CoreUserProvider, private translate: TranslateService, - private notesOffline: AddonNotesOfflineProvider) { + private userProvider: CoreUserProvider, private notesOffline: AddonNotesOfflineProvider) { // Refresh data if notes are synchronized automatically. this.syncObserver = eventsProvider.on(AddonNotesSyncProvider.AUTO_SYNCED, (data) => { if (data.courseId == this.courseId) { @@ -211,7 +209,7 @@ export class AddonNotesListComponent implements OnInit, OnDestroy { e.preventDefault(); e.stopPropagation(); - this.domUtils.showConfirm(this.translate.instant('addon.notes.deleteconfirm')).then(() => { + this.domUtils.showDeleteConfirm('addon.notes.deleteconfirm').then(() => { this.notesProvider.deleteNote(note, this.courseId).then(() => { this.showDelete = false; diff --git a/src/components/attachments/attachments.ts b/src/components/attachments/attachments.ts index efb6bd21e..810165c39 100644 --- a/src/components/attachments/attachments.ts +++ b/src/components/attachments/attachments.ts @@ -113,7 +113,7 @@ export class CoreAttachmentsComponent implements OnInit { let promise; if (askConfirm) { - promise = this.domUtils.showConfirm(this.translate.instant('core.confirmdeletefile')); + promise = this.domUtils.showDeleteConfirm('core.confirmdeletefile'); } else { promise = Promise.resolve(); } diff --git a/src/components/local-file/local-file.ts b/src/components/local-file/local-file.ts index f6ee67eaa..dc01724f1 100644 --- a/src/components/local-file/local-file.ts +++ b/src/components/local-file/local-file.ts @@ -172,8 +172,8 @@ export class CoreLocalFileComponent implements OnInit { e.stopPropagation(); // Ask confirmation. - this.domUtils.showConfirm(this.translate.instant('core.confirmdeletefile')).then(() => { - const modal = this.domUtils.showModalLoading(); + this.domUtils.showDeleteConfirm('core.confirmdeletefile').then(() => { + const modal = this.domUtils.showModalLoading('core.deleting', true); return this.fileProvider.removeFile(this.relativePath).then(() => { this.onDelete.emit(); diff --git a/src/core/comments/pages/viewer/viewer.ts b/src/core/comments/pages/viewer/viewer.ts index b17d39f17..07fb57a03 100644 --- a/src/core/comments/pages/viewer/viewer.ts +++ b/src/core/comments/pages/viewer/viewer.ts @@ -324,8 +324,8 @@ export class CoreCommentsViewerPage implements OnDestroy { comment.itemid = this.itemId; comment.area = this.area; - this.domUtils.showConfirm(this.translate.instant('core.comments.deletecommentbyon', {$a: - { user: comment.fullname || '', time: time } })).then(() => { + this.domUtils.showDeleteConfirm('core.comments.deletecommentbyon', {$a: + { user: comment.fullname || '', time: time } }).then(() => { this.commentsProvider.deleteComment(comment).then(() => { this.showDelete = false; diff --git a/src/core/course/providers/helper.ts b/src/core/course/providers/helper.ts index d529e5187..1ecf7a124 100644 --- a/src/core/course/providers/helper.ts +++ b/src/core/course/providers/helper.ts @@ -407,7 +407,7 @@ export class CoreCourseHelperProvider { * @return Promise resolved when done. */ confirmAndRemoveFiles(module: any, courseId: number): Promise { - return this.domUtils.showConfirm(this.translate.instant('core.course.confirmdeletemodulefiles')).then(() => { + return this.domUtils.showDeleteConfirm('core.course.confirmdeletemodulefiles').then(() => { return this.prefetchDelegate.removeModuleFiles(module, courseId); }).catch((error) => { if (error) { diff --git a/src/core/login/pages/sites/sites.ts b/src/core/login/pages/sites/sites.ts index fe7cdb6d0..d8cf372fc 100644 --- a/src/core/login/pages/sites/sites.ts +++ b/src/core/login/pages/sites/sites.ts @@ -14,7 +14,6 @@ import { Component } from '@angular/core'; import { IonicPage } from 'ionic-angular'; -import { TranslateService } from '@ngx-translate/core'; import { CoreLoggerProvider } from '@providers/logger'; import { CoreSitesProvider, CoreSiteBasicInfo } from '@providers/sites'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; @@ -40,7 +39,6 @@ export class CoreLoginSitesPage { private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider, logger: CoreLoggerProvider, - private translate: TranslateService, private pushNotificationsProvider: CorePushNotificationsProvider) { this.logger = logger.getInstance('CoreLoginSitesPage'); } @@ -92,7 +90,7 @@ export class CoreLoginSitesPage { this.filterProvider.formatText(siteName, {clean: true, singleLine: true, filter: false}, [], site.id).then((siteName) => { - this.domUtils.showConfirm(this.translate.instant('core.login.confirmdeletesite', { sitename: siteName })).then(() => { + this.domUtils.showDeleteConfirm('core.login.confirmdeletesite', { sitename: siteName }).then(() => { this.sitesProvider.deleteSite(site.id).then(() => { this.sites.splice(index, 1); this.showDelete = false; diff --git a/src/providers/utils/dom.ts b/src/providers/utils/dom.ts index 7e96d421b..c8246dd1d 100644 --- a/src/providers/utils/dom.ts +++ b/src/providers/utils/dom.ts @@ -1194,6 +1194,19 @@ export class CoreDomUtilsProvider { return this.showAlert(title, message, buttonText, autocloseTime); } + /** + * Shortcut for a delete confirmation modal. + * + * @param translateMessage String key to show in the modal body translated. Default: 'core.areyousure'. + * @param translateArgs Arguments to pass to translate if necessary. + * @param options More options. See https://ionicframework.com/docs/v3/api/components/alert/AlertController/ + * @return Promise resolved if the user confirms and rejected with a canceled error if he cancels. + */ + showDeleteConfirm(translateMessage: string = 'core.areyousure', translateArgs: any = {}, options?: any): Promise { + return this.showConfirm(this.translate.instant(translateMessage, translateArgs), undefined, + this.translate.instant('core.delete'), undefined, options); + } + /** * Show a confirm modal. *