Author Topic: [SOLVED] [Plugin-API] Need help for 1.0.3-compatibility  (Read 4913 times)

Offline 0csic

  • Newbie
  • *
  • Posts: 3
[SOLVED] [Plugin-API] Need help for 1.0.3-compatibility
« on: October 19, 2015, 04:44:10 PM »
Hi there,

I'm quite new to roundcube, because a customer of mine needs a little function I had to programm for him. So I did with the current release of RC and it just works fine. But now there is a problem: My customer uses v1.0.3 and is not going to update within the next time and recommends to get the plugin compatible to this version. I had some trouble till now to find the issue but I'm noch able to do so.

It seems to be a problem with the output: my script waits for JSON-data but gets the hole page. Here a snippet of the relevant code:

Code: [Select]
$(document).ready(function() {
  rcmail.addEventListener('plugin.myaction', myaction);
 
  rcmail.http_post('plugin.myaction');
});

function myaction(response)
{
  // do some stuff
}

This code-snipped is somewhat simple but should show what I want to do. The JS is only included if there is a defined condition so there will be no communication otherwise.
If the JS is loaded it sends a POST-request to the server to start the action which runs as expected, but there is no JSON-output as expected like in v1.1.3. I hope someone can help me out, I donÄt know where to look at and the changelogs doesn't help to find the relevant difference within v1.0.3 and 1.1.3...

Code: [Select]
class myplugin extends rcube_plugin
{
  // [...]

  public function init()
  {
    // register hook
    $this->add_hook('myhook', array($this, 'mycheck'));
    // register action
    $this->register_action('plugin.myaction', array($this, 'myaction'));
  }
 
  public function myaction()
  {
    // send ajax-response back to client
    $rcmail = rcmail::get_instance();
    $rcmail->output->command('plugin.myaction', array('_mycontent' => 'content'));
  }

  public function mycheck($p)
  {
    // [...] do some stuff
   
    if ($foo == $bar) {
      // include js/css
      $this->include_script('myplugin.js');
    }
   
    // return the object as expected by api
    return $p;
  }
}
« Last Edit: October 20, 2015, 02:55:14 AM by 0csic »

Offline alec

  • Hero Member
  • *****
  • Posts: 1,363
Re: [Plugin-API] Need help for 1.0.3-compatibility
« Reply #1 on: October 20, 2015, 01:24:44 AM »
Add $rcmail->output->send(); in myaction() method of the plugin class.

Offline 0csic

  • Newbie
  • *
  • Posts: 3
Re: [Plugin-API] Need help for 1.0.3-compatibility
« Reply #2 on: October 20, 2015, 01:48:48 AM »
Hi!

I tried this out but it results in an error "501" - something with a missing template or so!?

Is there a possibility to get the documentation of this version anywhere?

[EDIT]

This is what I got after adding the $rcmail->output->send();:

Code: [Select]
SERVICE CURRENTLY NOT AVAILABLE!

Error No. [501]

[EDIT2]

Activating the debug_level "4" results in this:

Code: [Select]
SERVICE CURRENTLY NOT AVAILABLE!

Error loading template for

so there seems to be no name for the template (I guess there should be a "template for xyz"!?) which results in not being able to load a template??
« Last Edit: October 20, 2015, 02:31:41 AM by 0csic »

Offline alec

  • Hero Member
  • *****
  • Posts: 1,363
Re: [Plugin-API] Need help for 1.0.3-compatibility
« Reply #3 on: October 20, 2015, 02:49:55 AM »
Looks like it does not recognize the request as ajax request. Try rcmail.http_post('plugin.myaction', {});

Offline 0csic

  • Newbie
  • *
  • Posts: 3
Re: [Plugin-API] Need help for 1.0.3-compatibility
« Reply #4 on: October 20, 2015, 02:54:53 AM »
Looks like it does not recognize the request as ajax request. Try rcmail.http_post('plugin.myaction', {});

You are my personal hero! Hours of troubleshooting and just three chars in a function-call are the solution!! Thank you very much!

For the mods: The problem is solved!