diff --git a/src/addons/messages/pages/discussion/discussion.html b/src/addons/messages/pages/discussion/discussion.html index 94fa726af..f38237550 100644 --- a/src/addons/messages/pages/discussion/discussion.html +++ b/src/addons/messages/pages/discussion/discussion.html @@ -44,8 +44,8 @@ 'addon.messages.muteconversation') | translate" (action)="changeMute($event)" [closeOnClick]="false" [iconAction]="muteIcon"> + [content]="'addon.messages.showdeletemessages' | translate" + iconAction="toggle" [(toggle)]="showDelete"> diff --git a/src/addons/messages/pages/discussion/discussion.page.ts b/src/addons/messages/pages/discussion/discussion.page.ts index c99f24161..bdff8c4f9 100644 --- a/src/addons/messages/pages/discussion/discussion.page.ts +++ b/src/addons/messages/pages/discussion/discussion.page.ts @@ -1263,15 +1263,6 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView return !nextMessage || nextMessage.useridfrom != message.useridfrom || !!nextMessage.showDate; } - /** - * Toggles delete state. - * - * @param enabled Wether to enable or disable show delete toggle. - */ - toggleDelete(enable: boolean): void { - this.showDelete = enable; - } - /** * View info. If it's an individual conversation, go to the user profile. * If it's a group conversation, view info about the group. diff --git a/src/core/components/context-menu/context-menu-item.ts b/src/core/components/context-menu/context-menu-item.ts index 4129ef889..2d6a66587 100644 --- a/src/core/components/context-menu/context-menu-item.ts +++ b/src/core/components/context-menu/context-menu-item.ts @@ -38,7 +38,7 @@ export class CoreContextMenuItemComponent implements OnInit, OnDestroy, OnChange @Input() iconDescription?: string; // Name of the icon to be shown on the left side of the item. @Input() iconAction?: string; // Name of the icon to show on the right side of the item. Represents the action to do on click. // If is "spinner" an spinner will be shown. - // If is "toggle" an toggle switch will be shown. + // If is "toggle" a toggle switch will be shown. // If no icon or spinner is selected, no action or link will work. // If href but no iconAction is provided arrow-right will be used. @Input() iconSlash?: boolean; // Display a red slash over the icon. @@ -56,6 +56,7 @@ export class CoreContextMenuItemComponent implements OnInit, OnDestroy, OnChange @Input() toggle = false; // Whether the toggle is on or off. @Output() action?: EventEmitter<() => void>; // Will emit an event when the item clicked. @Output() onClosed?: EventEmitter<() => void>; // Will emit an event when the popover is closed because the item was clicked. + @Output() toggleChange = new EventEmitter();// Will emit an event when toggle changes to enable 2-way data binding. protected hasAction = false; protected destroyed = false; @@ -89,6 +90,21 @@ export class CoreContextMenuItemComponent implements OnInit, OnDestroy, OnChange } } + /** + * Toggle changed. + * + * @param event Event. + */ + toggleChanged(event: Event): void { + if (this.toggle === undefined) { + return; + } + + event.preventDefault(); + event.stopPropagation(); + this.toggleChange.emit(this.toggle); + } + /** * Component destroyed. */ diff --git a/src/core/components/context-menu/context-menu-popover.ts b/src/core/components/context-menu/context-menu-popover.ts index 17e6e1885..46461b45f 100644 --- a/src/core/components/context-menu/context-menu-popover.ts +++ b/src/core/components/context-menu/context-menu-popover.ts @@ -55,6 +55,12 @@ export class CoreContextMenuPopoverComponent { * @return Return true if success, false if error. */ itemClicked(event: Event, item: CoreContextMenuItemComponent): boolean { + if (item.iconAction == 'toggle' && !event.defaultPrevented) { + event.preventDefault(); + event.stopPropagation(); + item.toggle = !item.toggle; + } + if (!!item.action && item.action.observers.length > 0) { event.preventDefault(); event.stopPropagation(); diff --git a/src/core/components/context-menu/core-context-menu-popover.html b/src/core/components/context-menu/core-context-menu-popover.html index 4baeb6c85..36091feec 100644 --- a/src/core/components/context-menu/core-context-menu-popover.html +++ b/src/core/components/context-menu/core-context-menu-popover.html @@ -12,14 +12,14 @@

