Mobile App support in custom plugin

Re: Mobile App support in custom plugin

by Dani Palou -
Number of replies: 2
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi,

the PHP function that returns the template can also return Javascript code that will run when your plugin is rendered in the app. E.g. the Big Blue Button plugin does it.

If you haven't done it already, I recommend you to read this page that contains a lot of information about supporting plugins in the app. As you'll see we provide some directives to easily call WebServices, like core-site-plugins-call-ws, maybe that's enough for you.

Cheers,
Dani
Average of ratings: Useful (1)
In reply to Dani Palou

Re: Mobile App support in custom plugin

by Евгений Мамаев -
Picture of Plugin developers

Thank you, Dani, for help! I have read this page and now I have questions about how can I write custom JavaScript code to be able to show dialog box with a button in Mobile App (on my plugin page). When a user clicks a button, it should send AJAX request to server with some custom data (userid and current time). So, what are the guidelines and any samples for this?

I have searched the other plugins code and have found only mod_choicegroup sample code with such JavaScript you wrote.

It has the following code:

that.CoreDomUtilsProvider.showConfirm(that.TranslateService.instant('core.areyousure'));

Can I use it to send AJAX requiest after user confirms the question?

In reply to Евгений Мамаев

Re: Mobile App support in custom plugin

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Hi,

the showConfirm will display a confirmation dialog with the text you specify, and it returns a promise. If the user confirms, the promise is resolved. If the user cancels, then it's rejected.

So you should do something like:

that.CoreDomUtilsProvider.showConfirm(that.TranslateService.instant('core.areyousure')).then(() => {
    // Send the AJAX data.
}).catch(() => {
    // User canceled, stop.
});

Does your AJAX request use a WebService? Because the app has some APIs to call WebServices. If you don't, then you'll need to use XMLHttpRequest or Angular's HttpClient service to do it.

Cheers,
Dani