Ignore:
Timestamp:
May 27, 2011, 4:16:09 PM (14 years ago)
Author:
dennisw
Message:

Tried to make the process of getting filters a bit more dynamic. They are more dynamic now, but it's unfinished and not really working yet.

If you want working filters (that is, the working node filter), stay with older Rev.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/website/static/heatmap_extensions.js

    r9217 r9218  
    11// Base stolen from http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
    2 function AjaxRequest(url, callback) {
     2function AjaxRequest(url, callback, filter) {
    33
    44  var req = init();
     
    1616    if (req.readyState == 4) {
    1717      if (req.status == 200) {
    18         if (callback) callback(req.responseText);
     18        if (callback) {
     19          if (filter) callback(filter, req.responseText);
     20          else callback(req.responseText);
     21        }
    1922      }
    2023    }
     
    2629  }
    2730}
     31
    2832
    2933// Uses zoomlevel en mouseposition to call the nodelist.py view. View returns nodes in json format which is read and printed in document element.
     
    5155
    5256
    53 function filter_node() {
    54   var url = "/website/filter/filter_node";
    55   var ajax = new AjaxRequest(url, set_filter_node);
     57function get_filters() {
     58  var formstart = '<form method="get" action="">';
     59  var formend = '<input type="button" value="Add filter" onClick="addFilter()"/></form>';
     60
     61  document.getElementById('filter_list').innerHTML+=formstart;
     62
     63  var filters = new Array('user', 'dataset');
     64  for (var i=0; i<filters.length; i++) {
     65    get_json(filters[i]);
     66  }
     67
     68  // todo: Fix formend, it is called before the 'for' filter is completed, making the form look silly.
     69  document.getElementById('filter_list').innerHTML+=formend;
     70}
     71
     72
     73function get_json(filter) {
     74  var url = "/website/filter/filter_" + filter;
     75  var ajax = new AjaxRequest(url, set_filter, filter);
    5676  ajax.doGet();
    5777}
    5878
    5979
    60 function set_filter_node(responseText) {
     80function set_filter(filter, responseText) {
    6181  json=eval('(' + responseText + ')');
    62   list = '<form method="get" action=""><select id="wlnode" style="width:104px"><option></option>';
     82  var options = '<select id=' + filter + ' style="width:104px"><option></option>';
    6383  for (var i=0; i<json.length; i++){
    64     list += '<option>' + json[i].fields.ssid + '</option>';
    65   }
    66   list += '</select> WLnode<br /><input type="button" value="Add filter" onClick="addFilter()"/></form>';
    67   document.getElementById('filter_list').innerHTML=list;
     84    options += '<option>' + json[i].fields.naam + '</option>';
     85  }
     86  options += '</select> ' + filter + '<br />';
     87  document.getElementById('filter_list').innerHTML+=options;
    6888}
    6989
     
    7191function addFilter(){
    7292
    73   var user = '';
     93  var user = encodeURIComponent(document.getElementById("user").value);
    7494  var dataset = '';
    75   var wlnode = encodeURIComponent(document.getElementById("wlnode").value);
     95  var wlnode = '';
    7696  var enc ='';
    7797  var date = '';
     
    7999  var lname = '';
    80100
    81   if (user != ''){user='&accespoint__id='+user;}
     101  if (user != ''){user='&gebruiker__naam='+user;}
    82102  if (dataset != ''){dataset='&meetrondje__naam='+dataset;}
    83103  if (wlnode != ''){wlnode='&accespoint__ssid='+wlnode;}
Note: See TracChangeset for help on using the changeset viewer.