Roundcube Community Forum

Third Party Contributions => API Based Plugins => Topic started by: YourSexyMama on October 12, 2011, 06:26:14 PM

Title: I'm having issues interacting with JavaScript...
Post by: YourSexyMama on October 12, 2011, 06:26:14 PM
I for the life of me can't see what I'm doing wrong.

For now all I'm attempting to do is get an alert box.  Once I get that working then I'll progress onto actually asking for a password.  The problem is that I get nothing from this code...

Code: [Select]
PHP:
function init() {
  $this->include_script('decrypt.js');
  ...
  $this->add_hook('message_part_before', array($this, 'decryption_pw'));
  ...
}

function decryption_pw($args) {
   $rcmail = rcmail::get_instance();
   $rcmail->output->command('plugin.decrypt_password', array('test'=>"TEST"));
}

JavaScript:
if(window.rcmail) {
  rcmail.addEventListener('init', function(evt) {
    rcmail.addEventListener('plugin.decrypt_password', get_password);
  });
}
 
function get_password(data) {
  alert("I am a box!");
}  


Any help would be appreciated...
YSM
Title: I'm having issues interacting with JavaScript...
Post by: JohnDoh on October 13, 2011, 02:24:26 AM
hi, looks like you are getting commands and event listeners confused. try this in the JS instead of of the addeventlistener line:
Code: [Select]
rcmail.register_command('plugin.decrypt_password', get_password, true);the "true" at the end is to enable the command.
Title: I'm having issues interacting with JavaScript...
Post by: YourSexyMama on October 13, 2011, 12:33:52 PM
Thanks for your response, but unfortunatly that didn't fix my problem.

I tried having both the register and event listener in, with no success.

I even tried adding in

Code: [Select]
rcmail.enable_command('plugin.decrypt_password', true);

with no success.  From what it looks like that is the same as the third field in register_command, but I wanted to test it all the same.

I know the JS is getting hit, because if I move the alert into the init I get an actual alert every time there is an action.

So again I'm at a loss as to what I'm doing wrong.  More than likely its something dumb I'm not doing...

Anyways thanks for your help.
~Brock
Title: I'm having issues interacting with JavaScript...
Post by: SKaero on October 14, 2011, 11:59:37 AM
It should be:
Code: [Select]

rcmail.register_command('plugin.decrypt_password', function(d) { get_password(d); }, true);