Move popup generation to horde
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 31 Jul 2009 17:45:12 +0000 (11:45 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 31 Jul 2009 21:02:11 +0000 (15:02 -0600)
imp/js/src/imp.js
imp/lib/Contents.php
imp/lib/Crypt/Pgp.php
imp/lib/Crypt/Smime.php
imp/lib/IMP.php
imp/mailbox.php
imp/pgp.php
imp/smime.php
imp/templates/javascript_defs_dimp.php
imp/templates/pgp/pgp.html
imp/templates/smime/smime.html

index baf06cd..c2dd05e 100644 (file)
@@ -19,51 +19,6 @@ IMP.menuFolderSubmit = function(clear)
 };
 
 /**
- * Open a popup window.
- *
- * @param string $url      The URL to open in the popup window.
- * @param integer $width   The width of the popup window. (Default: 600 px)
- * @param integer $height  The height of the popup window. (Default: 500 px)
- * @param string $args     Any additional args to pass to the script.
- *                         (Default: no args)
- */
-IMP.popup = function(url, width, height, args)
-{
-    var q, win,
-        params = $H(),
-        name = new Date().getTime();
-
-    height = Math.min(screen.height - 75, height || 500);
-    width = Math.min(screen.width - 75, width || 600);
-
-    q = url.indexOf('?');
-    if (q != -1) {
-        params = $H(url.toQueryParams());
-        url = url.substring(0, q);
-    }
-
-    if (args) {
-        $H(args.toQueryParams()).each(function(a) {
-            params.set(a.key, unescape(a.value));
-        });
-    }
-    params.set('uniq', name);
-
-    win = window.open(url + '?' + params.toQueryString(), name, 'toolbar=no,location=no,status=yes,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',left=0,top=0');
-    if (!win) {
-        alert(IMP.text.popup_block);
-    } else {
-        if (Object.isUndefined(win.name)) {
-            win.name = name;
-        }
-        if (Object.isUndefined(win.opener)) {
-            win.opener = self;
-        }
-        win.focus();
-    }
-};
-
-/**
  * Use DOM manipulation to un-block images.
  */
 IMP.unblockImages = function(e)
index c499771..907f4ad 100644 (file)
@@ -642,7 +642,7 @@ class IMP_Contents
         if (($mask && self::SUMMARY_IMAGE_SAVE) &&
             $GLOBALS['registry']->hasMethod('images/selectGalleries') &&
             ($mime_part->getPrimaryType() == 'image')) {
-            $part['img_save'] = Horde::link('#', _("Save Image in Gallery"), 'saveImgAtc', null, IMP::popupIMPString('saveimage.php', array('index' => ($this->_index . IMP::IDX_SEP . $this->_mailbox), 'id' => $id), 450, 200) . "return false;") . '</a>';
+            $part['img_save'] = Horde::link('#', _("Save Image in Gallery"), 'saveImgAtc', null, Horde::popupJs(Horde::applicationUrl('saveimage.php'), array('params' => array('index' => ($this->_index . IMP::IDX_SEP . $this->_mailbox), 'id' => $id), 'height' => 200, 'width' => 450)) . 'return false;') . '</a>';
         }
 
         /* Strip Attachment? Allow stripping of base parts other than the
@@ -764,7 +764,7 @@ class IMP_Contents
             $options['jstext'] = sprintf(_("View %s"), $mime_part->getDescription(true));
         }
 
-        $url = IMP::popupIMPString('view.php', $this->_urlViewParams($mime_part, $actionID, isset($options['params']) ? $options['params'] : array())) . 'return false;';
+        $url = Horde::popupJs(Horde::applicationUrl('view.php'), array('params' => $this->_urlViewParams($mime_part, $actionID, isset($options['params']) ? $options['params'] : array()))) . 'return false;';
 
         return empty($options['widget'])
             ? Horde::link('#', $options['jstext'], empty($options['css']) ? null : $options['css'], null, $url) . $text . '</a>'
index ccaaf58..9f56948 100644 (file)
@@ -470,7 +470,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp
             'uid' => $uid,
             'mime_id' => $id
         );
-        return IMP::popupIMPString('pgp.php', $params, 450, 200);
+        return Horde::popupJs(Horde::applicationUrl('pgp.php'), array('params' => $params, 'height' => 200, 'width' => 450));
     }
 
     /**
index 736d4cf..fea83d9 100644 (file)
@@ -329,7 +329,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime
             'uid' => $uid,
             'mime_id' => $id
         );
-        return IMP::popupIMPString('smime.php', $params, 450, 200);
+        return Horde::popupJs(Horde::applicationUrl('smime.php'), array('params' => $params, 'height' => 200, 'width' => 450));
     }
 
     /**
index 65fb7c7..4705ad9 100644 (file)
@@ -405,11 +405,10 @@ class IMP
         if (($view != 'mimp') &&
             $GLOBALS['prefs']->getValue('compose_popup') &&
             $GLOBALS['browser']->hasFeature('javascript')) {
-            Horde::addScriptFile('imp.js', 'imp', true);
             if (isset($args['to'])) {
                 $args['to'] = addcslashes($args['to'], '\\"');
             }
-            return "javascript:" . self::popupIMPString('compose.php', $args);
+            return "javascript:" . Horde::popupJs(Horde::applicationUrl('compose.php'), array('params' => $args, 'urlencode' => true));
         }
 
         return Horde_Util::addParameter(Horde::applicationUrl(($view == 'mimp') ? 'compose-mimp.php' : 'compose.php'), $args);
@@ -1187,22 +1186,6 @@ class IMP
     }
 
     /**
-     * Output the javascript needed to call the IMP popup JS function.
-     *
-     * @param string $url      The IMP page to load.
-     * @param array $params    An array of paramters to pass to the URL.
-     * @param integer $width   The width of the popup window.
-     * @param integer $height  The height of the popup window.
-     *
-     * @return string  The javascript needed to call the popup code.
-     */
-    static public function popupIMPString($url, $params = array(),
-                                          $width = 700, $height = 650)
-    {
-        return "IMP.popup('" . Horde::applicationUrl($url) . "'," . $width . "," . $height . ",'" . $GLOBALS['browser']->escapeJSCode(str_replace('+', '%20', substr(Horde_Util::addParameter('', $params, null, false), 1))) . "');";
-    }
-
-    /**
      * Returns a Horde_Cache object (if configured) and handles any errors
      * associated with creating the object.
      *
index 70c28b1..c18f29f 100644 (file)
@@ -395,8 +395,7 @@ if ($open_compose_window === false) {
     if (!isset($options)) {
         $options = array();
     }
-    Horde::addScriptFile('imp.js', 'imp', true);
-    $notification->push(IMP::popupIMPString('compose.php', array_merge(array('popup' => 1), $options, IMP::getComposeArgs())), 'javascript');
+    Horde::addInlineScript(Horde::popupJs(Horde::applicationUrl('compose.php'), array('params' => array_merge(array('popup' => 1), $options, IMP::getComposeArgs()))), 'dom');
 }
 
 if (!empty($newmsgs)) {
@@ -411,7 +410,7 @@ if (!empty($newmsgs)) {
         }
         /* Newmail alert. */
         if ($prefs->getValue('nav_popup')) {
-            $notification->push(IMP::getNewMessagePopup($newmsgs), 'javascript');
+            Horde::addInlineScript(IMP::getNewMessagePopup($newmsgs), 'dom');
         }
     }
 }
