1

I don't know how to trigger drupal rule from JavaScript code.

      lowerLayer[image.feature_nid].on("dragend", function() {
               var position = kineticImage.getPosition();
               var layerPosition = this.getPosition();
               var slotNid = kineticImage.slot_nid;
               positionX = position.x + layerPosition.x;
               positionY = position.y + layerPosition.y;
               //Here I want to call drupal rule
        });  

I commented the line where I need to trigger drupal rule. Can I call a drupal rule with these parameters (slotNid,positionX,positionY) like I can call some function (someFunction(slotNid,positionX,positionY).

Any solutions are welcome.

gherkins
  • 14,603
  • 6
  • 44
  • 70
Haris Hajdarevic
  • 1,535
  • 2
  • 25
  • 39
  • There's no javascript Rules API - you'll need to use an AJAX call to a custom callback you define yourself. In that callback you invoke the rule using `rules_invoke_event()`, and prepare any output you want to return to the client. – Clive May 30 '13 at 12:09
  • Can you write me some small example which will work in my case, please.. – Haris Hajdarevic May 30 '13 at 12:11

1 Answers1

2

As mentioned by Clive, You can achieve this by ajax call.
You need to setup page callback under menu hook in your custom module & there you can mention the function to call on page request.

Example:
// this code will go under menu hook
$items['ajax/rule1.1'] = array(
    'title' => 'Rule 1.1', 
    'page callback' => 'custom_rule_trigger', 
    'access arguments' => array('access content'), 
    'file' => 'custom_rules.inc',
  );

// then you can write php code which you want to execute under custom_rule_trigger function in custom_rules.inc file.
function custom_rule_trigger(){
// write your rules here.. 
}

In javascript, you can call www.example.com/ajax/rule1.1 url to trigger your rule.

Hope this will help.

Sumoanand
  • 8,835
  • 2
  • 47
  • 46