MOBILE-4059 user: Close inapp after submission
parent
d78a7dd78b
commit
2143f49d0d
|
@ -2396,6 +2396,7 @@
|
||||||
"core.user.sendemail": "local_moodlemobileapp",
|
"core.user.sendemail": "local_moodlemobileapp",
|
||||||
"core.user.student": "moodle/defaultcoursestudent",
|
"core.user.student": "moodle/defaultcoursestudent",
|
||||||
"core.user.support": "local_moodlemobileapp",
|
"core.user.support": "local_moodlemobileapp",
|
||||||
|
"core.user.supportmessagesent": "user",
|
||||||
"core.user.supportsubject": "local_moodlemobileapp",
|
"core.user.supportsubject": "local_moodlemobileapp",
|
||||||
"core.user.teacher": "moodle/noneditingteacher",
|
"core.user.teacher": "moodle/noneditingteacher",
|
||||||
"core.user.useraccount": "moodle",
|
"core.user.useraccount": "moodle",
|
||||||
|
|
|
@ -66,6 +66,13 @@ export class CoreUserAuthenticatedSupportConfig extends CoreUserSupportConfig {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
getSupportPageLang(): string | null {
|
||||||
|
return this.site.infos?.lang ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -65,6 +65,13 @@ export class CoreUserGuestSupportConfig extends CoreUserSupportConfig {
|
||||||
return 'supportpage' in this.config;
|
return 'supportpage' in this.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
getSupportPageLang(): string | null {
|
||||||
|
return this.config.lang ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -29,6 +29,13 @@ export class CoreUserNullSupportConfig extends CoreUserSupportConfig {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
getSupportPageLang(): string | null {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -24,6 +24,13 @@ export abstract class CoreUserSupportConfig {
|
||||||
*/
|
*/
|
||||||
public abstract canContactSupport(): boolean;
|
public abstract canContactSupport(): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get language used in the support page, if any.
|
||||||
|
*
|
||||||
|
* @return Support page language.
|
||||||
|
*/
|
||||||
|
public abstract getSupportPageLang(): string | null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get url to use for contacting support.
|
* Get url to use for contacting support.
|
||||||
*
|
*
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
"sendemail": "Email",
|
"sendemail": "Email",
|
||||||
"student": "Student",
|
"student": "Student",
|
||||||
"support": "Contact site support",
|
"support": "Contact site support",
|
||||||
|
"supportmessagesent": "Your message has been sent.",
|
||||||
"supportsubject": "[App] {{subject}}",
|
"supportsubject": "[App] {{subject}}",
|
||||||
"teacher": "Non-editing teacher",
|
"teacher": "Non-editing teacher",
|
||||||
"userwithid": "User with ID {{id}}",
|
"userwithid": "User with ID {{id}}",
|
||||||
|
|
|
@ -24,6 +24,7 @@ import { CoreEvents } from '@singletons/events';
|
||||||
import { CoreSubscriptions } from '@singletons/subscriptions';
|
import { CoreSubscriptions } from '@singletons/subscriptions';
|
||||||
import { AlertButton } from '@ionic/angular';
|
import { AlertButton } from '@ionic/angular';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
|
import { CoreLang } from '@services/lang';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle site support.
|
* Handle site support.
|
||||||
|
@ -44,6 +45,7 @@ export class CoreUserSupportService {
|
||||||
|
|
||||||
if (supportPageUrl.endsWith('/user/contactsitesupport.php')) {
|
if (supportPageUrl.endsWith('/user/contactsitesupport.php')) {
|
||||||
this.populateSupportForm(browser, options.subject, options.message);
|
this.populateSupportForm(browser, options.subject, options.message);
|
||||||
|
this.listenSupportFormSubmission(browser, supportConfig.getSupportPageLang());
|
||||||
}
|
}
|
||||||
|
|
||||||
await CoreEvents.waitUntil(CoreEvents.IAB_EXIT);
|
await CoreEvents.waitUntil(CoreEvents.IAB_EXIT);
|
||||||
|
@ -106,6 +108,37 @@ export class CoreUserSupportService {
|
||||||
CoreEvents.once(CoreEvents.IAB_EXIT, () => unsubscribe());
|
CoreEvents.once(CoreEvents.IAB_EXIT, () => unsubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up listeners to close the browser when the contact form has been submitted.
|
||||||
|
*
|
||||||
|
* @param browser In App browser.
|
||||||
|
* @param lang Language used in the support page.
|
||||||
|
*/
|
||||||
|
protected async listenSupportFormSubmission(browser: InAppBrowserObject, lang: string | null): Promise<void> {
|
||||||
|
const appSuccessMessage = Translate.instant('core.user.supportmessagesent');
|
||||||
|
const lmsSuccessMessage = lang && await CoreLang.getMessage('core.user.supportmessagesent', lang);
|
||||||
|
const subscription = browser.on('loadstop').subscribe(async () => {
|
||||||
|
const result = await browser.executeScript({
|
||||||
|
code: `
|
||||||
|
[...document.querySelectorAll('.alert-success')].some(
|
||||||
|
div =>
|
||||||
|
div.textContent?.includes(${JSON.stringify(lmsSuccessMessage)}) ||
|
||||||
|
div.textContent?.includes(${JSON.stringify(appSuccessMessage)})
|
||||||
|
)
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!Array.isArray(result) || result[0] !== true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
browser.close();
|
||||||
|
CoreDomUtils.showAlert(undefined, appSuccessMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
CoreEvents.once(CoreEvents.IAB_EXIT, () => subscription.unsubscribe());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CoreUserSupport = makeSingleton(CoreUserSupportService);
|
export const CoreUserSupport = makeSingleton(CoreUserSupportService);
|
||||||
|
|
|
@ -119,6 +119,33 @@ export class CoreLangProvider {
|
||||||
return value.charAt(0).toUpperCase() + value.slice(1);
|
return value.charAt(0).toUpperCase() + value.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get message for the given language.
|
||||||
|
*
|
||||||
|
* @param key Message key.
|
||||||
|
* @param lang Language.
|
||||||
|
* @returns Message if found, null otherwise.
|
||||||
|
*/
|
||||||
|
async getMessage(key: string, lang: string): Promise<string | null> {
|
||||||
|
const messages = await this.getMessages(lang);
|
||||||
|
|
||||||
|
return messages[key] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get messages for the given language.
|
||||||
|
*
|
||||||
|
* @param lang Language.
|
||||||
|
* @returns Messages.
|
||||||
|
*/
|
||||||
|
getMessages(lang: string): Promise<Record<string, string>> {
|
||||||
|
return new Promise(resolve => CoreSubscriptions.once(
|
||||||
|
Translate.getTranslation(lang),
|
||||||
|
messages => resolve(messages),
|
||||||
|
() => resolve({}),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the parent language defined on the language strings.
|
* Get the parent language defined on the language strings.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue