6 Commits
1.2 ... 3.1

Author SHA1 Message Date
Boris Gulay
8b2798e412 Show account selection only for MAIL task.
Optimize JS scripts.
2018-03-17 23:03:42 +03:00
Boris Gulay
c28305509f Fix identity form.
Closes #22.
2018-03-17 22:10:00 +03:00
Boris Gulay
8a8bca1ae5 Make identity selection work with classic skin. 2018-03-17 17:47:32 +03:00
Boris Gulay
28d7841af5 Fix description of compatibility for v1.3 branch. 2018-03-17 17:16:18 +03:00
Boris Gulay
707abf2a81 Initial release for Roundcube 1.3.
Fixed compatibility with new jQuery (combobox not displayed). Closes #20.
Pumped up Roundcube version requirement.
2018-03-17 17:09:16 +03:00
Boris Gulay
c90efaa00b Readme updated. 2018-03-12 23:21:38 +03:00
8 changed files with 145 additions and 55 deletions

View File

@@ -9,3 +9,10 @@ This plugin allows users to switch between different accounts (including remote)
* In settigs interface create new identity. * In settigs interface create new identity.
* For all identities except default you will see new section of settings - IMAP. Enter data required to connect to remote server. Don't forget to check Enabled check box. * For all identities except default you will see new section of settings - IMAP. Enter data required to connect to remote server. Don't forget to check Enabled check box.
* After you have created at least one identity with active IMAP settings you will see combobox in the top right corner instead of plain text field with account name. It will allows you to switch to another account. * After you have created at least one identity with active IMAP settings you will see combobox in the top right corner instead of plain text field with account name. It will allows you to switch to another account.
### Version compatibility ###
* Branch 1.X - for Roundcube v1.1
* Branch 2.X - for Roundcube v1.2
* Branch 3.X - for Roundcube v1.3
Please specify verion like "~2.0" in your composer.json file for ident_switch requirement. In this case you will stay inside compatible branch until you manually update ypur Roundcube installation.

View File

@@ -30,7 +30,7 @@
}, },
"extra": { "extra": {
"roundcube": { "roundcube": {
"min-version": "1.1", "min-version": "1.3",
"sql-dir": "SQL" "sql-dir": "SQL"
} }
} }

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

