MDL-78324 bbb: Switch to SaveCancelPromise

This change removes an unnecessarily complicated Modal instantiation
when an existing helper exists to simplify this approach.
This commit is contained in:
Andrew Nicols 2023-08-15 15:44:05 +08:00
parent a797020524
commit 96e32d6f90
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
3 changed files with 16 additions and 36 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -22,12 +22,10 @@
*/
import * as repository from './repository';
import {exception as displayException} from 'core/notification';
import {exception as displayException, saveCancelPromise} from 'core/notification';
import {prefetchStrings} from 'core/prefetch';
import {getString, getStrings} from 'core/str';
import {addIconToContainerWithPromise} from 'core/loadingicon';
import ModalFactory from 'core/modal_factory';
import ModalEvents from 'core/modal_events';
import Pending from 'core/pending';
const stringsWithKeys = {
@ -53,9 +51,12 @@ const getStringsForYui = () => {
// Return an object with the matching string keys (we want an object with {<stringkey>: <stringvalue>...}).
return getStrings(stringMap)
.then((stringArray) => Object.assign({}, ...Object.keys(stringsWithKeys).map(
(key, index) => ({[key]: stringArray[index]})))
).catch();
.then((stringArray) => Object.assign(
{},
...Object.keys(stringsWithKeys).map(
(key, index) => ({[key]: stringArray[index]})
)
));
};
const getYuiInstance = lang => new Promise(resolve => {
@ -205,33 +206,12 @@ const getDataTableFunctions = (tableId, searchFormId, dataTable) => {
payload.additionaloptions = JSON.stringify(payload.additionaloptions);
if (element.dataset.requireConfirmation === "1") {
// Create the confirmation dialogue.
return new Promise((resolve) =>
ModalFactory.create({
title: getString('confirm'),
body: recordingConfirmationMessage(payload),
type: ModalFactory.types.SAVE_CANCEL
}).then(async(modal) => {
modal.setSaveButtonText(await getString('ok', 'moodle'));
// Handle save event.
modal.getRoot().on(ModalEvents.save, () => {
resolve(true);
});
// Handle hidden event.
modal.getRoot().on(ModalEvents.hidden, () => {
// Destroy when hidden.
modal.destroy();
resolve(false);
});
modal.show();
return modal;
}).catch(displayException)
).then((proceed) =>
proceed ? repository.updateRecording(payload) : () => null
);
return saveCancelPromise(
getString('confirm'),
recordingConfirmationMessage(payload),
getString('ok', 'moodle'),
)
.then(() => repository.updateRecording(payload));
} else {
return repository.updateRecording(payload);
}