summaryrefslogtreecommitdiffstats
path: root/public_html
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-02-16 10:16:55 +0100
committerAleksander Machniak <alec@alec.pl>2012-02-16 10:16:55 +0100
commit6664b058c428e86511c5330f735df3d7752b6fe8 (patch)
treef8230098602e644e88ef01376479f7abe927bbdd /public_html
parent620c4bf621f607b21904f590e4e676f396d40362 (diff)
downloadwebadmin-6664b058c428e86511c5330f735df3d7752b6fe8.tar.gz
Added proxy functionality - allows direct API calls
Diffstat (limited to 'public_html')
-rw-r--r--public_html/.htaccess2
-rw-r--r--public_html/api/index.php2
-rw-r--r--public_html/js/kolab_admin.js78
3 files changed, 66 insertions, 16 deletions
diff --git a/public_html/.htaccess b/public_html/.htaccess
index 7af6ff3..e646d2d 100644
--- a/public_html/.htaccess
+++ b/public_html/.htaccess
@@ -1,6 +1,6 @@
<IfModule mod_rewrite.c>
RewriteEngine on
- RewriteBase /~machniak/kolab-wap/public_html
+ RewriteBase /rc/admin/public_html
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
diff --git a/public_html/api/index.php b/public_html/api/index.php
index 9633e95..0760e9e 100644
--- a/public_html/api/index.php
+++ b/public_html/api/index.php
@@ -6,7 +6,7 @@ require_once dirname(__FILE__) . "/../../lib/functions.php";
$controller = new kolab_api_controller;
try {
- $postdata = $_SERVER['REQUEST_METHOD'] == 'POST' ? @json_decode(file_get_contents('php://input'), true) : null;
+ $postdata = $_SERVER['REQUEST_METHOD'] == 'POST' ? file_get_contents('php://input') : null;
$controller->dispatch($postdata);
} catch(Exception $e) {
error_log($e->getMessage());
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index d1b3daf..46d3dc9 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -7,14 +7,14 @@ function kolab_admin()
this.env = {};
this.translations = {};
this.request_timeout = 300;
- this.message_time = 4000;
+ this.message_time = 3000;
this.events = {};
// set jQuery ajax options
$.ajaxSetup({
cache: false,
error: function(request, status, err) { ref.http_error(request, status, err); },
- beforeSend: function(xmlhttp) { xmlhttp.setRequestHeader('X-KAP-Request', ref.env.token); }
+ beforeSend: function(xmlhttp) { xmlhttp.setRequestHeader('X-Session-Token', ref.env.token); }
});
@@ -250,8 +250,7 @@ function kolab_admin()
// send a http POST request to the server
this.http_post = function(action, postdata)
{
- var url = this.url(action),
- dt = new Date();
+ var url = this.url(action);
if (postdata && typeof postdata === 'object')
postdata.remote = 1;
@@ -261,11 +260,27 @@ function kolab_admin()
postdata += '&remote=1';
}
- this.set_request_time()
+ this.set_request_time();
return $.ajax({
type: 'POST', url: url, data: postdata, dataType: 'json',
- success: function(data) { ref.http_response(data); },
+ success: function(data) { kadm.http_response(data); },
+ error: function(o, status, err) { kadm.http_error(o, status, err); }
+ });
+ };
+
+ // send a http POST request to the API service
+ this.api_post = function(action, postdata, func)
+ {
+ var url = 'api/' + action;
+
+ if (!func) func = 'api_response';
+
+ this.set_request_time();
+
+ return $.ajax({
+ type: 'POST', url: url, data: postdata, dataType: 'json',
+ success: function(data) { kadm[func](data); },
error: function(o, status, err) { kadm.http_error(o, status, err); }
});
};
@@ -273,7 +288,7 @@ function kolab_admin()
// handle HTTP response
this.http_response = function(response)
{
- var i, el, t;
+ var i;
if (!response)
return;
@@ -287,17 +302,11 @@ function kolab_admin()
for (i in response.objects)
$('#'+i).html(response.objects[i]);
- // Update gen. time
- if (this.env.request_time) {
- t = ((new Date()).getTime() - this.env.request_time)/1000;
- el = $('#reqtime');
- el.text(el.text().replace(/[0-9.,]+/, t));
- }
-
// we have translation labels to add
if (typeof response.labels === 'object')
this.tdef(response.labels);
+ this.update_request_time();
this.set_busy(false);
// if we get javascript code from server -> execute it
@@ -317,6 +326,22 @@ function kolab_admin()
this.display_message(this.t('servererror') + ' (' + errmsg + ')', 'error');
};
+ this.api_response = function(response)
+ {
+ if (!response)
+ return false;
+
+ this.update_request_time();
+ this.set_busy(false);
+
+ if (response.status == 'ERROR') {
+ this.display_message(response.reason, 'error');
+ return false;
+ }
+
+ return true;
+ };
+
/********************************************************/
/********* Helper methods *********/
@@ -353,6 +378,16 @@ function kolab_admin()
this.env.request_time = (new Date()).getTime();
};
+ // Update request time element
+ this.update_request_time = function()
+ {
+ if (this.env.request_time) {
+ var t = ((new Date()).getTime() - this.env.request_time)/1000,
+ el = $('#reqtime');
+ el.text(el.text().replace(/[0-9.,]+/, t));
+ }
+ };
+
this.serialize_form = function(id)
{
var i, query = $(id).serializeArray(),
@@ -390,6 +425,21 @@ function kolab_admin()
this.http_post('user.list', props);
};
+ this.user_delete = function(props)
+ {
+
+ };
+
+ this.user_save = function(props)
+ {
+ this.api_post('user.add', {}, 'user_save_response');
+ };
+
+ this.user_save_response = function(response)
+ {
+ this.api_response(response);
+ };
+
};
var kadm = new kolab_admin();