MDL-43538 Javascript: Deprecate callback argument to confirm_action

As a precursor to deprecating M.util.show_confirm, this deprecates the
callback argment to the confirm_action class.

This is not currently used anywhere in core, and it's use leads to use of
eval in Javascript.
This commit is contained in:
Andrew Nicols 2014-01-02 14:58:31 +08:00
parent 9788e26805
commit 1d98ca14eb
3 changed files with 14 additions and 5 deletions

View File

@ -256,12 +256,12 @@ M.util.show_confirm_dialog = function(e, args) {
simpledialog.hide();
if (args.callback) {
// args comes from PHP, so callback will be a string, needs to be evaluated by JS
var callback = null;
if (Y.Lang.isFunction(args.callback)) {
callback = args.callback;
} else {
callback = eval('('+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');
}
if (Y.Lang.isObject(args.scope)) {

View File

@ -93,13 +93,19 @@ class confirm_action extends component_action {
*
* @param string $message The message to display to the user when they are shown
* the confirm dialogue.
* @param string $callback The method to call when the user confirms the action.
* @param string $callback Deprecated since 2.7
* @param string $continuelabel The string to use for he continue button
* @param string $cancellabel The string to use for the cancel button
*/
public function __construct($message, $callback = null, $continuelabel = null, $cancellabel = null) {
if ($callback !== null) {
debugging('The callback argument to new confirm_action() has been deprecated.' .
' If you need to use a callback, please write Javascript to use moodle-core-notification-confirmation ' .
'and attach to the provided events.',
DEBUG_DEVELOPER);
}
parent::__construct('click', 'M.util.show_confirm_dialog', array(
'message' => $message, 'callback' => $callback,
'message' => $message,
'continuelabel' => $continuelabel, 'cancellabel' => $cancellabel));
}
}
@ -197,4 +203,4 @@ class popup_action extends component_action {
return $jsoptions;
}
}
}

View File

@ -26,6 +26,9 @@ YUI:
JavaSript:
* The findChildNodes global function has been deprecated. Y.all should
be used instead.
* The callback argument to confirm_action and M.util.show_confirm_dialog has been deprecated. If you need to write a
confirmation which includes a callback, please use moodle-core-notification-confirmation and attach callbacks to the
events provided.
=== 2.6 ===