Show account selection only for MAIL task.

Optimize JS scripts.
This commit is contained in:
Boris Gulay
2018-03-17 22:34:45 +03:00
parent c28305509f
commit 8b2798e412
5 changed files with 40 additions and 15 deletions

10
ident_switch-form.js Normal file
View File

@@ -0,0 +1,10 @@
/*
* This is part of identity_imap plugin
*/
$(function() {
$("INPUT[name='_ident_switch.form.enabled']").change();
$("SELECT[name='_ident_switch.form.secure']").change();
plugin_switchIdent_processPreconfig();
});

1
ident_switch-form.min.js vendored Normal file
View File

@@ -0,0 +1 @@
$(function(){$("INPUT[name='_ident_switch.form.enabled']").change();$("SELECT[name='_ident_switch.form.secure']").change();plugin_switchIdent_processPreconfig();});

View File

@@ -1,5 +1,6 @@
$(function(){$sw=$('#plugin-ident_switch-account');isOk=false;switch(rcmail.env['skin']){case'larry':isOk=plugin_switchIdent_addCbLarry($sw);break;case'classic':isOk=plugin_switchIdent_addCbClassic($sw);break;}
if(isOk){$sw.show();$("INPUT[name='_ident_switch.form.enabled']").change();$("SELECT[name='_ident_switch.form.secure']").change();plugin_switchIdent_processPreconfig();}});function plugin_switchIdent_addCbLarry($sw){var $truName=$('.topright .username');if($truName.length>0){if($sw.length>0){$sw.prependTo('.topright');$truName.hide();return true;}}
if(isOk)
$sw.show();$("INPUT[name='_ident_switch.form.enabled']").change();$("SELECT[name='_ident_switch.form.secure']").change();plugin_switchIdent_processPreconfig();});function plugin_switchIdent_addCbLarry($sw){var $truName=$('.topright .username');if($truName.length>0){if($sw.length>0){$sw.prependTo('.topright');$truName.hide();return true;}}
return false;}
function plugin_switchIdent_addCbClassic($sw){var $taskBar=$('#taskbar');if($taskBar.length>0){$taskBar.prepend($sw);return true;}
return false;}

View File

@@ -58,16 +58,31 @@ class ident_switch extends rcube_plugin
{
$rc = rcmail::get_instance();
// Currently selected identity
$iid = $_SESSION['iid' . self::MY_POSTFIX];
switch ($rc->task)
{
case 'mail':
$this->render_switch($rc, $args);
case 'settings':
$this->include_script('ident_switch-form.js');
break;
}
$iid_int = 0;
if (is_int($iid))
$iid_int = $iid;
elseif ($iid === '-1')
$iid_int = -1;
elseif (ctype_digit($iid))
$iid_int = intval($iid);
return $args;
}
private function render_switch($rc, $args)
{
// Currently selected identity
$iid_s = $_SESSION['iid' . self::MY_POSTFIX];
$iid = 0;
if (is_int($iid_s))
$iid = $iid_s;
elseif ($iid_s === '-1')
$iid = -1;
elseif (ctype_digit($iid_s))
$iid = intval($iid_s);
// Get list of alternative accounts
$sOpt = '';
@@ -76,7 +91,7 @@ class ident_switch extends rcube_plugin
while ($r = $rc->db->fetch_assoc($qRec))
{
$opts = array('value' => $r['id']);
if ($iid_int == $r['iid'])
if ($iid == $r['iid'])
$opts['selected'] = 'selected';
// Make label
@@ -110,7 +125,7 @@ class ident_switch extends rcube_plugin
{
// Add main account
$opts = array('value' => -1);
if (!$iid || $iid_int == -1)
if ($iid <= 0)
$opts['selected'] = 'selected';
$sOpt = html::tag(
@@ -119,7 +134,7 @@ class ident_switch extends rcube_plugin
$_SESSION['global_alias'] ? $_SESSION['global_alias'] : $rc->user->data['username']
) . $sOpt;
$this->include_script('ident_switch.js');
$this->include_script('ident_switch-switch.js');
$sw = html::tag(
'select',
array(
@@ -131,8 +146,6 @@ class ident_switch extends rcube_plugin
);
$rc->output->add_footer($sw);
}
return $args;
}
function on_smtp_connect($args)