Adding Custom Modal Errors In Moodle App

Adding Custom Modal Errors In Moodle App

- Sanat Sharma の投稿
返信数: 3

Hi,
I'm developing a plugin for moodle mobile and need to show an error message (and send user to the Dashboard) when a PHP function returns false.

How does one do Modal/Toast Messages in Moodle Mobile? Furthermore, how does one redirect users to pages? Thanks!

Sanat Sharma への返信

Re: Adding Custom Modal Errors In Moodle App

- Dani Palou の投稿
画像 Core developers 画像 Moodle HQ 画像 Particularly helpful Moodlers 画像 Peer reviewers 画像 Plugin developers
Hi Sanat,

your plugin's Javascript code should have access to a service named CoreDomUtilsProvider, and that service has some helper function for modals. E.g. in here you can see a function that the app usually uses to display an error message. You can also interact with the Ionic services directly: AlertController, LoadingController, PopoverController, ...

As for the redirect, you can use the following line to send the user to the Dashboard:

this.CoreLoginHelperProvider.redirect('CoreCoursesDashboardPage');
This line will do the following:

  • If the user is in a tab that isn't the Dashboard tab, the Dashboard tab will be selected and the Dashboard will be reloaded.
  • If the user is in the Dashboard tab, a confirm message will be displayed asking the user if he wants to go back to Dashboard. If he confirms, he'll go back to the Dashboard.
If you don't want the confirm to be displayed, please try this (I haven't tested it though):

if (this.NavController && this.NavController.root == 'CoreCoursesDashboardPage') {
    this.NavController.goToRoot();

} else {
    this.CoreLoginHelperProvider.redirect('CoreCoursesDashboardPage');
}
Cheers,
Dani