diff --git a/ident_switch-form.js b/ident_switch-form.js new file mode 100644 index 0000000..874ca60 --- /dev/null +++ b/ident_switch-form.js @@ -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(); +}); + diff --git a/ident_switch-form.min.js b/ident_switch-form.min.js new file mode 100644 index 0000000..5715279 --- /dev/null +++ b/ident_switch-form.min.js @@ -0,0 +1 @@ +$(function(){$("INPUT[name='_ident_switch.form.enabled']").change();$("SELECT[name='_ident_switch.form.secure']").change();plugin_switchIdent_processPreconfig();}); \ No newline at end of file diff --git a/ident_switch.js b/ident_switch-switch.js similarity index 100% rename from ident_switch.js rename to ident_switch-switch.js diff --git a/ident_switch.min.js b/ident_switch-switch.min.js similarity index 82% rename from ident_switch.min.js rename to ident_switch-switch.min.js index 0b9f356..047df9c 100644 --- a/ident_switch.min.js +++ b/ident_switch-switch.min.js @@ -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;} diff --git a/ident_switch.php b/ident_switch.php index cb342bb..02d07d2 100644 --- a/ident_switch.php +++ b/ident_switch.php @@ -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)