- - - - - + + + + + {{item.badge}} diff --git a/src/core/features/course/pages/contents/contents.html b/src/core/features/course/pages/contents/contents.html index 938d20ba6..1e2ab177a 100644 --- a/src/core/features/course/pages/contents/contents.html +++ b/src/core/features/course/pages/contents/contents.html @@ -1,7 +1,7 @@ - + { - this.toggleDownload(data.enabled); + this.downloadEnabled = this.displayEnableDownload && data.enabled; }); } @@ -494,12 +494,9 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { /** * Toggle download enabled. - * - * @param enable Whether enable or disable download enabled toggle. */ - toggleDownload(enable: boolean): void { - this.downloadEnabled = - CoreCourses.setCourseDownloadOptionsEnabled(this.displayEnableDownload && enable); + toggleDownload(): void { + CoreCourses.setCourseDownloadOptionsEnabled(this.downloadEnabled); } /** diff --git a/src/core/features/courses/pages/categories/categories.html b/src/core/features/courses/pages/categories/categories.html index 33fb19de2..7ecd32f4b 100644 --- a/src/core/features/courses/pages/categories/categories.html +++ b/src/core/features/courses/pages/categories/categories.html @@ -10,11 +10,11 @@ + [content]="'core.settings.showdownloadoptions' | translate" (action)="toggleDownload()" + iconAction="toggle" [(toggle)]="downloadEnabled"> + [content]="'core.courses.showonlyenrolled' | translate" (action)="filterEnrolled()" + iconAction="toggle" [(toggle)]="showOnlyEnrolled"> diff --git a/src/core/features/courses/pages/categories/categories.ts b/src/core/features/courses/pages/categories/categories.ts index 34dd3c7a0..3cce72f0a 100644 --- a/src/core/features/courses/pages/categories/categories.ts +++ b/src/core/features/courses/pages/categories/categories.ts @@ -76,7 +76,7 @@ export class CoreCoursesCategoriesPage implements OnInit, OnDestroy { }, this.currentSiteId); this.downloadEnabledObserver = CoreEvents.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, (data) => { - this.toggleDownload(data.enabled); + this.downloadEnabled = (this.downloadCourseEnabled || this.downloadCoursesEnabled) && data.enabled; }); } @@ -133,7 +133,7 @@ export class CoreCoursesCategoriesPage implements OnInit, OnDestroy { try { this.categoryCourses = await CoreCourses.getCoursesByField('category', this.categoryId); - await this.toggleEnrolled(this.showOnlyEnrolled); + await this.filterEnrolled(); } catch (error) { !this.isDestroyed && CoreDomUtils.showErrorModalDefault(error, 'core.courses.errorloadcourses', true); } @@ -178,13 +178,9 @@ export class CoreCoursesCategoriesPage implements OnInit, OnDestroy { } /** - * Toggle show only my courses. - * - * @param enable If enable or disable. + * Filter my courses or not. */ - async toggleEnrolled(enable: boolean): Promise { - this.showOnlyEnrolled = enable; - + async filterEnrolled(): Promise { if (!this.showOnlyEnrolled) { this.courses = this.categoryCourses; } else { @@ -207,12 +203,9 @@ export class CoreCoursesCategoriesPage implements OnInit, OnDestroy { /** * Toggle download enabled. - * - * @param enable If enable or disable. */ - toggleDownload(enable: boolean): void { - this.downloadEnabled = - CoreCourses.setCourseDownloadOptionsEnabled((this.downloadCourseEnabled || this.downloadCoursesEnabled) && enable); + toggleDownload(): void { + CoreCourses.setCourseDownloadOptionsEnabled(this.downloadEnabled); } /** diff --git a/src/core/features/courses/pages/dashboard/dashboard.html b/src/core/features/courses/pages/dashboard/dashboard.html index a7dc2fc79..c4315e7d1 100644 --- a/src/core/features/courses/pages/dashboard/dashboard.html +++ b/src/core/features/courses/pages/dashboard/dashboard.html @@ -4,8 +4,8 @@ + [content]="'core.settings.showdownloadoptions' | translate" (action)="switchDownload()" + iconAction="toggle" [(toggle)]="downloadEnabled"> diff --git a/src/core/features/courses/pages/dashboard/dashboard.ts b/src/core/features/courses/pages/dashboard/dashboard.ts index 712f893e5..5102614cc 100644 --- a/src/core/features/courses/pages/dashboard/dashboard.ts +++ b/src/core/features/courses/pages/dashboard/dashboard.ts @@ -54,11 +54,11 @@ export class CoreCoursesDashboardPage implements OnInit, OnDestroy { this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); - this.switchDownload(this.downloadEnabled); + this.downloadEnabled = (this.downloadCourseEnabled || this.downloadCoursesEnabled) && this.downloadEnabled; }, CoreSites.getCurrentSiteId()); this.downloadEnabledObserver = CoreEvents.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, (data) => { - this.switchDownload(data.enabled); + this.downloadEnabled = (this.downloadCourseEnabled || this.downloadCoursesEnabled) && data.enabled; }); } @@ -149,12 +149,9 @@ export class CoreCoursesDashboardPage implements OnInit, OnDestroy { /** * Switch download enabled. - * - * @param enable If enable or disable. */ - switchDownload(enable: boolean): void { - this.downloadEnabled = - CoreCourses.setCourseDownloadOptionsEnabled((this.downloadCourseEnabled || this.downloadCoursesEnabled) && enable); + switchDownload(): void { + CoreCourses.setCourseDownloadOptionsEnabled(this.downloadEnabled); } /** diff --git a/src/core/features/courses/pages/list/list.html b/src/core/features/courses/pages/list/list.html index 89108f71e..114a5a78b 100644 --- a/src/core/features/courses/pages/list/list.html +++ b/src/core/features/courses/pages/list/list.html @@ -6,19 +6,19 @@

{{ 'core.courses.availablecourses' | translate }}

{{ 'core.courses.mycourses' | translate }}

- - - - - - + + + + + + diff --git a/src/core/features/courses/pages/list/list.ts b/src/core/features/courses/pages/list/list.ts index 9e192dc82..04d855ffb 100644 --- a/src/core/features/courses/pages/list/list.ts +++ b/src/core/features/courses/pages/list/list.ts @@ -86,7 +86,7 @@ export class CoreCoursesListPage implements OnInit, OnDestroy { this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); this.downloadEnabled = (this.downloadCourseEnabled || this.downloadCoursesEnabled) && this.downloadEnabled; - if (!this.searchEnabled) { + if (!this.searchEnabled && this.searchMode) { this.searchMode = false; this.fetchCourses(); @@ -94,7 +94,7 @@ export class CoreCoursesListPage implements OnInit, OnDestroy { }, this.currentSiteId); this.downloadEnabledObserver = CoreEvents.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, (data) => { - this.toggleDownload(data.enabled); + this.downloadEnabled = (this.downloadCourseEnabled || this.downloadCoursesEnabled) && data.enabled; }); } @@ -287,24 +287,17 @@ export class CoreCoursesListPage implements OnInit, OnDestroy { /** * Toggle show only my courses. - * - * @param enable If enable or disable. */ - toggleEnrolled(enable: boolean): void { + toggleEnrolled(): void { this.loaded = false; - this.showOnlyEnrolled = enable; - this.fetchCourses(); } /** * Toggle download enabled. - * - * @param enable If enable or disable. */ - toggleDownload(enable: boolean): void { - this.downloadEnabled = - CoreCourses.setCourseDownloadOptionsEnabled((this.downloadCourseEnabled || this.downloadCoursesEnabled) && enable); + toggleDownload(): void { + CoreCourses.setCourseDownloadOptionsEnabled(this.downloadEnabled); } /** diff --git a/src/core/features/courses/services/courses.ts b/src/core/features/courses/services/courses.ts index 9ccd82fbc..fa9a973c9 100644 --- a/src/core/features/courses/services/courses.ts +++ b/src/core/features/courses/services/courses.ts @@ -1229,17 +1229,14 @@ export class CoreCoursesProvider { * Set trigger and save the download option. * * @param enable True to enable, false to disable. - * @return Current status. */ - setCourseDownloadOptionsEnabled(enable: boolean): boolean { + setCourseDownloadOptionsEnabled(enable: boolean): void { if (this.downloadOptionsEnabled == enable) { - return enable; + return; } this.downloadOptionsEnabled = enable; CoreEvents.trigger(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, { enabled: enable }); - - return enable; } } diff --git a/src/core/features/sitehome/pages/index/index.html b/src/core/features/sitehome/pages/index/index.html index 179a73f10..4dd2ce8d5 100644 --- a/src/core/features/sitehome/pages/index/index.html +++ b/src/core/features/sitehome/pages/index/index.html @@ -4,8 +4,8 @@ + [content]="'core.settings.showdownloadoptions' | translate" (action)="switchDownload()" + iconAction="toggle" [(toggle)]="downloadEnabled"> diff --git a/src/core/features/sitehome/pages/index/index.ts b/src/core/features/sitehome/pages/index/index.ts index 81ecc1c03..777d6ce9c 100644 --- a/src/core/features/sitehome/pages/index/index.ts +++ b/src/core/features/sitehome/pages/index/index.ts @@ -66,7 +66,7 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy { }, CoreSites.getCurrentSiteId()); this.downloadEnabledObserver = CoreEvents.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, (data) => { - this.switchDownload(data.enabled); + this.downloadEnabled = data.enabled; }); } @@ -195,12 +195,9 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy { /** * Switch download enabled. - * - * @param enable If enable or disable. */ - switchDownload(enable: boolean): void { - this.downloadEnabled = - CoreCourses.setCourseDownloadOptionsEnabled(enable); + switchDownload(): void { + CoreCourses.setCourseDownloadOptionsEnabled(this.downloadEnabled); } /**