/**
* Javascript code used to display a RedBox dialog.
*
+ * Parameters to display():
+ * 'cancel_text' - [REQUIRED] Cancel text.
+ * 'dialog_load' - TODO
+ * 'form' - TODO
+ * 'form_id' - The ID for the form (default: RB_confirm).
+ * 'noinput' - TODO
+ * 'ok_text' - OK text.
+ * 'password' - TODO
+ * 'text' - [REQUIRED] The text to display at top of dialog box.
+ *
+ * If these are set, an AJAX action (to 'uri') will be initiated if the OK
+ * button is pressed.
+ * 'params' - TODO
+ * 'type' - TODO
+ * 'uri' - TODO
+ *
* Copyright 2008-2010 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
if (Object.isString(data)) {
data = decodeURIComponent(data).evalJSON(true);
}
+
if (data.dialog_load) {
new Ajax.Request(data.dialog_load, { onComplete: this._onComplete.bind(this) });
} else {
_display: function(data)
{
- this.params = data.params;
- this.type = data.type;
- this.uri = data.uri;
+ if (data.uri) {
+ this.params = data.params;
+ this.type = data.type;
+ this.uri = data.uri;
+ }
- var n = new Element('FORM', { action: '#', id: 'RB_confirm' }).insert(
+ var n = new Element('FORM', { action: '#', id: data.form_id || 'RB_confirm' }).insert(
new Element('P').insert(data.text)
);
if (data.form) {
n.insert(data.form);
- } else {
+ } else if (!data.noinput) {
n.insert(new Element('INPUT', { name: 'dialog_input', type: data.password ? 'password' : 'text', size: 15 }));
}
{
var c = RedBox.getWindowContents();
[ c, c.descendants()].flatten().compact().invoke('stopObserving');
+ c.fire('IMPDialog:close');
RedBox.close();
},
_onClick: function(e)
{
- var params = $H((!this.params || Object.isArray(this.params)) ? {} : this.params);
- params.update(e.findElement('form').serialize(true));
+ if (this.uri) {
+ var params = $H((!this.params || Object.isArray(this.params)) ? {} : this.params);
+ params.update(e.findElement('form').serialize(true));
- new Ajax.Request(this.uri, { parameters: params, onSuccess: this._onSuccess.bind(this) });
+ new Ajax.Request(this.uri, {
+ onSuccess: this._onSuccess.bind(this),
+ parameters: params
+ });
+ } else {
+ RedBox.getWindowContents().fire('IMPDialog:onClick', e);
+ this._close();
+ }
},
_onSuccess: function(r)
if (r.response.success) {
this._close();
this.noreload = false;
- document.fire('IMPDialog:success', this.type);
+ RedBox.getWindowContents().fire('IMPDialog:success', this.type);
if (!this.noreload) {
location.reload();
}
id.down('INPUT.checkbox').setValue(select);
},
- confirmDialog: function(url, msg)
- {
- RedBox.overlay = true;
- RedBox.showHtml('<div id="RB_confirm"><p>' + msg + '</p><input type="button" class="button" onclick="window.location=\'' + url + '\';" value="' + IMP.text.yes + '" />' +
- '<input type="button" class="button" onclick="RedBox.close();" value="' + IMP.text.no + '" /></div>');
- },
-
submit: function(actID)
{
if (!this.anySelected()) {
return;
case 'delete_vfolder':
- this.confirmDialog(elt.readAttribute('href'), IMP.text.mailbox_delete_vfolder);
+ this.lastclick = elt.readAttribute('href');
+ IMPDialog.display({
+ cancel_text: IMP.text.no,
+ form_id: 'RB_ImpMailbox',
+ noinput: true,
+ ok_text: IMP.text.yes,
+ text: IMP.text.mailbox_delete_vfolder
+ });
e.stop();
return;
case 'empty_mailbox':
- this.confirmDialog(elt.readAttribute('href'), IMP.text.mailbox_delete_all);
+ this.lastclick = elt.readAttribute('href');
+ IMPDialog.display({
+ cancel_text: IMP.text.no,
+ form_id: 'RB_ImpMailbox',
+ noinput: true,
+ ok_text: IMP.text.yes,
+ text: IMP.text.mailbox_delete_all
+ });
e.stop();
return;
}
} catch (e) {}
}
});
+
+document.observe('IMPDialog:onClick', function(e) {
+ if (e.element().identify() == 'RB_ImpMailbox') {
+ window.location = this.lastclick;
+ }
+}.bindAsEventListener(ImpMailbox));