Changeset 9216 for src/django_gheat


Ignore:
Timestamp:
May 26, 2011, 5:15:09 PM (13 years ago)
Author:
dennisw
Message:

Redid some code with help of a java.sun.com article. Should make it easier to add the filters.

A lot of crappy/old code is still there, will clean up when done.

Location:
src/django_gheat/website
Files:
2 edited

Legend:

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

    r9214 r9216  
     1// Base stolen from http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
     2function AjaxRequest(url, callback) {
     3
     4  var req = init();
     5  req.onreadystatechange = processRequest;
     6       
     7  function init() {
     8    if (window.XMLHttpRequest) {
     9      return new XMLHttpRequest();
     10    } else if (window.ActiveXObject) {
     11      return new ActiveXObject("Microsoft.XMLHTTP");
     12    }
     13  }
     14   
     15  function processRequest () {
     16    if (req.readyState == 4) {
     17      if (req.status == 200) {
     18        if (callback) callback(req.responseText);
     19      }
     20    }
     21  }
     22
     23  this.doGet = function() {
     24    req.open("GET", url, true);
     25    req.send(null);
     26  }
     27}
     28
    129// Uses zoomlevel en mouseposition to call the nodelist.py view. View returns nodes in json format which is read and printed in document element.
    2 function getNodeList(zoomlevel, mousepos){
    3   var nodelist;
     30function getNodeList(zoomlevel, mousepos) {
     31  var url = "/website/nodelist/" + zoomlevel + "," + mousepos.lat + "," + mousepos.lon;
     32  var ajax = new AjaxRequest(url, setNodeList);
     33  ajax.doGet();
     34}
    435
    5   if (window.XMLHttpRequest){
    6     nodelist=new XMLHttpRequest();
     36
     37function setNodeList(responseText) {
     38  json=eval('(' + responseText + ')');
     39  var list = 'test';
     40  if (json.length>0){
     41    list = 'Wireless Leiden nodes on mouseposition:<br /><b>';
     42    for (var i=0; i<json.length; i++){
     43      list += json[i].fields.ssid + '<br />';
     44    }
     45    list += '</b>';
    746  }
    847  else{
    9     nodelist=new ActiveXObject("Microsoft.XMLHTTP");
     48    list = 'No nodes to display.';
    1049  }
    11 
    12   nodelist.onreadystatechange=function(){
    13     if (nodelist.readyState==4 && nodelist.status==200){
    14       json=eval('(' + nodelist.responseText + ')');
    15       var list;
    16       if (json.length>0){
    17         list = 'Wireless Leiden nodes on mouseposition:<br /><b>';
    18         for (var i=0; i<json.length; i++){
    19           list += json[i].fields.ssid + '<br />';
    20         }
    21         list += '</b>';
    22       }
    23       else{
    24         list = 'No nodes to display.';
    25       }
    26       document.getElementById('node_list').innerHTML=list;
    27     }
    28   }
    29   nodelist.open("GET","/website/nodelist/" + zoomlevel + "," + mousepos.lat + "," + mousepos.lon,true);
    30   nodelist.send();
     50  document.getElementById('node_list').innerHTML=list;
    3151}
    3252
     53
     54
     55/*
     56
     57The following code is old, broken and for reference purposes. Will be removed when new code is done.
     58The above (new) code was used instead to make everything more easy when adding new pieces.
    3359
    3460// Get filter values from django view and serve as option list
    3561function getFilters(){
    3662  var filterlist;
     63  var nodelist;
     64  var userlist;
     65  var datasetlist;
    3766
    3867  if (window.XMLHttpRequest){
    39     filterlist=new XMLHttpRequest();
     68    nodelist=new XMLHttpRequest();
     69    userlist=new XMLHttpRequest();
     70    datasetlist=new XMLHttpRequest();
    4071  }
    4172  else{
    42     filterlist=new ActiveXObject("Microsoft.XMLHTTP");
     73    nodelist=new ActiveXObject("Microsoft.XMLHTTP");
     74    userlist=new ActiveXObject("Microsoft.XMLHTTP");
     75    datasetlist=new ActiveXObject("Microsoft.XMLHTTP");
    4376  }
     77
     78  var list = '<form method="get" action="">';
     79
     80
    4481  // todo: Get new options if one option is selected; every user has different datasets, make sure when user 'John' is selected, you can only choose datasets who are his.
    45   filterlist.onreadystatechange=function(){
    46     if (filterlist.readyState==4 && filterlist.status==200){
    47       json=eval('(' + filterlist.responseText + ')');
    48       var list = '<form method="get" action="">';
    49       list += '<input type="text" id="user" name="user" size="10"/> User<br />';
    50       list += '<input type="text" id="dataset" name="dataset" size="10"/> Dataset<br />';
    51       list += '<input type="text" id="date" name="date" size="10"/> Date<br />';
     82
     83  userlist.onreadystatechange=function(){
     84    if (userlist.readyState==4 && userlist.status==200){
     85      userlist=eval('(' + userlist.responseText + ')');
    5286     
     87      list += '<select id="user" style="width:104px"><option></option>';
     88      for (var i=0; i<userlist.length; i++){
     89        list += '<option>' + userlist[i].fields.naam + '</option>';
     90      }
     91      list += '</select> User<br />';
     92
     93      document.getElementById('filter_list').innerHTML=list;
     94    }
     95  }
     96
     97
     98
     99
     100  nodelist.onreadystatechange=function(){
     101    if (nodelist.readyState==4 && nodelist.status==200){
     102      nodelist=eval('(' + nodelist.responseText + ')');
     103
    53104      list += '<select id="wlnode" style="width:104px"><option></option>';
    54       for (var i=0; i<json.length; i++){
    55         list += '<option>' + json[i].fields.ssid + '</option>';
     105      for (var i=0; i<nodelist.length; i++){
     106        list += '<option>' + nodelist[i].fields.ssid + '</option>';
    56107      }
    57108      list += '</select> WLnode<br />';
    58109
    59       list += '<input type="text" id="enc" name="enc" size="10"/> Encrypted<br />';
    60       list += '<input type="text" id="colour" name="colour" size="10"/> Colour<br />';
    61       list += '<input type="text" id="lname" name="lname" size="10"/> Layername<br />';
    62       list += '<input type="button" value="Add filter" onClick="addFilter()"/>';
    63       list += '</form>';
    64110      document.getElementById('filter_list').innerHTML=list;
    65111    }
    66112  }
    67   filterlist.open("GET","/website/filters",true);
    68   filterlist.send();
     113
     114
     115  datasetlist.onreadystatechange=function(){
     116    if (datasetlist.readyState==4 && datasetlist.status==200){
     117      datasetlist=eval('(' + datasetlist.responseText + ')');
     118
     119      list += '<select id="dataset" style="width:104px"><option></option>';
     120      for (var i=0; i<datasetlist.length; i++){
     121        list += '<option>' + datasetlist[i].fields.naam + '</option>';
     122      }
     123      list += '</select> Dataset<br />';
     124
     125      document.getElementById('filter_list').innerHTML=list;
     126    }
     127  }
     128
     129
     130  list += '<input type="text" id="enc" name="enc" size="10"/> Encrypted<br />';
     131  list += '<input type="text" id="colour" name="colour" size="10"/> Colour<br />';
     132  list += '<input type="text" id="lname" name="lname" size="10"/> Layername<br />';
     133  list += '<input type="button" value="Add filter" onClick="addFilter()"/>';
     134  list += '</form>';
     135
     136
     137
     138
     139
     140  nodelist.open("GET","/website/filters/1",true);
     141  nodelist.send();
     142  userlist.open("GET","/website/filters/2",true);
     143  userlist.send();
     144  datasetlist.open("GET","/website/filters/3",true);
     145  datasetlist.send();
    69146}
    70147
     
    108185  map.addLayer(filterlayer);
    109186}
     187*/
  • src/django_gheat/website/templates/home.html

    r9214 r9216  
    2929
    3030
    31 <body onload="init(),getFilters()">
     31<body onload="init()">
    3232  <div id="heatmap"></div>
    3333  <div id="container">
Note: See TracChangeset for help on using the changeset viewer.