source: src/django_gheat/website/static/heatmap_extensions.js@ 9218

Last change on this file since 9218 was 9218, checked in by dennisw, 13 years ago

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 size: 6.6 KB
Line 
1// Base stolen from http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
2function AjaxRequest(url, callback, filter) {
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) {
19 if (filter) callback(filter, req.responseText);
20 else callback(req.responseText);
21 }
22 }
23 }
24 }
25
26 this.doGet = function() {
27 req.open("GET", url, true);
28 req.send(null);
29 }
30}
31
32
33// Uses zoomlevel en mouseposition to call the nodelist.py view. View returns nodes in json format which is read and printed in document element.
34function getNodeList(zoomlevel, mousepos) {
35 var url = "/website/nodelist/" + zoomlevel + "," + mousepos.lat + "," + mousepos.lon;
36 var ajax = new AjaxRequest(url, setNodeList);
37 ajax.doGet();
38}
39
40
41function setNodeList(responseText) {
42 json=eval('(' + responseText + ')');
43 if (json.length>0){
44 list = 'Wireless Leiden nodes on mouseposition:<br /><b>';
45 for (var i=0; i<json.length; i++){
46 list += json[i].fields.ssid + '<br />';
47 }
48 list += '</b>';
49 }
50 else{
51 list = 'No nodes to display.';
52 }
53 document.getElementById('node_list').innerHTML=list;
54}
55
56
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);
76 ajax.doGet();
77}
78
79
80function set_filter(filter, responseText) {
81 json=eval('(' + responseText + ')');
82 var options = '<select id=' + filter + ' style="width:104px"><option></option>';
83 for (var i=0; i<json.length; i++){
84 options += '<option>' + json[i].fields.naam + '</option>';
85 }
86 options += '</select> ' + filter + '<br />';
87 document.getElementById('filter_list').innerHTML+=options;
88}
89
90
91function addFilter(){
92
93 var user = encodeURIComponent(document.getElementById("user").value);
94 var dataset = '';
95 var wlnode = '';
96 var enc ='';
97 var date = '';
98 var colour = '';
99 var lname = '';
100
101 if (user != ''){user='&gebruiker__naam='+user;}
102 if (dataset != ''){dataset='&meetrondje__naam='+dataset;}
103 if (wlnode != ''){wlnode='&accespoint__ssid='+wlnode;}
104 if (enc != ''){enc='&accespoint__encryptie='+enc;}
105 if (date != ''){date='&meetrondje__datum='+date;}
106 if (colour != ''){colour='colour='+colour;}
107 else {colour = '&colour='+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256);}
108 if (lname != ''){lname=lname;}
109 else {lname = 'Custom Filter';}
110
111 var baseurl = "/website/tile/${z}/${x},${y}.png?";
112
113 OpenLayers.Layer.OSM.Overlay = OpenLayers.Class(OpenLayers.Layer.OSM, {
114 initialize: function(name, options) {
115 var url = [
116 baseurl + colour + user + dataset + wlnode + enc + date
117 ];
118 options = OpenLayers.Util.extend({ numZoomLevels: 21 }, options);
119 var newArguments = [name, url, options];
120 OpenLayers.Layer.OSM.prototype.initialize.apply(this, newArguments);
121 },
122 CLASS_NAME: "OpenLayers.Layer.Overlay"
123 });
124
125 filterlayer = new OpenLayers.Layer.OSM.Overlay(lname, {isBaseLayer: false, visibility: true});
126 map.addLayer(filterlayer);
127}
128
129
130/*
131
132The following code is old, broken and for reference purposes. Will be removed when new code is done.
133The above (new) code was used instead to make everything more easy when adding new pieces.
134
135// Get filter values from django view and serve as option list
136function getFilters(){
137 var filterlist;
138 var nodelist;
139 var userlist;
140 var datasetlist;
141
142 if (window.XMLHttpRequest){
143 nodelist=new XMLHttpRequest();
144 userlist=new XMLHttpRequest();
145 datasetlist=new XMLHttpRequest();
146 }
147 else{
148 nodelist=new ActiveXObject("Microsoft.XMLHTTP");
149 userlist=new ActiveXObject("Microsoft.XMLHTTP");
150 datasetlist=new ActiveXObject("Microsoft.XMLHTTP");
151 }
152
153 var list = '<form method="get" action="">';
154
155
156 // 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.
157
158 userlist.onreadystatechange=function(){
159 if (userlist.readyState==4 && userlist.status==200){
160 userlist=eval('(' + userlist.responseText + ')');
161
162 list += '<select id="user" style="width:104px"><option></option>';
163 for (var i=0; i<userlist.length; i++){
164 list += '<option>' + userlist[i].fields.naam + '</option>';
165 }
166 list += '</select> User<br />';
167
168 document.getElementById('filter_list').innerHTML=list;
169 }
170 }
171
172
173
174
175 nodelist.onreadystatechange=function(){
176 if (nodelist.readyState==4 && nodelist.status==200){
177 nodelist=eval('(' + nodelist.responseText + ')');
178
179 list += '<select id="wlnode" style="width:104px"><option></option>';
180 for (var i=0; i<nodelist.length; i++){
181 list += '<option>' + nodelist[i].fields.ssid + '</option>';
182 }
183 list += '</select> WLnode<br />';
184
185 document.getElementById('filter_list').innerHTML=list;
186 }
187 }
188
189
190 datasetlist.onreadystatechange=function(){
191 if (datasetlist.readyState==4 && datasetlist.status==200){
192 datasetlist=eval('(' + datasetlist.responseText + ')');
193
194 list += '<select id="dataset" style="width:104px"><option></option>';
195 for (var i=0; i<datasetlist.length; i++){
196 list += '<option>' + datasetlist[i].fields.naam + '</option>';
197 }
198 list += '</select> Dataset<br />';
199
200 document.getElementById('filter_list').innerHTML=list;
201 }
202 }
203
204
205 list += '<input type="text" id="enc" name="enc" size="10"/> Encrypted<br />';
206 list += '<input type="text" id="colour" name="colour" size="10"/> Colour<br />';
207 list += '<input type="text" id="lname" name="lname" size="10"/> Layername<br />';
208 list += '<input type="button" value="Add filter" onClick="addFilter()"/>';
209 list += '</form>';
210
211
212
213
214
215 nodelist.open("GET","/website/filters/1",true);
216 nodelist.send();
217 userlist.open("GET","/website/filters/2",true);
218 userlist.send();
219 datasetlist.open("GET","/website/filters/3",true);
220 datasetlist.send();
221}
222*/
Note: See TracBrowser for help on using the repository browser.