Changeset 9220 for src/django_gheat/website
- Timestamp:
- May 30, 2011, 2:49:46 PM (14 years ago)
- Location:
- src/django_gheat/website
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/website/static/heatmap_extensions.js
r9219 r9220 1 1 // Base stolen from http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/ 2 function AjaxRequest(url, callback, filter ) {2 function AjaxRequest(url, callback, filter, field) { 3 3 4 4 var req = init(); … … 17 17 if (req.status == 200) { 18 18 if (callback) { 19 if (filter) callback(filter, req.responseText);19 if (filter) callback(filter, field, req.responseText); 20 20 else callback(req.responseText); 21 21 } … … 56 56 57 57 function get_filters() { 58 59 // Create form 58 60 var formstart = '<form method="get" action="">'; 59 61 var formend = '<input type="button" value="Add filter" onClick="addFilter()"/></form>'; … … 61 63 var colour = '<input type="text" id="colour" name="colour" size="10"/> Colour<br />'; 62 64 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 />'; 65 69 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']] 70 76 for (var i=0; i<filters.length; i++) { 71 get_json(filters[i] );77 get_json(filters[i][0], filters[i][1]); 72 78 } 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;76 79 } 77 80 78 81 79 function get_json(filter ) {82 function get_json(filter, field) { 80 83 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); 82 85 ajax.doGet(); 83 86 } 84 87 85 88 86 function set_filter(filter, responseText) {89 function set_filter(filter, field, responseText) { 87 90 json=eval('(' + responseText + ')'); 88 91 var options = ''; 89 92 for (var i=0; i<json.length; i++){ 90 options += '<option>' + json[i].fields .naam+ '</option>';93 options += '<option>' + json[i].fields[field] + '</option>'; 91 94 } 92 document.getElementById( 'user').innerHTML+=options;95 document.getElementById(filter).innerHTML+=options; 93 96 } 94 97 … … 97 100 98 101 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); 105 108 106 109 if (user != ''){user='&gebruiker__naam='+user;} … … 131 134 map.addLayer(filterlayer); 132 135 } 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 list141 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 29 29 30 30 31 <body onload="init(), filter_node()">31 <body onload="init(), get_filters()"> 32 32 <div id="heatmap"></div> 33 33 <div id="container">
Note:
See TracChangeset
for help on using the changeset viewer.