Author Topic: I'm having issues interacting with JavaScript...  (Read 1994 times)

Offline YourSexyMama

  • Newbie
  • *
  • Posts: 3
I'm having issues interacting with JavaScript...
« 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
« Last Edit: October 12, 2011, 06:28:55 PM by YourSexyMama »

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,305
I'm having issues interacting with JavaScript...
« Reply #1 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.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and moreā€¦

Offline YourSexyMama

  • Newbie
  • *
  • Posts: 3
I'm having issues interacting with JavaScript...
« Reply #2 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

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,553
    • http://SKaero.com/
I'm having issues interacting with JavaScript...
« Reply #3 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);