From 4b600ba8f7806b634cb6a0596e69839f5009f765 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 6 Jul 2010 21:44:37 -0600 Subject: [PATCH] Allow IMPDialog to handle simple Yes/No dialogs Add a bit of IMPDialog documentation --- imp/js/dialog.js | 46 +++++++++++++++++++++++++++++++++++++--------- imp/js/mailbox.js | 31 ++++++++++++++++++++++--------- imp/mailbox.php | 1 + 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/imp/js/dialog.js b/imp/js/dialog.js index de588a403..9f1ef7900 100644 --- a/imp/js/dialog.js +++ b/imp/js/dialog.js @@ -1,6 +1,22 @@ /** * 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 @@ -16,6 +32,7 @@ var IMPDialog = { 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 { @@ -30,17 +47,19 @@ var IMPDialog = { _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 })); } @@ -63,15 +82,24 @@ var IMPDialog = { { 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) @@ -81,7 +109,7 @@ var IMPDialog = { 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(); } diff --git a/imp/js/mailbox.js b/imp/js/mailbox.js index 2a533b6b7..b01ca5f04 100644 --- a/imp/js/mailbox.js +++ b/imp/js/mailbox.js @@ -22,13 +22,6 @@ var ImpMailbox = { id.down('INPUT.checkbox').setValue(select); }, - confirmDialog: function(url, msg) - { - RedBox.overlay = true; - RedBox.showHtml('

' + msg + '

' + - '
'); - }, - submit: function(actID) { if (!this.anySelected()) { @@ -263,12 +256,26 @@ var ImpMailbox = { 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; } @@ -370,3 +377,9 @@ document.observe('dom:loaded', function() { } catch (e) {} } }); + +document.observe('IMPDialog:onClick', function(e) { + if (e.element().identify() == 'RB_ImpMailbox') { + window.location = this.lastclick; + } +}.bindAsEventListener(ImpMailbox)); diff --git a/imp/mailbox.php b/imp/mailbox.php index 21b91ec3b..c5e40fc70 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -344,6 +344,7 @@ if ($vfolder || $pagetitle = $title = htmlspecialchars($title); } +Horde::addScriptFile('dialog.js', 'imp'); Horde::addScriptFile('effects.js', 'horde'); Horde::addScriptFile('redbox.js', 'horde'); Horde::addScriptFile('mailbox.js', 'imp'); -- 2.11.0