Small framework for providing details
authorJoey Schulze <joey@infodrom.org>
Wed, 20 Jan 2010 14:07:19 +0000 (15:07 +0100)
committerJoey Schulze <joey@infodrom.org>
Wed, 20 Jan 2010 14:07:19 +0000 (15:07 +0100)
lib/functions.js

index 3a69024..07af498 100644 (file)
@@ -28,6 +28,22 @@ function ajax_request(func,params,oncomplete)
     req.send(params);
 }
 
+function set_value(id, value)
+{
+    var obj = document.getElementById(id);
+    if (!obj) return;
+
+    if (obj.nodeName.toLowerCase() == 'input'
+       || obj.nodeName.toLowerCase() == 'textarea')
+       obj.value = value;
+    else if (obj.nodeName.toLowerCase() == 'span')
+       obj.innerHTML = value;
+    else if (obj.nodeName.toLowerCase() == 'select')
+       for (var i=0; i < obj.options.length; i++)
+           if (obj.options[i].value == value)
+               obj.selectedIndex = i;
+}
+
 /*
  * Form functions
  */
@@ -36,6 +52,12 @@ function form_save(obj)
     return false;
 }
 
+function details_callback(data)
+{
+    for (var id in data)
+       set_value('detail_'+id, data[id]);
+}
+
 /*
  * Rico functions
  */
@@ -50,6 +72,11 @@ function gridDrillDown(e)
     if (!cell) return;
     var value = cell.innerHTML;
 
+    if (document.getElementById('details')) {
+       var params = 'mask=' + grid.tableId.substr(5) + '&id=' + value;
+       ajax_request('details', params, details_callback);
+    }
+
     if (document.getElementById('form_edit')) {
        var params = 'mask=' + grid.tableId.substr(5) + '&id=' + value;
        ajax_request('fetch', params, false);