mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
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:
parent
a797020524
commit
96e32d6f90
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -22,12 +22,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as repository from './repository';
|
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 {prefetchStrings} from 'core/prefetch';
|
||||||
import {getString, getStrings} from 'core/str';
|
import {getString, getStrings} from 'core/str';
|
||||||
import {addIconToContainerWithPromise} from 'core/loadingicon';
|
import {addIconToContainerWithPromise} from 'core/loadingicon';
|
||||||
import ModalFactory from 'core/modal_factory';
|
|
||||||
import ModalEvents from 'core/modal_events';
|
|
||||||
import Pending from 'core/pending';
|
import Pending from 'core/pending';
|
||||||
|
|
||||||
const stringsWithKeys = {
|
const stringsWithKeys = {
|
||||||
@ -53,9 +51,12 @@ const getStringsForYui = () => {
|
|||||||
|
|
||||||
// Return an object with the matching string keys (we want an object with {<stringkey>: <stringvalue>...}).
|
// Return an object with the matching string keys (we want an object with {<stringkey>: <stringvalue>...}).
|
||||||
return getStrings(stringMap)
|
return getStrings(stringMap)
|
||||||
.then((stringArray) => Object.assign({}, ...Object.keys(stringsWithKeys).map(
|
.then((stringArray) => Object.assign(
|
||||||
(key, index) => ({[key]: stringArray[index]})))
|
{},
|
||||||
).catch();
|
...Object.keys(stringsWithKeys).map(
|
||||||
|
(key, index) => ({[key]: stringArray[index]})
|
||||||
|
)
|
||||||
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
const getYuiInstance = lang => new Promise(resolve => {
|
const getYuiInstance = lang => new Promise(resolve => {
|
||||||
@ -205,33 +206,12 @@ const getDataTableFunctions = (tableId, searchFormId, dataTable) => {
|
|||||||
payload.additionaloptions = JSON.stringify(payload.additionaloptions);
|
payload.additionaloptions = JSON.stringify(payload.additionaloptions);
|
||||||
if (element.dataset.requireConfirmation === "1") {
|
if (element.dataset.requireConfirmation === "1") {
|
||||||
// Create the confirmation dialogue.
|
// Create the confirmation dialogue.
|
||||||
return new Promise((resolve) =>
|
return saveCancelPromise(
|
||||||
ModalFactory.create({
|
getString('confirm'),
|
||||||
title: getString('confirm'),
|
recordingConfirmationMessage(payload),
|
||||||
body: recordingConfirmationMessage(payload),
|
getString('ok', 'moodle'),
|
||||||
type: ModalFactory.types.SAVE_CANCEL
|
)
|
||||||
}).then(async(modal) => {
|
.then(() => repository.updateRecording(payload));
|
||||||
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
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return repository.updateRecording(payload);
|
return repository.updateRecording(payload);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user