Ignore:
Timestamp:
May 30, 2011, 2:49:46 PM (14 years ago)
Author:
dennisw
Message:

Fixed form except encryption & date.

Location:
src/django_gheat/website
Files:
2 edited

Legend:

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

    r9219 r9220  
    11// Base stolen from http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
    2 function AjaxRequest(url, callback, filter) {
     2function AjaxRequest(url, callback, filter, field) {
    33
    44  var req = init();
     
    1717      if (req.status == 200) {
    1818        if (callback) {
    19           if (filter) callback(filter, req.responseText);
     19          if (filter) callback(filter, field, req.responseText);
    2020          else callback(req.responseText);
    2121        }
     
    5656
    5757function get_filters() {
     58
     59  // Create form
    5860  var formstart = '<form method="get" action="">';
    5961  var formend = '<input type="button" value="Add filter" onClick="addFilter()"/></form>';
     
    6163  var colour = '<input type="text" id="colour" name="colour" size="10"/> Colour<br />';
    6264  var user = '<select id="user" style="width:104px"><option></option></select> User<br />';
    63 var dataset = '<select id="dataset" style="width:104px"><option></option></select> Dataset<br />';
    64 var node = '<select id="node" style="width:104px"><option></option></select> Node<br />';
     65  var dataset = '<select id="dataset" style="width:104px"><option></option></select> Dataset<br />';
     66  var node = '<select id="node" style="width:104px"><option></option></select> Node<br />';
     67  var enc = '<select id="enc" style="width:104px"><option></option></select> Encryption<br />';
     68  var date = '<select id="date" style="width:104px"><option></option></select> Date<br />';
    6569
    66   document.getElementById('filter_list').innerHTML+=formstart;
    67   document.getElementById('filter_list').innerHTML+=user;
    68 
    69   var filters = new Array('user');
     70  // Write form to document
     71  document.getElementById('filter_list').innerHTML+=(formstart + user + dataset + node + enc + date + colour + layername + formend);
     72 
     73  // Get values for select boxes
     74  // filters[] first value is what to get, second value is which field values will be shown in select box
     75  var filters = [['user','naam'],['dataset','naam'],['node','ssid']]
    7076  for (var i=0; i<filters.length; i++) {
    71     get_json(filters[i]);
     77    get_json(filters[i][0], filters[i][1]);
    7278  }
    73 
    74   // todo: Fix formend, it is called before the 'for' filter is completed, making the form look silly.
    75   document.getElementById('filter_list').innerHTML+=formend;
    7679}
    7780
    7881
    79 function get_json(filter) {
     82function get_json(filter, field) {
    8083  var url = "/website/filter/filter_" + filter;
    81   var ajax = new AjaxRequest(url, set_filter, filter);
     84  var ajax = new AjaxRequest(url, set_filter, filter, field);
    8285  ajax.doGet();
    8386}
    8487
    8588
    86 function set_filter(filter, responseText) {
     89function set_filter(filter, field, responseText) {
    8790  json=eval('(' + responseText + ')');
    8891  var options = '';
    8992  for (var i=0; i<json.length; i++){
    90     options += '<option>' + json[i].fields.naam + '</option>';
     93    options += '<option>' + json[i].fields[field] + '</option>';
    9194  }
    92   document.getElementById('user').innerHTML+=options;
     95  document.getElementById(filter).innerHTML+=options;
    9396}
    9497
     
    97100
    98101  var user = encodeURIComponent(document.getElementById("user").value);
    99   var dataset = '';
    100   var wlnode = '';
    101   var enc ='';
    102   var date = '';
    103   var colour = '';
    104   var lname = '';
     102  var dataset = encodeURIComponent(document.getElementById("dataset").value);
     103  var wlnode = encodeURIComponent(document.getElementById("node").value);
     104  var enc = encodeURIComponent(document.getElementById("enc").value);
     105  var date = encodeURIComponent(document.getElementById("date").value);
     106  var colour = encodeURIComponent(document.getElementById("colour").value);
     107  var lname = encodeURIComponent(document.getElementById("lname").value);
    105108
    106109  if (user != ''){user='&gebruiker__naam='+user;}
     
    131134  map.addLayer(filterlayer);
    132135}
    133 
    134 
    135 /*
    136 
    137 The following code is old, broken and for reference purposes. Will be removed when new code is done.
    138 The above (new) code was used instead to make everything more easy when adding new pieces.
    139 
    140 // Get filter values from django view and serve as option list
    141 function getFilters(){
    142   var filterlist;
    143   var nodelist;
    144   var userlist;
    145   var datasetlist;
    146 
    147   if (window.XMLHttpRequest){
    148     nodelist=new XMLHttpRequest();
    149     userlist=new XMLHttpRequest();
    150     datasetlist=new XMLHttpRequest();
    151   }
    152   else{
    153     nodelist=new ActiveXObject("Microsoft.XMLHTTP");
    154     userlist=new ActiveXObject("Microsoft.XMLHTTP");
    155     datasetlist=new ActiveXObject("Microsoft.XMLHTTP");
    156   }
    157 
    158   var list = '<form method="get" action="">';
    159 
    160 
    161   // 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.
    162 
    163   userlist.onreadystatechange=function(){
    164     if (userlist.readyState==4 && userlist.status==200){
    165       userlist=eval('(' + userlist.responseText + ')');
    166      
    167       list += '<select id="user" style="width:104px"><option></option>';
    168       for (var i=0; i<userlist.length; i++){
    169         list += '<option>' + userlist[i].fields.naam + '</option>';
    170       }
    171       list += '</select> User<br />';
    172 
    173       document.getElementById('filter_list').innerHTML=list;
    174     }
    175   }
    176 
    177 
    178 
    179 
    180   nodelist.onreadystatechange=function(){
    181     if (nodelist.readyState==4 && nodelist.status==200){
    182       nodelist=eval('(' + nodelist.responseText + ')');
    183 
    184       list += '<select id="wlnode" style="width:104px"><option></option>';
    185       for (var i=0; i<nodelist.length; i++){
    186         list += '<option>' + nodelist[i].fields.ssid + '</option>';
    187       }
    188       list += '</select> WLnode<br />';
    189 
    190       document.getElementById('filter_list').innerHTML=list;
    191     }
    192   }
    193 
    194 
    195   datasetlist.onreadystatechange=function(){
    196     if (datasetlist.readyState==4 && datasetlist.status==200){
    197       datasetlist=eval('(' + datasetlist.responseText + ')');
    198 
    199       list += '<select id="dataset" style="width:104px"><option></option>';
    200       for (var i=0; i<datasetlist.length; i++){
    201         list += '<option>' + datasetlist[i].fields.naam + '</option>';
    202       }
    203       list += '</select> Dataset<br />';
    204 
    205       document.getElementById('filter_list').innerHTML=list;
    206     }
    207   }
    208 
    209 
    210   list += '<input type="text" id="enc" name="enc" size="10"/> Encrypted<br />';
    211   list += '<input type="text" id="colour" name="colour" size="10"/> Colour<br />';
    212   list += '<input type="text" id="lname" name="lname" size="10"/> Layername<br />';
    213   list += '<input type="button" value="Add filter" onClick="addFilter()"/>';
    214   list += '</form>';
    215 
    216 
    217 
    218 
    219 
    220   nodelist.open("GET","/website/filters/1",true);
    221   nodelist.send();
    222   userlist.open("GET","/website/filters/2",true);
    223   userlist.send();
    224   datasetlist.open("GET","/website/filters/3",true);
    225   datasetlist.send();
    226 }
    227 */
  • src/django_gheat/website/templates/home.html

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