@@ -3,22 +3,50 @@
*/ */
$(function() { $(function() {
var $truName = $('.topright .username'); $sw = $('#plugin-ident_switch-account');
if ($truName.size() > 0) { isOk = false;
$sw = $('#plugin-ident_switch-account');
if ($sw.size() > 0) { switch (rcmail.env['skin']) {
$sw.prependTo('.topright'); case 'larry':
$truName.hide(); isOk = plugin_switchIdent_addCbLarry($sw);
$('#plugin-ident_switch-account').show(); break;
} case 'classic':
isOk = plugin_switchIdent_addCbClassic($sw);
break;
} }
if (isOk)
$sw.show();
$("INPUT[name='_ident_switch.form.enabled']").change(); $("INPUT[name='_ident_switch.form.enabled']").change();
$("SELECT[name='_ident_switch.form.secure']").change(); $("SELECT[name='_ident_switch.form.secure']").change();
plugin_switchIdent_processPreconfig(); 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;
}
function plugin_switchIdent_processPreconfig() { function plugin_switchIdent_processPreconfig() {
var disFld = $("INPUT[name='_ident_switch.form.readonly']"); var disFld = $("INPUT[name='_ident_switch.form.readonly']");
disFld.parentsUntil("TABLE", "TR").hide(); disFld.parentsUntil("TABLE", "TR").hide();

15
ident_switch-switch.min.js vendored Normal file
View File

@@ -0,0 +1,15 @@
$(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;}}
return false;}
function plugin_switchIdent_addCbClassic($sw){var $taskBar=$('#taskbar');if($taskBar.length>0){$taskBar.prepend($sw);return true;}
return false;}
function plugin_switchIdent_processPreconfig(){var disFld=$("INPUT[name='_ident_switch.form.readonly']");disFld.parentsUntil("TABLE","TR").hide();var disVal=disFld.val();if(disVal>0){$("INPUT[name='_ident_switch.form.host']").prop("disabled",true);$("SELECT[name='_ident_switch.form.secure']").prop("disabled",true);$("INPUT[name='_ident_switch.form.port']").prop("disabled",true);}
if(2==disVal){$("INPUT[name='_ident_switch.form.username']").prop("disabled",true);}}
function plugin_switchIdent_enabled_onChange(e){var $enFld=$("INPUT[name='_ident_switch.form.enabled']");$("INPUT[name!='_ident_switch.form.enabled'], SELECT",$enFld.parents("FIELDSET")).prop("disabled",!$enFld.is(":checked"));plugin_switchIdent_processPreconfig();}
function plugin_switchIdent_secure_onChange(e){var $secSel=$("SELECT[name='_ident_switch.form.secure']");var $portFld=$("INPUT[name='_ident_switch.form.port']");if('SSL'===$secSel.val().toUpperCase())
$portFld.attr("placeholder",993);else
$portFld.attr("placeholder",143);}
function plugin_switchIdent_switch(val){rcmail.http_post('plugin.ident_switch.switch',{'_ident-id':val,'_mbox':rcmail.env.mailbox});}
function plugin_switchIdent_fixIdent(iid){if(parseInt(iid)>0)
$("#_from").val(iid);}

10
ident_switch.min.js vendored
View File

@@ -1,10 +0,0 @@
$(function(){var $truName=$('.topright .username');if($truName.size()>0){$sw=$('#plugin-ident_switch-account');if($sw.size()>0){$sw.prependTo('.topright');$truName.hide();$('#plugin-ident_switch-account').show();}}
$("INPUT[name='_ident_switch.form.enabled']").change();$("SELECT[name='_ident_switch.form.secure']").change();plugin_switchIdent_processPreconfig();});function plugin_switchIdent_processPreconfig(){var disFld=$("INPUT[name='_ident_switch.form.readonly']");disFld.parentsUntil("TABLE","TR").hide();var disVal=disFld.val();if(disVal>0){$("INPUT[name='_ident_switch.form.host']").prop("disabled",true);$("SELECT[name='_ident_switch.form.secure']").prop("disabled",true);$("INPUT[name='_ident_switch.form.port']").prop("disabled",true);}
if(2==disVal){$("INPUT[name='_ident_switch.form.username']").prop("disabled",true);}}
function plugin_switchIdent_enabled_onChange(e){var $enFld=$("INPUT[name='_ident_switch.form.enabled']");$("INPUT[name!='_ident_switch.form.enabled'], SELECT",$enFld.parents("FIELDSET")).prop("disabled",!$enFld.is(":checked"));plugin_switchIdent_processPreconfig();}
function plugin_switchIdent_secure_onChange(e){var $secSel=$("SELECT[name='_ident_switch.form.secure']");var $portFld=$("INPUT[name='_ident_switch.form.port']");if('SSL'===$secSel.val().toUpperCase())
$portFld.attr("placeholder",993);else
$portFld.attr("placeholder",143);}
function plugin_switchIdent_switch(val){rcmail.http_post('plugin.ident_switch.switch',{'_ident-id':val,'_mbox':rcmail.env.mailbox});}
function plugin_switchIdent_fixIdent(iid){if(parseInt(iid)>0)
$("#_from").val(iid);}

View File

@@ -58,16 +58,31 @@ class ident_switch extends rcube_plugin
{ {
$rc = rcmail::get_instance(); $rc = rcmail::get_instance();
// Currently selected identity switch ($rc->task)
$iid = $_SESSION['iid' . self::MY_POSTFIX]; {
case 'mail':
$this->render_switch($rc, $args);
case 'settings':
$this->include_script('ident_switch-form.js');
break;
}
$iid_int = 0;
if (is_int($iid)) return $args;
$iid_int = $iid; }
elseif ($iid === '-1')
$iid_int = -1; private function render_switch($rc, $args)
elseif (ctype_digit($iid)) {
$iid_int = intval($iid); // 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 // Get list of alternative accounts
$sOpt = ''; $sOpt = '';
@@ -76,7 +91,7 @@ class ident_switch extends rcube_plugin
while ($r = $rc->db->fetch_assoc($qRec)) while ($r = $rc->db->fetch_assoc($qRec))
{ {
$opts = array('value' => $r['id']); $opts = array('value' => $r['id']);
if ($iid_int == $r['iid']) if ($iid == $r['iid'])
$opts['selected'] = 'selected'; $opts['selected'] = 'selected';
// Make label // Make label
@@ -110,7 +125,7 @@ class ident_switch extends rcube_plugin
{ {
// Add main account // Add main account
$opts = array('value' => -1); $opts = array('value' => -1);
if (!$iid || $iid_int == -1) if ($iid <= 0)
$opts['selected'] = 'selected'; $opts['selected'] = 'selected';
$sOpt = html::tag( $sOpt = html::tag(
@@ -119,7 +134,7 @@ class ident_switch extends rcube_plugin
$_SESSION['global_alias'] ? $_SESSION['global_alias'] : $rc->user->data['username'] $_SESSION['global_alias'] ? $_SESSION['global_alias'] : $rc->user->data['username']
) . $sOpt; ) . $sOpt;
$this->include_script('ident_switch.js'); $this->include_script('ident_switch-switch.js');
$sw = html::tag( $sw = html::tag(
'select', 'select',
array( array(
@@ -131,8 +146,6 @@ class ident_switch extends rcube_plugin
); );
$rc->output->add_footer($sw); $rc->output->add_footer($sw);
} }
return $args;
} }
function on_smtp_connect($args) function on_smtp_connect($args)
@@ -162,26 +175,6 @@ class ident_switch extends rcube_plugin
$this->add_texts('localization'); $this->add_texts('localization');
// Create our field set
$args['form']['ident_switch'] = array(
'name' => $this->gettext('form.caption'),
'content' => array(
'ident_switch.form.enabled' => array('type' => 'checkbox', 'onchange' => 'plugin_switchIdent_enabled_onChange();'),
'ident_switch.form.label' => array('type' => 'text', 'size' => 32, 'placeholder' => $args['record']['email']),
'ident_switch.form.host' => array('type' => 'text', 'size' => 64, 'placeholder' => 'localhost'),
'ident_switch.form.secure' => array(
'type' => 'select',
'options' => array('ssl' => 'SSL', 'tls' => 'TLS'),
'onchange' => 'plugin_switchIdent_secure_onChange();'
),
'ident_switch.form.port' => array('type' => 'text', 'size' => 5),
'ident_switch.form.username' => array('type' => 'text', 'size' => 64, 'placeholder' => $args['record']['email']),
'ident_switch.form.password' => array('type' => 'password', 'size' => 64),
'ident_switch.form.delimiter' => array('type' => 'text', 'size' => 1, 'placeholder' => '.'),
'ident_switch.form.readonly' => array('type' => 'hidden'),
),
);
// Load data if exists // Load data if exists
if (isset($args['record']['identity_id'])) if (isset($args['record']['identity_id']))
{ {
@@ -214,6 +207,52 @@ class ident_switch extends rcube_plugin
$this->apply_preconfig($args['record']); $this->apply_preconfig($args['record']);
} }
// Create our field set
// Do that manually decause standard processing shows hidden fields (WTF?)
$fieldset = array(
'ident_switch.form.enabled' => array('type' => 'checkbox', 'onchange' => 'plugin_switchIdent_enabled_onChange();'),
'ident_switch.form.label' => array('type' => 'text', 'size' => 32, 'placeholder' => $args['record']['email']),
'ident_switch.form.host' => array('type' => 'text', 'size' => 64, 'placeholder' => 'localhost'),
'ident_switch.form.secure' => array(
'type' => 'select',
'options' => array('ssl' => 'SSL', 'tls' => 'TLS'),
'onchange' => 'plugin_switchIdent_secure_onChange();'
),
'ident_switch.form.port' => array('type' => 'text', 'size' => 5),
'ident_switch.form.username' => array('type' => 'text', 'size' => 64, 'placeholder' => $args['record']['email']),
'ident_switch.form.password' => array('type' => 'password', 'size' => 64),
'ident_switch.form.delimiter' => array('type' => 'text', 'size' => 1, 'placeholder' => '.'),
'ident_switch.form.readonly' => array('type' => 'hidden'),
);
// Process fields
$addAfter = '';
$table = new html_table(array('cols' => 2));
foreach ($fieldset as $col => $colprop)
{
$data = $args['record'][$col];
if ($colprop['type'] == 'hidden')
{
$addAfter .= rcube_output::get_edit_field($col, $data, $colprop, $colprop['type']);
}
else
{
$colprop['id'] = 'rcmfd_' . $col;
$label = $colprop['label'] ?: $this->gettext(str_replace('-', '', $col));
$value = $colprop['value'] ?: rcube_output::get_edit_field($col, $data, $colprop, $colprop['type']);
$table->add('title', html::label($colprop['id'], rcube::Q($label)));
$table->add(null, $value);
}
}
// Set data for output
$args['form']['ident_switch'] = array(
'name' => $this->gettext('form.caption'),
'content' => $table->show(array('class' => 'propform')) . $addAfter // TODO: copy styles from other tables
);
return $args; return $args;
} }