index 1c19a81..664ba6b 100644 (file)
@@ -346,7 +346,7 @@ if ($prefs->getValue('use_pgp')) {
         $t->set('no_source', !$GLOBALS['prefs']->getValue('add_source'));
         if (!$t->get('no_source')) {
             $cacheSess = Horde_SessionObjects::singleton();
-            $t->set('public_import_url', Horde_Util::addParameter(Horde_Util::addParameter($selfURL, 'actionID', 'import_public_key'), 'reload', $cacheSess->storeOid($selfURL, false)));
+            $t->set('public_import_url', Horde::popupJs($selfURL, array('params' => array('actionID' => 'import_public_key', 'reload' => $cacheSess->storeOid($selfURL, false)), 'height' => 275, 'width' => 750, 'urlencode' => true)));
             $t->set('import_pubkey-help', Horde_Help::link('imp', 'pgp-import-pubkey'));
         }
     }
@@ -377,7 +377,7 @@ if ($prefs->getValue('use_pgp')) {
             $t->set('personalkey-create-keylength-help', Horde_Help::link('imp', 'pgp-personalkey-create-keylength'));
             $t->set('personalkey-create-passphrase-help', Horde_Help::link('imp', 'pgp-personalkey-create-passphrase'));
             $t->set('keygen', addslashes(_("Key generation may take a long time to complete.  Continue with key generation?")));
-            $t->set('personal_import_url', Horde_Util::addParameter($selfURL, 'actionID', 'import_personal_public_key'));
+            $t->set('personal_import_url', Horde::popupJs($selfURL, array('params' => array('actionID' => 'import_personal_public_key'), 'height' => 275, 'width' => 750, 'urlencode' => true)));
             $t->set('personalkey-create-actions-help', Horde_Help::link('imp', 'pgp-personalkey-create-actions'));
         }
     }
