Author Topic: Add button to markmenu  (Read 4930 times)


Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,855
Add button to markmenu
« Reply #1 on: November 26, 2010, 03:13:40 AM »
hi,

you need to do it in two steps, using add_content rather than add_button. something like this:
Code: [Select]
$button = $this->api->output->button(array('command' => 'plugin.blah.blah', 'label' => 'blah'));
$this->api->add_content(html::tag('li', null, $button), 'markmenu');
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline emmeliv

  • Jr. Member
  • **
  • Posts: 12
Add button to markmenu
« Reply #2 on: November 26, 2010, 10:35:50 AM »
Thank you!!
It works except for one thing: the enable/disable commands stopped working. I have stolen the js from "markasjunk". Is there anything that has to be done differently if the button is on the markmenu instead of the toolbar?

Code: [Select]
/* Mark-as-Junk plugin script */

function rcmail_markasjunk(prop)
{
  if (!rcmail.env.uid && (!rcmail.message_list || !rcmail.message_list.get_selection().length))
    return;
 
    var uids = rcmail.env.uid ? rcmail.env.uid : rcmail.message_list.get_selection().join(',');
   
    rcmail.set_busy(true, 'loading');
    rcmail.http_post('plugin.markasjunk', '_uid='+uids+'&_mbox='+urlencode(rcmail.env.mailbox), true);
}

// callback for app-onload event
if (window.rcmail) {
  rcmail.addEventListener('init', function(evt) {
   
    // register command (directly enable in message view mode)
    rcmail.register_command('plugin.markasjunk', rcmail_markasjunk, rcmail.env.uid);
   
    // add event-listener to message list
    if (rcmail.message_list)
      rcmail.message_list.addEventListener('select', function(list){
        rcmail.enable_command('plugin.markasjunk', list.get_selection().length > 0);
      });
  })
}

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,855
Add button to markmenu
« Reply #3 on: November 27, 2010, 03:58:03 AM »
do you mean that it doesnt grey out or that its always enabled? the JS is no different if the button is in a popup menu. if you coppied my first example then you need to add the class and classact paramters (you can see them in MAJ2) to chance the styles on the enabled/disabled button.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline emmeliv

  • Jr. Member
  • **
  • Posts: 12
Add button to markmenu
« Reply #4 on: November 30, 2010, 03:15:34 AM »
Once again, I am really grateful for your help!!

The problem I get is that the link stays grayed out.

If I put the button on the toolbar with this code it works:
Code: [Select]
$this->add_button(array(
        'command' => 'plugin.telenormarkasjunk.junk',
        'imagepas' => $skin_path.'/junk_pas.png',
        'imageact' => $skin_path.'/junk_act.png',
'title' => 'telenormarkasjunk.buttontitle'), 'toolbar');


But if i put the button on the markmenu with this code it doesn't work (the class attribute never gets set to "spamlink active" when I choose a message in the messages list).
 
Code: [Select]
$button = $this->api->output->button(array(
      'command' => 'plugin.telenormarkasjunk.junk',
'class' => 'spamlink',
'classAct'=>'spamlink active',
'label' => 'telenormarkasjunk.buttondesc'));
$this->api->add_content(html::tag('li', null, $button), 'markmenu');

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,855
Add button to markmenu
« Reply #5 on: November 30, 2010, 04:44:42 AM »
in the JS above, in the code you actually use did you change the command name from plugin.markasjunk to plugin.telenormarkasjunk.junk?
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline emmeliv

  • Jr. Member
  • **
  • Posts: 12
Add button to markmenu
« Reply #6 on: November 30, 2010, 04:47:46 AM »
Yes I did. Now the code looks as follows:
Code: [Select]
function rcmail_telenormarkasjunk(prop)
{
  if (!rcmail.env.uid && (!rcmail.message_list || !rcmail.message_list.get_selection().length))
    return;
 
    var uids = rcmail.env.uid ? rcmail.env.uid : rcmail.message_list.get_selection().join(',');
   
    rcmail.set_busy(true, 'loading');
    rcmail.http_post('plugin.telenormarkasjunk.junk', '_uid='+uids+'&_mbox='+urlencode(rcmail.env.mailbox), true);
}

// callback for app-onload event
if (window.rcmail) {
  rcmail.addEventListener('init', function(evt) {
   
    // register command (directly enable in message view mode)
    rcmail.register_command('plugin.telenormarkasjunk.junk', rcmail_telenormarkasjunk, rcmail.env.uid);
   
    // add event-listener to message list
    if (rcmail.message_list)
      rcmail.message_list.addEventListener('select', function(list){
        rcmail.enable_command('plugin.telenormarkasjunk.junk', list.get_selection().length > 0);
      });
  })
}

Any ideas?

Offline emmeliv

  • Jr. Member
  • **
  • Posts: 12
Add button to markmenu
« Reply #7 on: November 30, 2010, 11:09:33 AM »
I found the error!!
In the example code I got from you the classact has to be in lowercase (not classAct).
Code: [Select]
$button = $this->api->output->button(array(
      'command' => 'plugin.telenormarkasjunk.junk',
'class' => 'spamlink',
'classact'=>'spamlink active',
'label' => 'telenormarkasjunk.buttondesc'));
$this->api->add_content(html::tag('li', null, $button), 'markmenu');


Now this issue is solved!