Author Topic: Need JS callback when message is selected  (Read 3493 times)

Offline christallin

  • Newbie
  • *
  • Posts: 2
Need JS callback when message is selected
« on: April 10, 2013, 04:09:57 PM »
I want to develop a custom plugin for a company which shall support internal workflows.

When a message in the inbox is selected and previewed I need to have a JS callback, well, called. It should get the message UID as argument or is able to get the UID from the message list's selection.

I found the documention of JavaScript events not very helpful. I successfully tried the init event. But I cannot find an event fired by message selection, load or display. How are these called? The trac wiki page (http://trac.roundcube.net/wiki/Plugin_Events#beforeandafter) says I can use after* or before* but I cannot find a reference of commands suitable as replacement for the asterisk. I tried afterload or aftermessage_load without success.

As a workaround I tried to implement a PHP hook on serverside and delegate the event via API to JS on the client. This is what I've written:

Code: [Select]
// PHP server side
class my_plugin extends rcube_plugin {
// embed javascript file
function init() {
$this->include_script('my_plugin.js');

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

function message_read($args) {
$rcmail = rcmail::get_instance();

$rcmail->output->command('plugin.message_read', $args['uid']);
}
}


// JavaScript side
rcmail.addEventListener('plugin.message_read', function(uid) {
console.log('read message ' + uid);
});

Unfortunately I didn't see any sign that this worked out. So to sum it up:

1. How to get JS code called when a message is opened in preview?

2. How get a log/debug output of events/hooks/commands on server respectively client side?


Kind regards

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,882
    • SKaero - Custom Roundcube development
Re: Need JS callback when message is selected
« Reply #1 on: April 12, 2013, 06:18:01 AM »
If I remember correctly the following will get you the uid when a message is clicked:
Code: [Select]
rcmail.message_list.addEventListener('click', function () {
  console.log(rcmail.message_list.get_selection());
});

Offline christallin

  • Newbie
  • *
  • Posts: 2
Re: Need JS callback when message is selected
« Reply #2 on: April 15, 2013, 04:21:25 PM »
I succeeded by register an event handler for the select-event of the
Code: [Select]
rcmail.message_list.

Thank you for the hint to the right point!