From: Michael M Slusarz Date: Wed, 16 Dec 2009 20:04:54 +0000 (-0700) Subject: Use custom events to trigger successful dialog actions X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=72cae93e16f4b247017c9c05428cd458d77958de;p=horde.git Use custom events to trigger successful dialog actions --- diff --git a/imp/compose.php b/imp/compose.php index 9b0f9f510..7e07d7be5 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -688,16 +688,16 @@ if ($get_sig && isset($msg) && !empty($sig)) { if ($pgp_passphrase_dialog || $pgp_symmetric_passphrase_dialog) { if ($pgp_passphrase_dialog) { Horde::addInlineScript(array( - IMP::passphraseDialogJS('PGPPersonal', 'ImpCompose.uniqSubmit(\'send_message\')') + IMP::passphraseDialogJS('PGPPersonal') ), 'dom'); } else { Horde::addInlineScript(array( - IMP::passphraseDialogJS('PGPSymmetric', 'ImpCompose.uniqSubmit(\'send_message\')', array('symmetricid' => 'imp_compose_' . $composeCacheID)) + IMP::passphraseDialogJS('PGPSymmetric', array('symmetricid' => 'imp_compose_' . $composeCacheID)) ), 'dom'); } } elseif ($smime_passphrase_dialog) { Horde::addInlineScript(array( - IMP::passphraseDialogJS('SMIMEPersonal', 'ImpCompose.uniqSubmit(\'send_message\')') + IMP::passphraseDialogJS('SMIMEPersonal') ), 'dom'); } diff --git a/imp/js/DimpCore.js b/imp/js/DimpCore.js index 5a8a3bfab..1973c9322 100644 --- a/imp/js/DimpCore.js +++ b/imp/js/DimpCore.js @@ -504,6 +504,18 @@ var DimpCore = { /* Add click handler. */ document.observe('click', DimpCore.clickHandler.bindAsEventListener(DimpCore)); + /* Catch dialog actions. */ + document.observe('IMPDialog:success', function(e) { + switch (e.memo) { + case 'PGPPersonal': + case 'PGPSymmetric': + case 'SMIMEPersonal': + IMPDialog.noreload = true; + this.reloadMessage({}); + break; + } + }.bindAsEventListener(this)); + /* Determine base window. Need a try/catch block here since, if the * page was loaded by an opener out of this current domain, this will * throw an exception. */ diff --git a/imp/js/compose.js b/imp/js/compose.js index 3b4783558..312c25e67 100644 --- a/imp/js/compose.js +++ b/imp/js/compose.js @@ -447,3 +447,15 @@ document.observe('dom:loaded', ImpCompose.onDomLoad.bind(ImpCompose)); /* Warn before closing the window. */ Event.observe(window, 'beforeunload', ImpCompose.onBeforeUnload.bind(ImpCompose)); + +/* Catch dialog actions. */ +document.observe('IMPDialog:success', function(e) { + switch (e.memo) { + case 'PGPPersonal': + case 'PGPSymmetric': + case 'SMIMEPersonal': + IMPDialog.noreload = true; + ImpCompose.uniqSubmit('send_message'); + break; + } +}); diff --git a/imp/js/dialog.js b/imp/js/dialog.js index bbf5c80ed..5b9ebbc50 100644 --- a/imp/js/dialog.js +++ b/imp/js/dialog.js @@ -13,6 +13,8 @@ var IMPDialog = { display: function(data) { + this.noreload = false; + if (Object.isString(data)) { data = decodeURIComponent(data).evalJSON(true); } @@ -30,8 +32,8 @@ var IMPDialog = { _display: function(data) { - this.action = data.action; this.params = data.params; + this.type = data.type; this.uri = data.uri; var n = new Element('FORM', { action: '#', id: 'RB_confirm' }).insert( @@ -80,13 +82,8 @@ var IMPDialog = { if (r.response.success) { this._close(); - if (this.action) { - if (Object.isFunction(this.action)) { - this.action(); - } else { - eval(this.action)(); - } - } else { + document.fire('IMPDialog:success', this.type); + if (!this.noreload) { location.reload(); } } else if (r.response.error) { diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index edbb19eda..dc8447885 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -1111,15 +1111,12 @@ class IMP * Generate the JS code necessary to open a passphrase dialog. Adds the * necessary JS files to open the dialog. * - * @param string $type The dialog type. - * @param string $action The JS code to run after success. Defaults to - * reloading the current window. - * @param array $params Any additional parameters to pass. + * @param string $type The dialog type. + * @param array $params Any additional parameters to pass. * * @return string The generated JS code. */ - static public function passphraseDialogJS($type, $action = null, - $params = array()) + static public function passphraseDialogJS($type, $params = array()) { Horde::addScriptFile('effects.js', 'horde'); Horde::addScriptFile('redbox.js', 'horde'); @@ -1145,13 +1142,13 @@ class IMP } $js_params = array( - 'action' => $action, - 'uri' => Horde::applicationUrl('ajax.php', true, -1) . '/' . $type, + 'cancel_text' => _("Cancel"), + 'ok_text' => _("OK"), 'params' => $params, - 'text' => $text, 'password' => true, - 'ok_text' => _("OK"), - 'cancel_text' => _("Cancel") + 'text' => $text, + 'type' => $type, + 'uri' => Horde::applicationUrl('ajax.php', true, -1) . '/' . $type ); return 'IMPDialog.display(' . Horde::escapeJson($js_params, array('urlencode' => true)) . ')'; diff --git a/imp/lib/Mime/Viewer/Pgp.php b/imp/lib/Mime/Viewer/Pgp.php index c5b8581b0..58c7c8190 100644 --- a/imp/lib/Mime/Viewer/Pgp.php +++ b/imp/lib/Mime/Viewer/Pgp.php @@ -209,20 +209,12 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Driver $symmetric_pass = $this->_imppgp->getPassphrase('symmetric', $symmetric_id); if (is_null($symmetric_pass)) { - $js_action = ''; $status[] = _("The data in this part has been encrypted via PGP."); - switch ($_SESSION['imp']['view']) { - case 'dimp': - $js_action = 'DimpCore.reloadMessage({});'; - // Fall through + /* Ask for the correct passphrase if this is encrypted + * symmetrically. */ + $status[] = Horde::link('#', '', '', '', IMP::passphraseDialogJS('PGPSymmetric', array('symmetricid' => $symmetric_id)) . ';return false;') . _("You must enter the passphrase used to encrypt this message to view it.") . ''; - case 'imp': - /* Ask for the correct passphrase if this is encrypted - * symmetrically. */ - $status[] = Horde::link('#', '', '', '', IMP::passphraseDialogJS('PGPSymmetric', $js_action, array('symmetricid' => $symmetric_id)) . ';return false;') . _("You must enter the passphrase used to encrypt this message to view it.") . ''; - break; - } return null; } } @@ -249,19 +241,9 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Driver if ($this->_imppgp->getPersonalPrivateKey()) { $personal_pass = $this->_imppgp->getPassphrase('personal'); if (is_null($personal_pass)) { - $js_action = ''; - - switch ($_SESSION['imp']['view']) { - case 'dimp': - $js_action = 'DimpCore.reloadMessage({});'; - // Fall through - - case 'imp': - /* Ask for the private key's passphrase if this is - * encrypted asymmetrically. */ - $status[] = Horde::link('#', '', '', '', IMP::passphraseDialogJS('PGPPersonal', $js_action) . ';return false;') . _("You must enter the passphrase for your PGP private key to view this message.") . ''; - break; - } + /* Ask for the private key's passphrase if this is + * encrypted asymmetrically. */ + $status[] = Horde::link('#', '', '', '', IMP::passphraseDialogJS('PGPPersonal') . ';return false;') . _("You must enter the passphrase for your PGP private key to view this message.") . ''; return null; } } else { diff --git a/imp/lib/Mime/Viewer/Smime.php b/imp/lib/Mime/Viewer/Smime.php index 21ef7c285..771233feb 100644 --- a/imp/lib/Mime/Viewer/Smime.php +++ b/imp/lib/Mime/Viewer/Smime.php @@ -182,17 +182,7 @@ class IMP_Horde_Mime_Viewer_Smime extends Horde_Mime_Viewer_Driver /* Make sure we have a passphrase. */ $passphrase = $this->_impsmime->getPassphrase(); if (is_null($passphrase)) { - $js_action = ''; - - switch ($_SESSION['imp']['view']) { - case 'dimp': - $js_action = 'DimpCore.reloadMessage({});'; - // Fall through - - case 'imp': - $status[] = Horde::link('#', '', '', '', IMP::passphraseDialogJS('SMIMEPersonal', $js_action) . ';return false;') . _("You must enter the passphrase for your S/MIME private key to view this data.") . ''; - break; - } + $status[] = Horde::link('#', '', '', '', IMP::passphraseDialogJS('SMIMEPersonal') . ';return false;') . _("You must enter the passphrase for your S/MIME private key to view this data.") . ''; return null; }