Small AJAX framework and auxiliary JavaScript functions
authorJoey Schulze <joey@infodrom.org>
Wed, 20 Jan 2010 09:51:27 +0000 (10:51 +0100)
committerJoey Schulze <joey@infodrom.org>
Wed, 20 Jan 2010 09:51:27 +0000 (10:51 +0100)
lib/functions.js [new file with mode: 0644]

diff --git a/lib/functions.js b/lib/functions.js
new file mode 100644 (file)
index 0000000..3a69024
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Small AJAX framework
+ */
+function ajax_request_callback(req)
+{
+    if (req.readyState == 4 && req.status == 200) {
+       var data = json_parse(req.responseText);
+
+       if (req.oncomplete)
+           req.oncomplete(data);
+    }
+}
+
+function ajax_request(func,params,oncomplete)
+{
+    var req = new XMLHttpRequest();
+    if (!req) return;
+
+    var params = 'func=' + func + '&' + params;
+    req.open ("POST", 'ajax/ajax.php');
+    req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+    req.setRequestHeader("Content-length", params.length);
+    req.setRequestHeader("Connection", "close");
+    if (typeof oncomplete == 'function') {
+       req.onreadystatechange = function() { ajax_request_callback(req); }
+       req.oncomplete = oncomplete;
+    }
+    req.send(params);
+}
+
+/*
+ * Form functions
+ */
+function form_save(obj)
+{
+    return false;
+}
+
+/*
+ * Rico functions
+ */
+function gridDrillDown(e)
+{
+    if (e.originalTarget && e.originalTarget.target && e.originalTarget.target == '_top')
+       return;
+
+    var id = 0; // Column 0 contains ID
+    var row = grid.edit.drillDown(e,0,0);
+    var cell = grid.columns[id].cell(row);
+    if (!cell) return;
+    var value = cell.innerHTML;
+
+    if (document.getElementById('form_edit')) {
+       var params = 'mask=' + grid.tableId.substr(5) + '&id=' + value;
+       ajax_request('fetch', params, false);
+    }
+}