From 7ceabc8815ef27557826380d649e18942b02c814 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sat, 29 May 2010 13:16:45 -0400
Subject: [PATCH] - Add request* event triggers in http_post/http_request (#1486054)

---
 program/js/app.js |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index fbbae4a..dcc2120 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -4884,9 +4884,19 @@
   // send a http request to the server
   this.http_request = function(action, querystring, lock)
   {
-    querystring += (querystring ? '&' : '') + '_remote=1';
-    var url = this.env.comm_path + '&_action=' + action + '&' + querystring
+    // trigger plugin hook
+    var result = this.triggerEvent('request'+action, querystring);
+    if (typeof result != 'undefined') {
+      // abort if one the handlers returned false
+      if (result === false)
+        return false;
+      else
+        querystring = result;
+    }
 
+    querystring += (querystring ? '&' : '') + '_remote=1';
+    var url = this.env.comm_path + '&_action=' + action + '&' + querystring;
+                                              
     // send request
     console.log('HTTP GET: ' + url);
     $.get(url, { _unlock:(lock?1:0) }, function(data){ ref.http_response(data); }, 'json');
@@ -4904,6 +4914,16 @@
     else
       postdata += (postdata ? '&' : '') + '_remote=1' + (lock ? '&_unlock=1' : '');
 
+    // trigger plugin hook
+    var result = this.triggerEvent('request'+action, postdata);
+    if (typeof result != 'undefined') {
+      // abort if one the handlers returned false
+      if (result === false)
+        return false;
+      else
+        postdata = result;
+    }
+
     // send request
     console.log('HTTP POST: ' + url);
     $.post(url, postdata, function(data){ ref.http_response(data); }, 'json');

--
Gitblit v1.9.1