From dbc4875e553af4d617bba3d2450562c0671aea95 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 30 Dec 2013 02:38:49 +0000 Subject: improved reload control --- map.js | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'map.js') diff --git a/map.js b/map.js index 56212d6..8f7a088 100644 --- a/map.js +++ b/map.js @@ -37,9 +37,7 @@ function initialize(lat, lng, res) { //##// map.addControl(new RulerControl()); var reloadconDiv = document.createElement('div'); - var reloadcon = new ReloadControl(reloadconDiv, map); - - reloadconDiv.index = 1; + reloadcon = new ReloadControl(reloadconDiv, map); map.controls[google.maps.ControlPosition.TOP_RIGHT].push(reloadconDiv); google.maps.event.addListener(map, "click", onMapClick); @@ -58,8 +56,7 @@ function initialize(lat, lng, res) { countboxText = document.createTextNode("Aktiv: 0"); countbox.appendChild(countboxText); - reloadcon.started(); - $.get( "data.php",onData); + reloadcon.reload(); } function onMapClick(mouse_event) @@ -68,11 +65,10 @@ function onMapClick(mouse_event) setNewMarker(mouse_event.latLng); } -//##//function onData(data, responseCode) { -//##// if (responseCode < 200 || responseCode > 299) { -//##// reloadcon.finished(); -//##// return alert("Fehler: Konnte die Daten nicht laden!\n(Server Antwort-Code: " + responseCode + ")"); -//##// } +function onDataErr() { + reloadcon.finished(); +} + function onData(xmlData) { reloadcon.loaded(); @@ -528,8 +524,7 @@ function onFFLogin(xmlData) { if(status[0].getAttribute("code") == "logged_in") { var username = xmlData.getElementsByTagName("username")[0].getAttribute("name"); showFFLogout(username); - reloadcon.started(); - $.get( "data.php",onData); + reloadcon.reload(); } } } @@ -560,8 +555,7 @@ function onFFLogout(xmlData) { } else { showFFLogin(); - reloadcon.started(); - $.get("data.php", onData); + reloadcon.reload(); } } @@ -601,15 +595,15 @@ function ReloadControl(controlDiv, map) { controlText.innerHTML = 'Daten neu laden'; controlUI.appendChild(controlText); - google.maps.event.addDomListener(controlUI, 'click', function() { - controlText.innerHTML = 'wird geladen...'; - $.get("data.php", onData); - }); - var cntrl = new Object(); - cntrl.started = function() { controlText.innerHTML = 'wird geladen...'; } + cntrl.reload = function() { + controlText.innerHTML = 'wird geladen...'; + $.get("data.php", onData).fail(onDataErr); + } cntrl.loaded = function() { controlText.innerHTML = 'wird verarbeitet...'; } cntrl.finished = function() { controlText.innerHTML = 'Daten neu laden'; } + + google.maps.event.addDomListener(controlUI, 'click', cntrl.reload); return cntrl; } -- cgit v1.2.1