Author Topic: Add own popup menu to mailtoolbar  (Read 5315 times)

Offline nuclearping

  • Newbie
  • *
  • Posts: 5
Add own popup menu to mailtoolbar
« on: March 02, 2013, 05:01:44 PM »
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
Code: [Select]
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
Code: [Select]
<?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
Code: [Select]
<?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. :)

Offline nuclearping

  • Newbie
  • *
  • Posts: 5
Re: Add own popup menu to mailtoolbar
« Reply #1 on: March 03, 2013, 12:06:04 AM »
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.