index c1d8026..5113afd 100644 (file)
@@ -266,7 +266,7 @@ if ($openssl_check && $prefs->getValue('use_smime')) {
         $t->set('no_source', !$GLOBALS['prefs']->getValue('add_source'));
         if (!$t->get('no_source')) {
             $cacheSess = Horde_SessionObjects::singleton();
-            $t->set('public_import_url', Horde_Util::addParameter(Horde_Util::addParameter($selfURL, 'actionID', 'import_public_key'), 'reload', $cacheSess->storeOid($selfURL, false)));
+            $t->set('public_import_url', Horde::popupJs($selfURL, array('params' => array('actionID' => 'import_public_key', 'reload' => $cacheSess->storeOid($selfURL, false)), 'height' => 275, 'width' => 750, 'urlencode' => true)));
             $t->set('import_pubkey-help', Horde_Help::link('imp', 'smime-import-pubkey'));
         }
     }
@@ -284,7 +284,7 @@ if ($openssl_check && $prefs->getValue('use_smime')) {
             $t->set('deletekeypair', addslashes(_("Are you sure you want to delete your keypair? (This is NOT recommended!)")));
             $t->set('personalkey-delete-help', Horde_Help::link('imp', 'smime-delete-personal-certs'));
         } else {
-            $t->set('personal_import_url', Horde_Util::addParameter($selfURL, 'actionID', 'import_personal_certs'));
+            $t->set('personal_import_url', Horde::popupJs($selfURL, array('params' => array('actionID' => 'import_personal_certs'), 'height' => 275, 'width' => 750, 'urlencode' => true)));
             $t->set('import-cert-help', Horde_Help::link('imp', 'smime-import-personal-certs'));
         }
     }
index 2627b9b..c281075 100644 (file)
@@ -113,7 +113,6 @@ $code['text'] = array(
     'of' => _("of"),
     'ok' => _("Ok"),
     'onlogout' => _("Logging Out..."),
-    'popup_block' => _("A popup window could not be opened. Your browser may be blocking popups."),
     'portal' => ("Portal"),
     'prefs' => _("User Options"),
     'rename_prompt' => _("Rename folder to:"),
index 6c5ad00..6f0816b 100644 (file)
@@ -49,7 +49,7 @@
 <if:no_source>
  <br /><em><gettext>Key import is not available. You have no address book defined to add your contacts.</gettext></em><br />
 <else:no_source>
- <br /><input type="submit" name="save" class="button" onclick="IMP.popup('<tag:public_import_url />',750,275); return false;" value="<gettext>Import Public Key</gettext>" />
+ <br /><input type="submit" name="save" class="button" onclick="<tag:public_import_url />return false;" value="<gettext>Import Public Key</gettext>" />
  <tag:import_pubkey-help />
 </else:no_source></if:no_source></else:no_file_upload></if:no_file_upload>
 </div>
  <p>
   <input type="submit" name="save" class="button" onclick="if (confirm('<tag:keygen />')) { document.prefs.actionID.value='generate_key';return true; } else { return false; }" value="<gettext>Create Keys</gettext>" />
 <if:no_file_upload><else:no_file_upload>
-  <input type="submit" name="save" class="button" onclick="IMP.popup('<tag:personal_import_url />',750,275);return false;" value="<gettext>Import Keypair</gettext>" />
+  <input type="submit" name="save" class="button" onclick="<tag:personal_import_url />return false;" value="<gettext>Import Keypair</gettext>" />
 </else:no_file_upload></if:no_file_upload>
   <tag:personalkey-create-actions-help />
 </p>
index 61cbaa6..36dd343 100644 (file)
@@ -41,7 +41,7 @@
 <if:no_source>
  <em><gettext>Key import is not available. You have no address book defined to add your contacts.</gettext></em>
 <else:no_source>
- <p><input type="submit" name="save" class="button" onclick="IMP.popup('<tag:public_import_url />',750,275); return false;" value="<gettext>Import Public Key</gettext>" />
+ <p><input type="submit" name="save" class="button" onclick="<tag:public_import_url />return false;" value="<gettext>Import Public Key</gettext>" />
  <tag:import_pubkey-help /></p>
 </else:no_source></if:no_source></else:no_file_upload></if:no_file_upload>
 </div>
@@ -75,7 +75,7 @@
 <if:no_file_upload>
  <em style="color:red"><gettext>Certificate import is not available. File upload is not enabled on this server.</gettext></em>
 <else:no_file_upload>
- <p><input type="submit" name="save" class="button" onclick="IMP.popup('<tag:personal_import_url />',750,275);return false;" value="<gettext>Import Keypair</gettext>" /> <tag:import-cert-help /></p>
+ <p><input type="submit" name="save" class="button" onclick="<tag:personal_import_url />return false;" value="<gettext>Import Keypair</gettext>" /> <tag:import-cert-help /></p>
 </else:no_file_upload></if:no_file_upload>
 </else:has_key></if:has_key></else:secure_check></if:secure_check>
 <else:smimeactive>