Roundcube Community Forum

 

Add own popup menu to mailtoolbar

Started by nuclearping, March 02, 2013, 05:01:44 PM

Previous topic - Next topic

nuclearping

Hello folks,

I'm trying to add a custom popup menu to the mailtoolbar and so far I'm fine. The button is added to the toolbar and when I click it my popup menu is getting displayed.

My questions / problems are:

1) All items in the popup menu are "disabled" (grayed out), even when I selected a message. Why?

2) When I use the API to create buttons all texts are displayed in [...] brackets. Why? Can I disable it without editing the core file?

3) Am I doing it right at all? Or are there mistakes / bugs I didn't see? I'm quite new to RC Plugin Development and put this together by looking at other plugins or reading parts of the Doc_Plugins manual.

my_popup.js
rcmail.addEventListener('init', function(e) {
    var button = $('<A>').attr('id', 'my_popup_button').html(rcmail.gettext('buttontitle', 'my_popup'));
    button.bind('click', function(e){ return rcmail.command('plugin.my_popup', this); });

    rcmail.add_element(button, 'toolbar');
    rcmail.register_command('plugin.my_popup', function () {
        UI.show_popup('my_popup_menu');
        return false;
    }, true);
    rcmail.register_command('plugin.my_popup_button1', function () {
        alert("WORKS!");
        return false;
    }, true);
});


my_popup.php
<?php

class my_popup extends rcube_plugin {

    function 
init() {
        
$this->load_config();        
        
$this->rcmail rcmail::get_instance();

        
$this->add_hook('template_container', array($this'create_button'));
    }


    function 
create_button($attrib) {
        if (
$attrib['id'] == 'mailtoolbar') {
            
$button $this->api->output->button(array(
                    
'id' => 'my_popup_menulink',
                    
'type' => 'link',
                    
'label' => 'Test',
                    
'command' => 'plugin.my_popup',
                    
'class' => 'button more',
                    
'classact' => 'button more',
                    
'width' => 32,
                    
'height' => 32,
                    
'title' => 'Test Hint',
                    
'domain' => 'my_popup')
                    );
            
$this->api->add_content($button'toolbar');

            
$popup_button_1 $this->api->output->button(array(
                    
'id' => 'rcmbtn500',
                    
'type' => 'link',
                    
'label' => 'Button 1',
                    
'command' => 'plugin.my_popup_button1',
                    
'class' => 'icon',
                    
'classact' => 'icon',
                    
'width' => 32,
                    
'height' => 32,
                    
'domain' => 'my_popup')
                    );
           
            
$attr = array('id' => 'my_popup_menu''class' => 'popupmenu');
            
$li html::tag('li', array(), html::span(array('class' => 'icon read'), $popup_button_1));
            
$cont html::tag('ul', array('class' => 'toolbarmenu iconized'), $li);
            
$this->api->add_content(html::div($attr$cont), 'toolbar');
            
        }
    }
}
?>


my_popup.php - Another approach
<?php

class my_popup extends rcube_plugin {

    function 
init() {
        
$this->load_config();        
        
$this->rcmail rcmail::get_instance();

        
$this->add_hook('template_container', array($this'create_button'));
    }


    function 
create_button($attrib) {
        if (
$attrib['id'] == 'mailtoolbar') {
            
$button $this->api->output->button(array(
                    
'id' => 'my_popup_menulink',
                    
'type' => 'link',
                    
'label' => 'Test',
                    
'command' => 'plugin.my_popup',
                    
'class' => 'button more',
                    
'classact' => 'button more',
                    
'width' => 32,
                    
'height' => 32,
                    
'title' => 'Test Hint',
                    
'domain' => 'my_popup')
                    );
            
$this->api->add_content($button'toolbar');

            
$attr = array('id' => 'my_popup_menu''class' => 'popupmenu');
            
$li 
                
html::tag('li', array(), html::a(array('class' => 'icon''classact' => 'icon''href' => '#''onclick' => 'alert("TEST!");''id' => 'rcmbtn500'), 
                        
html::span(array('class' => 'icon read''classact' => 'icon read'), 'Button 1'))) . "\n";
            
$cont html::tag('ul', array('class' => 'toolbarmenu iconized'), $li);
            
$this->api->add_content(html::div($attr$cont), 'toolbar');
            
        }
    }
}

?>


Thanks in advance for your help. :)

nuclearping

Ok, I got it solved using a custom template and a similar approach like the "markasjunk2" plugin.

Works perfectly now:
1) Buttons in the menu get properly enabled or disabled depending if a message was selected.
2) And I also figured out why the text was in [...] brackets: Because it was not localized using the localization interface of RC.

If anyone is interessted in details, feel free to drop a note.