MOBILE-3157 utils: Add shortcut for delete confirmations

main
Pau Ferrer Ocaña 2019-10-31 12:54:21 +01:00
parent 32f320407d
commit e3e559da6f
12 changed files with 27 additions and 21 deletions

View File

@ -347,10 +347,7 @@ export class AddonCalendarEventPage implements OnDestroy {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
const message = this.translate.instant('core.areyousure'); this.domUtils.showDeleteConfirm().then(() => {
const okText = this.translate.instant('core.delete');
this.domUtils.showConfirm(message, undefined, okText).then(() => {
const modal = this.domUtils.showModalLoading('core.deleting', true); const modal = this.domUtils.showModalLoading('core.deleting', true);
this.calendarProvider.deleteEventReminder(id).then(() => { this.calendarProvider.deleteEventReminder(id).then(() => {
this.calendarProvider.getEventReminders(this.eventId).then((reminders) => { this.calendarProvider.getEventReminders(this.eventId).then((reminders) => {

View File

@ -1276,7 +1276,7 @@ export class AddonMessagesDiscussionPage implements OnDestroy {
deleteConversation(done?: () => void): void { deleteConversation(done?: () => void): void {
const confirmMessage = 'addon.messages.' + (this.isSelf ? 'deleteallselfconfirm' : 'deleteallconfirm'); const confirmMessage = 'addon.messages.' + (this.isSelf ? 'deleteallselfconfirm' : 'deleteallconfirm');
this.domUtils.showConfirm(this.translate.instant(confirmMessage)).then(() => { this.domUtils.showDeleteConfirm(confirmMessage).then(() => {
this.deleteIcon = 'spinner'; this.deleteIcon = 'spinner';
return this.messagesProvider.deleteConversation(this.conversation.id).then(() => { return this.messagesProvider.deleteConversation(this.conversation.id).then(() => {

View File

@ -372,7 +372,7 @@ export class AddonModChoiceIndexComponent extends CoreCourseModuleMainActivityCo
* Delete options selected. * Delete options selected.
*/ */
delete(): void { delete(): void {
this.domUtils.showConfirm(this.translate.instant('core.areyousure')).then(() => { this.domUtils.showDeleteConfirm().then(() => {
const modal = this.domUtils.showModalLoading('core.sending', true); const modal = this.domUtils.showModalLoading('core.sending', true);
this.choiceProvider.deleteResponses(this.choice.id, this.choice.name, this.courseId).then(() => { this.choiceProvider.deleteResponses(this.choice.id, this.choice.name, this.courseId).then(() => {
this.domUtils.scrollToTop(this.content); this.domUtils.scrollToTop(this.content);

View File

@ -645,7 +645,7 @@ export class AddonModDataHelperProvider {
showDeleteEntryModal(dataId: number, entryId: number, courseId?: number, siteId?: string): void { showDeleteEntryModal(dataId: number, entryId: number, courseId?: number, siteId?: string): void {
siteId = siteId || this.sitesProvider.getCurrentSiteId(); 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(); const modal = this.domUtils.showModalLoading();
return this.getActivityCourseIdIfNotSet(dataId, courseId, siteId).then((courseId) => { return this.getActivityCourseIdIfNotSet(dataId, courseId, siteId).then((courseId) => {

View File

@ -461,7 +461,7 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy {
* Perform the submission delete action. * Perform the submission delete action.
*/ */
deleteSubmission(): void { 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); const modal = this.domUtils.showModalLoading('core.deleting', true);
let success = false; let success = false;
this.workshopProvider.deleteSubmission(this.workshopId, this.submissionId, this.courseId).then(() => { this.workshopProvider.deleteSubmission(this.workshopId, this.submissionId, this.courseId).then(() => {

View File

@ -14,7 +14,6 @@
import { Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Content, ModalController } from 'ionic-angular'; import { Content, ModalController } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core';
import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreEventsProvider } from '@providers/events'; import { CoreEventsProvider } from '@providers/events';
import { CoreSitesProvider } from '@providers/sites'; import { CoreSitesProvider } from '@providers/sites';
@ -55,8 +54,7 @@ export class AddonNotesListComponent implements OnInit, OnDestroy {
constructor(private domUtils: CoreDomUtilsProvider, private textUtils: CoreTextUtilsProvider, constructor(private domUtils: CoreDomUtilsProvider, private textUtils: CoreTextUtilsProvider,
sitesProvider: CoreSitesProvider, eventsProvider: CoreEventsProvider, private modalCtrl: ModalController, sitesProvider: CoreSitesProvider, eventsProvider: CoreEventsProvider, private modalCtrl: ModalController,
private notesProvider: AddonNotesProvider, private notesSync: AddonNotesSyncProvider, private notesProvider: AddonNotesProvider, private notesSync: AddonNotesSyncProvider,
private userProvider: CoreUserProvider, private translate: TranslateService, private userProvider: CoreUserProvider, private notesOffline: AddonNotesOfflineProvider) {
private notesOffline: AddonNotesOfflineProvider) {
// Refresh data if notes are synchronized automatically. // Refresh data if notes are synchronized automatically.
this.syncObserver = eventsProvider.on(AddonNotesSyncProvider.AUTO_SYNCED, (data) => { this.syncObserver = eventsProvider.on(AddonNotesSyncProvider.AUTO_SYNCED, (data) => {
if (data.courseId == this.courseId) { if (data.courseId == this.courseId) {
@ -211,7 +209,7 @@ export class AddonNotesListComponent implements OnInit, OnDestroy {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); 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.notesProvider.deleteNote(note, this.courseId).then(() => {
this.showDelete = false; this.showDelete = false;

View File

@ -113,7 +113,7 @@ export class CoreAttachmentsComponent implements OnInit {
let promise; let promise;
if (askConfirm) { if (askConfirm) {
promise = this.domUtils.showConfirm(this.translate.instant('core.confirmdeletefile')); promise = this.domUtils.showDeleteConfirm('core.confirmdeletefile');
} else { } else {
promise = Promise.resolve(); promise = Promise.resolve();
} }

View File

@ -172,8 +172,8 @@ export class CoreLocalFileComponent implements OnInit {
e.stopPropagation(); e.stopPropagation();
// Ask confirmation. // Ask confirmation.
this.domUtils.showConfirm(this.translate.instant('core.confirmdeletefile')).then(() => { this.domUtils.showDeleteConfirm('core.confirmdeletefile').then(() => {
const modal = this.domUtils.showModalLoading(); const modal = this.domUtils.showModalLoading('core.deleting', true);
return this.fileProvider.removeFile(this.relativePath).then(() => { return this.fileProvider.removeFile(this.relativePath).then(() => {
this.onDelete.emit(); this.onDelete.emit();

View File

@ -324,8 +324,8 @@ export class CoreCommentsViewerPage implements OnDestroy {
comment.itemid = this.itemId; comment.itemid = this.itemId;
comment.area = this.area; comment.area = this.area;
this.domUtils.showConfirm(this.translate.instant('core.comments.deletecommentbyon', {$a: this.domUtils.showDeleteConfirm('core.comments.deletecommentbyon', {$a:
{ user: comment.fullname || '', time: time } })).then(() => { { user: comment.fullname || '', time: time } }).then(() => {
this.commentsProvider.deleteComment(comment).then(() => { this.commentsProvider.deleteComment(comment).then(() => {
this.showDelete = false; this.showDelete = false;

View File

@ -407,7 +407,7 @@ export class CoreCourseHelperProvider {
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
confirmAndRemoveFiles(module: any, courseId: number): Promise<any> { confirmAndRemoveFiles(module: any, courseId: number): Promise<any> {
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); return this.prefetchDelegate.removeModuleFiles(module, courseId);
}).catch((error) => { }).catch((error) => {
if (error) { if (error) {

View File

@ -14,7 +14,6 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { IonicPage } from 'ionic-angular'; import { IonicPage } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core';
import { CoreLoggerProvider } from '@providers/logger'; import { CoreLoggerProvider } from '@providers/logger';
import { CoreSitesProvider, CoreSiteBasicInfo } from '@providers/sites'; import { CoreSitesProvider, CoreSiteBasicInfo } from '@providers/sites';
import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreDomUtilsProvider } from '@providers/utils/dom';
@ -40,7 +39,6 @@ export class CoreLoginSitesPage {
private sitesProvider: CoreSitesProvider, private sitesProvider: CoreSitesProvider,
private loginHelper: CoreLoginHelperProvider, private loginHelper: CoreLoginHelperProvider,
logger: CoreLoggerProvider, logger: CoreLoggerProvider,
private translate: TranslateService,
private pushNotificationsProvider: CorePushNotificationsProvider) { private pushNotificationsProvider: CorePushNotificationsProvider) {
this.logger = logger.getInstance('CoreLoginSitesPage'); 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.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.sitesProvider.deleteSite(site.id).then(() => {
this.sites.splice(index, 1); this.sites.splice(index, 1);
this.showDelete = false; this.showDelete = false;

View File

@ -1194,6 +1194,19 @@ export class CoreDomUtilsProvider {
return this.showAlert(title, message, buttonText, autocloseTime); 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<any> {
return this.showConfirm(this.translate.instant(translateMessage, translateArgs), undefined,
this.translate.instant('core.delete'), undefined, options);
}
/** /**
* Show a confirm modal. * Show a confirm modal.
* *