MDL-69918 core: Update uses of legacy form change checker
This commit is contained in:
+71
-71
@@ -242,84 +242,84 @@ M.util.show_confirm_dialog = function(e, args) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
YUI().use('moodle-core-notification-confirm', function(Y) {
|
||||
var confirmationDialogue = new M.core.confirm({
|
||||
width: '300px',
|
||||
center: true,
|
||||
modal: true,
|
||||
visible: false,
|
||||
draggable: false,
|
||||
title: M.util.get_string('confirmation', 'admin'),
|
||||
noLabel: M.util.get_string('cancel', 'moodle'),
|
||||
question: args.message
|
||||
});
|
||||
require(['core_form/changechecker'], function(FormChangeChecker) {
|
||||
// eslint-disable-next-line no-undef, new-cap
|
||||
YUI().use('moodle-core-notification-confirm', function(Y) {
|
||||
var confirmationDialogue = new M.core.confirm({
|
||||
width: '300px',
|
||||
center: true,
|
||||
modal: true,
|
||||
visible: false,
|
||||
draggable: false,
|
||||
title: M.util.get_string('confirmation', 'admin'),
|
||||
noLabel: M.util.get_string('cancel', 'moodle'),
|
||||
question: args.message
|
||||
});
|
||||
|
||||
// The dialogue was submitted with a positive value indication.
|
||||
confirmationDialogue.on('complete-yes', function(e) {
|
||||
// Handle any callbacks.
|
||||
if (args.callback) {
|
||||
if (!Y.Lang.isFunction(args.callback)) {
|
||||
Y.log('Callbacks to show_confirm_dialog must now be functions. Please update your code to pass in a function instead.',
|
||||
'warn', 'M.util.show_confirm_dialog');
|
||||
return;
|
||||
}
|
||||
|
||||
var scope = e.target;
|
||||
if (Y.Lang.isObject(args.scope)) {
|
||||
scope = args.scope;
|
||||
}
|
||||
|
||||
var callbackargs = args.callbackargs || [];
|
||||
args.callback.apply(scope, callbackargs);
|
||||
return;
|
||||
}
|
||||
|
||||
var targetancestor = null,
|
||||
targetform = null;
|
||||
|
||||
if (target.test('a')) {
|
||||
window.location = target.get('href');
|
||||
|
||||
} else if ((targetancestor = target.ancestor('a')) !== null) {
|
||||
window.location = targetancestor.get('href');
|
||||
|
||||
} else if (target.test('input') || target.test('button')) {
|
||||
targetform = target.ancestor('form', true);
|
||||
if (!targetform) {
|
||||
return;
|
||||
}
|
||||
if (target.get('name') && target.get('value')) {
|
||||
targetform.append('<input type="hidden" name="' + target.get('name') +
|
||||
'" value="' + target.get('value') + '">');
|
||||
if (typeof M.core_formchangechecker !== 'undefined') {
|
||||
M.core_formchangechecker.set_form_submitted();
|
||||
// The dialogue was submitted with a positive value indication.
|
||||
confirmationDialogue.on('complete-yes', function(e) {
|
||||
// Handle any callbacks.
|
||||
if (args.callback) {
|
||||
if (!Y.Lang.isFunction(args.callback)) {
|
||||
Y.log('Callbacks to show_confirm_dialog must now be functions. ' +
|
||||
'Please update your code to pass in a function instead.',
|
||||
'warn', 'M.util.show_confirm_dialog');
|
||||
return;
|
||||
}
|
||||
}
|
||||
targetform.submit();
|
||||
|
||||
} else if (target.test('form')) {
|
||||
if (typeof M.core_formchangechecker !== 'undefined') {
|
||||
M.core_formchangechecker.set_form_submitted();
|
||||
}
|
||||
target.submit();
|
||||
var scope = e.target;
|
||||
if (Y.Lang.isObject(args.scope)) {
|
||||
scope = args.scope;
|
||||
}
|
||||
|
||||
} else {
|
||||
Y.log("Element of type " + target.get('tagName') +
|
||||
" is not supported by the M.util.show_confirm_dialog function. Use A, INPUT, BUTTON or FORM",
|
||||
'warn', 'javascript-static');
|
||||
var callbackargs = args.callbackargs || [];
|
||||
args.callback.apply(scope, callbackargs);
|
||||
return;
|
||||
}
|
||||
|
||||
var targetancestor = null,
|
||||
targetform = null;
|
||||
|
||||
if (target.test('a')) {
|
||||
window.location = target.get('href');
|
||||
|
||||
} else if ((targetancestor = target.ancestor('a')) !== null) {
|
||||
window.location = targetancestor.get('href');
|
||||
|
||||
} else if (target.test('input') || target.test('button')) {
|
||||
targetform = target.ancestor('form', true);
|
||||
if (!targetform) {
|
||||
return;
|
||||
}
|
||||
if (target.get('name') && target.get('value')) {
|
||||
targetform.append('<input type="hidden" name="' + target.get('name') +
|
||||
'" value="' + target.get('value') + '">');
|
||||
FormChangeChecker.markFormAsDirty(targetform);
|
||||
}
|
||||
targetform.submit();
|
||||
|
||||
} else if (target.test('form')) {
|
||||
FormChangeChecker.markFormAsDirty(target);
|
||||
target.submit();
|
||||
|
||||
} else {
|
||||
Y.log("Element of type " + target.get('tagName') +
|
||||
" is not supported by the M.util.show_confirm_dialog function. Use A, INPUT, BUTTON or FORM",
|
||||
'warn', 'javascript-static');
|
||||
}
|
||||
}, this);
|
||||
|
||||
if (args.cancellabel) {
|
||||
confirmationDialogue.set('noLabel', args.cancellabel);
|
||||
}
|
||||
}, this);
|
||||
|
||||
if (args.cancellabel) {
|
||||
confirmationDialogue.set('noLabel', args.cancellabel);
|
||||
}
|
||||
if (args.continuelabel) {
|
||||
confirmationDialogue.set('yesLabel', args.continuelabel);
|
||||
}
|
||||
|
||||
if (args.continuelabel) {
|
||||
confirmationDialogue.set('yesLabel', args.continuelabel);
|
||||
}
|
||||
|
||||
confirmationDialogue.render()
|
||||
.show();
|
||||
confirmationDialogue.render()
|
||||
.show();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user