Generate settings tabs with a template object 'settingstabs' and let plugins register themselves there using the 'settings_actions' hook

pull/125/merge
Thomas Bruederli 11 years ago
parent 85fece2c4d
commit c49c35ca0f

@ -1055,7 +1055,7 @@ class rcmail_output_html extends rcmail_output
// these commands can be called directly via url // these commands can be called directly via url
$a_static_commands = array('compose', 'list', 'preferences', 'folders', 'identities'); $a_static_commands = array('compose', 'list', 'preferences', 'folders', 'identities');
if (!($attrib['command'] || $attrib['name'])) { if (!($attrib['command'] || $attrib['name'] || $attrib['href'])) {
return ''; return '';
} }

@ -1246,9 +1246,66 @@ function rcmail_update_folder_row($name, $oldname=null, $subscribe=false, $class
$name_utf8, $display_name, $protected, $class_name); $name_utf8, $display_name, $protected, $class_name);
} }
/**
* Render the list of settings sections (AKA tabs)
*/
function rcmail_settings_tabs($attrib)
{
global $RCMAIL, $OUTPUT;
// add default attributes
$attrib += array('tagname' => 'span', 'idprefix' => 'settingstab', 'selclass' => 'selected');
$default_actions = array(
array('command' => 'preferences', 'type' => 'link', 'label' => 'preferences', 'title' => 'editpreferences'),
array('command' => 'folders', 'type' => 'link', 'label' => 'folders', 'title' => 'managefolders'),
array('command' => 'identities', 'type' => 'link', 'label' => 'identities', 'title' => 'manageidentities'),
);
// get all identites from DB and define list of cols to be displayed
$plugin = $RCMAIL->plugins->exec_hook('settings_actions', array(
'actions' => $default_actions,
'attrib' => $attrib,
));
$attrib = $plugin['attrib'];
$tagname = $attrib['tagname'];
$tabs = array();
foreach ($plugin['actions'] as $k => $action) {
if (!$action['command'] && !$action['href'] && $action['action']) {
$action['href'] = $RCMAIL->url(array('_action' => $action['action']));
}
$button = $OUTPUT->button($action);
$attr = $attrib;
$cmd = $action['action'] ? $action['action'] : $action['command'];
$id = $action['id'] ? $action['id'] : $cmd;
if (!empty($id)) {
$attr['id'] = preg_replace('/[^a-z0-9]/i', '', $attrib['idprefix'] . $id);
}
$classnames = array($attrib['class']);
if (!empty($action['class'])) {
$classnames[] = $action['class'];
}
else if (!empty($cmd)) {
$classnames[] = $cmd;
}
if ($RCMAIL->action == $cmd) {
$classnames[] = $attrib['selclass'];
}
$attr['class'] = join(' ', $classnames);
$tabs[] = html::tag($tagname, $attr, $button, html::$common_attrib);
}
return join('', $tabs);
}
// register UI objects // register UI objects
$OUTPUT->add_handlers(array( $OUTPUT->add_handlers(array(
'settingstabs' => 'rcmail_settings_tabs',
'prefsframe' => 'rcmail_preferences_frame', 'prefsframe' => 'rcmail_preferences_frame',
'sectionslist' => 'rcmail_sections_list', 'sectionslist' => 'rcmail_sections_list',
'identitieslist' => 'rcmail_identities_list', 'identitieslist' => 'rcmail_identities_list',

@ -10,7 +10,7 @@ function rcube_init_settings_tabs()
{ {
var el, cl, container = $('#tabsbar'), var el, cl, container = $('#tabsbar'),
last_tab = $('span:last', container), last_tab = $('span:last', container),
tab = '#settingstabdefault', tab = '#settingstabpreferences',
action = window.rcmail && rcmail.env.action ? rcmail.env.action : null; action = window.rcmail && rcmail.env.action ? rcmail.env.action : null;
// move About tab to the end // move About tab to the end
@ -22,7 +22,7 @@ function rcube_init_settings_tabs()
// get selected tab // get selected tab
if (action) if (action)
tab = '#settingstab' + (action == 'preferences' ? 'default' : (action.indexOf('identity')>0 ? 'identities' : action.replace(/\./g, ''))); tab = '#settingstab' + (action.indexOf('identity')>0 ? 'identities' : action.replace(/\./g, ''));
$(tab).addClass('tablink-selected'); $(tab).addClass('tablink-selected');
$('a', tab).removeAttr('onclick').click(function() { return false; }); $('a', tab).removeAttr('onclick').click(function() { return false; });

@ -1,8 +1,6 @@
<div id="tabsbar"> <div id="tabsbar">
<span id="settingstabdefault" class="tablink"><roundcube:button command="preferences" type="link" label="preferences" title="editpreferences" /></span> <roundcube:object name="settingstabs" class="tablink" selClass="tablink-selected" />
<span id="settingstabfolders" class="tablink"><roundcube:button command="folders" type="link" label="folders" title="managefolders" class="tablink" /></span>
<span id="settingstabidentities" class="tablink"><roundcube:button command="identities" type="link" label="identities" title="manageidentities" class="tablink" /></span>
<span id="settingstababout" class="tablink"><roundcube:button command="about" type="link" label="about" title="about" class="tablink" /></span>
<roundcube:container name="tabs" id="tabsbar" /> <roundcube:container name="tabs" id="tabsbar" />
<span id="settingstababout" class="tablink"><roundcube:button command="about" type="link" label="about" title="about" class="tablink" /></span>
<script type="text/javascript"> if (window.rcmail) rcmail.add_onload(rcube_init_settings_tabs); </script> <script type="text/javascript"> if (window.rcmail) rcmail.add_onload(rcube_init_settings_tabs); </script>
</div> </div>

@ -29,7 +29,7 @@
<roundcube:button command="logout" label="logout" class="button-logout" classSel="button-logout" innerClass="button-inner" /> <roundcube:button command="logout" label="logout" class="button-logout" classSel="button-logout" innerClass="button-inner" />
<span class="minmodetoggle"></span> <span class="minmodetoggle"></span>
</div> </div>
<roundcube:object name="logo" src="/images/roundcube_logo.png" id="toplogo" alt="Logo" onclick="rcmail.command('switch-task','mail');return false;" /> <roundcube:object name="logo" src="/images/roundcube_logo.png" id="toplogo" alt="Logo" onclick="if(window.rcmail)rcmail.command('switch-task','mail')" />
</div> </div>
<roundcube:endif /> <roundcube:endif />

@ -1,9 +1,7 @@
<div id="settings-sections" class="uibox listbox"> <div id="settings-sections" class="uibox listbox">
<h2 class="boxtitle"><roundcube:label name="settings" /></h2> <h2 class="boxtitle"><roundcube:label name="settings" /></h2>
<div id="settings-tabs" class="scroller"> <div id="settings-tabs" class="scroller">
<span id="settingstabpreferences" class="listitem preferences"><roundcube:button command="preferences" type="link" label="preferences" title="editpreferences" /></span> <roundcube:object name="settingstabs" class="listitem" />
<span id="settingstabfolders" class="listitem folders"><roundcube:button command="folders" type="link" label="folders" title="managefolders" /></span>
<span id="settingstabidentities" class="listitem identities"><roundcube:button command="identities" type="link" label="identities" title="manageidentities" /></span>
<roundcube:container name="tabs" id="settings-tabs" /> <roundcube:container name="tabs" id="settings-tabs" />
</div> </div>
</div> </div>

Loading…
Cancel
Save