Roundcube Community Forum

News and Announcements => General Discussion => Topic started by: emmeliv on November 26, 2010, 02:20:46 AM

Title: Add button to markmenu
Post by: emmeliv on November 26, 2010, 02:20:46 AM
I'd like to add a new option to the markmenu. The problem is that when I do add_button, the rendered tag that is added to the menu isn't enclosed in an
  • element like the rest of the menu links. Therefore the the style sheet doesn't work properly (the option isn't marked red onmouseover etc).
    Is there a way to get the added button to be enclosed in an
  • ?
  • Title: Add button to markmenu
    Post by: JohnDoh 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:
    $button = $this->api->output->button(array('command' => 'plugin.blah.blah', 'label' => 'blah'));
    $this->api->add_content(html::tag('li', null, $button), 'markmenu');
    Title: Add button to markmenu
    Post by: emmeliv 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?

    /* 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);
          });
      })
    }
    Title: Add button to markmenu
    Post by: JohnDoh 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.
    Title: Add button to markmenu
    Post by: emmeliv 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:
    $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).
     $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');
    Title: Add button to markmenu
    Post by: JohnDoh 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?
    Title: Add button to markmenu
    Post by: emmeliv on November 30, 2010, 04:47:46 AM
    Yes I did. Now the code looks as follows:
    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?
    Title: Add button to markmenu
    Post by: emmeliv 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).
    $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!