/**
* 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>
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',
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') {
}
};
- 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);
}
* 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)));
}
/**