mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-19797 Added callback support to the confirm_dialog function, and to the add_confirm_action() method
This commit is contained in:
parent
eef00ade8f
commit
5529f787bd
2 changed files with 23 additions and 8 deletions
|
@ -208,7 +208,7 @@ function lockoptionsallsetup(formid) {
|
|||
/**
|
||||
* Helper function mainly for drop-down menus' onchange events,
|
||||
* submits the form designated by args.id. If args.selectid is also
|
||||
* given, it only submits the form if the selected <option> is not
|
||||
* given, it only submits the form if the selected <option> is not
|
||||
* the first one (usually the "Choose..." option)
|
||||
* Example usage of the html_select component with this function:
|
||||
* <pre>
|
||||
|
@ -1215,6 +1215,7 @@ function init_help_icons() {
|
|||
function confirm_dialog(event, args) {
|
||||
var message = args.message;
|
||||
var target = this;
|
||||
target.args = args;
|
||||
YAHOO.util.Event.preventDefault(event);
|
||||
|
||||
var simpledialog = new YAHOO.widget.SimpleDialog('confirmdialog',
|
||||
|
@ -1230,13 +1231,19 @@ function confirm_dialog(event, args) {
|
|||
simpledialog.setBody(message);
|
||||
simpledialog.cfg.setProperty('icon', YAHOO.widget.SimpleDialog.ICON_WARN);
|
||||
|
||||
var handle_cancel = function() {
|
||||
this.handle_cancel = function() {
|
||||
this.hide();
|
||||
};
|
||||
|
||||
var handle_yes = function() {
|
||||
this.handle_yes = function() {
|
||||
this.hide();
|
||||
|
||||
|
||||
if (target.args.callback) {
|
||||
// args comes from PHP, so callback will be a string, needs to be evaluated by JS
|
||||
var callback = eval('('+target.args.callback+')');
|
||||
callback.apply(this);
|
||||
}
|
||||
|
||||
if (target.tagName.toLowerCase() == 'a') {
|
||||
window.location = target.href;
|
||||
} else if (target.tagName.toLowerCase() == 'input') {
|
||||
|
@ -1252,11 +1259,17 @@ function confirm_dialog(event, args) {
|
|||
}
|
||||
};
|
||||
|
||||
var buttons = [ { text: mstr.moodle.cancel, handler: handle_cancel, isDefault: true },
|
||||
{ text: mstr.moodle.yes, handler: handle_yes } ];
|
||||
var buttons = [ { text: mstr.moodle.cancel, handler: this.handle_cancel, isDefault: true },
|
||||
{ text: mstr.moodle.yes, handler: this.handle_yes } ];
|
||||
|
||||
simpledialog.cfg.queueProperty('buttons', buttons);
|
||||
|
||||
simpledialog.render(document.body);
|
||||
simpledialog.show();
|
||||
return simpledialog;
|
||||
}
|
||||
|
||||
function dialog_callback() {
|
||||
console.debug(this);
|
||||
console.debug(this.args);
|
||||
}
|
||||
|
|
|
@ -193,10 +193,12 @@ class moodle_html_component {
|
|||
* Shortcut for adding a JS confirm dialog when the component is clicked.
|
||||
* The message must be a yes/no question.
|
||||
* @param string $message The yes/no confirmation question. If "Yes" is clicked, the original action will occur.
|
||||
* @param string $callback The name of a JS function whose scope will be set to the simpleDialog object and have this
|
||||
* function's arguments set as this.args.
|
||||
* @return void
|
||||
*/
|
||||
public function add_confirm_action($message) {
|
||||
$this->add_action(new component_action('click', 'confirm_dialog', array('message' => $message)));
|
||||
public function add_confirm_action($message, $callback=null) {
|
||||
$this->add_action(new component_action('click', 'confirm_dialog', array('message' => $message, 'callback' => $callback)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue