Author Topic: Register global action  (Read 4390 times)

Offline lmitoraj

  • Newbie
  • *
  • Posts: 1
Register global action
« on: December 08, 2016, 06:20:54 AM »
Hi everyone:) I'm new developer in roundcube:) I'm writing simply plugin. In this plugin I would like init by ajax action from other plugin:) It is possible?:) I try init action from extra plugin by her name action, but it doesn't work.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,232
Re: Register global action
« Reply #1 on: December 09, 2016, 02:35:48 AM »
plugins can register an action like this:

$this->register_action('plugin.myplugin.action', array($this, 'do_something'));

eg: https://github.com/roundcube/roundcubemail/blob/master/plugins/acl/acl.php#L48
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and moreā€¦

Offline jcmoreno

  • Newbie
  • *
  • Posts: 2
Re: Register global action
« Reply #2 on: April 16, 2018, 10:31:37 AM »
Hello, I'm having the same difficulty.
I need to trigger an alert immediately after the action of sending the email "send". I could not understand where to insert the code to perform the action, follow the alert.js and test.php that I create inside plugin/ (folder).
PS: the add_hook option works the alert runs on all the screens, but as I said need only after sending the email

---
teste.php

class teste extends rcube_plugin
{
  public $task = 'mail';
  private $rc;

  /**
   * Plugin initialization
   */

  function init()
  {
    $this->rc = rcmail::get_instance(); 
   
    // Plugin actions
    // $this->add_hook('startup', array($this, 'startup'));
    $this->register_action('plugin.teste', array($this, 'startup'));
  }

  function startup($args)
  {
    $rcmail = rcmail::get_instance();
    $this->include_script('alert.js');
   
    // Only AJAX actions
    $this->rc->output->send();
 
  }

}
---
alert.js

$(document).ready(function(e) {

    alert('Catanduvas verdes!!!!');
});

Thank You.

JC

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,502
    • http://SKaero.com/
Re: Register global action
« Reply #3 on: April 16, 2018, 12:10:13 PM »
If you want to do something with PHP you use the "message_sent" https://github.com/roundcube/roundcubemail/wiki/Plugin-Hooks#message_sent hook. If you want to do something in JS you'd need to use the before/after hooks https://github.com/roundcube/roundcubemail/wiki/Plugin-Events#before-and-after

Offline jcmoreno

  • Newbie
  • *
  • Posts: 2
Re: Register global action
« Reply #4 on: April 16, 2018, 05:14:23 PM »
I was able to run the alert debug on the email composition screen, but it still runs when I enter the screen, I need to run the routine after the email is sent.
Studying the manual I found the message_ready someone can show by applying the command in my code?

--------------------
class testealert extends rcube_plugin
{
  public $task = 'settings|mail|login';

  function init()
  {
    $rcmail = rcmail::get_instance();
   
    if ($rcmail->task == 'mail' && ($rcmail->action == 'compose')) {
      $this->add_hook('startup', array($this, 'startup'));
    }
   
  }

  function startup()
  {   
    $this->include_script('alert.js');
  }

}
--------------------

Thank You

JC

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,502
    • http://SKaero.com/
Re: Register global action
« Reply #5 on: April 16, 2018, 08:17:21 PM »
So your trying to show an js alert when a message is sent?