diff options
author | Vinicius Coque <vcoque@gmail.com> | 2011-09-20 21:25:24 -0300 |
---|---|---|
committer | Vinicius Coque <vinicius.coque@bluepex.com> | 2011-09-27 19:31:19 -0300 |
commit | b1678e2d72a59dc066eb09c24240877fe4553f58 (patch) | |
tree | 860d029c439ec3637c2d1bda22290a086b8d3879 /usr/local/www | |
parent | 9cd55a6611f117ae7330cbfdf79649ae1408f351 (diff) | |
download | pfsense-b1678e2d72a59dc066eb09c24240877fe4553f58.zip pfsense-b1678e2d72a59dc066eb09c24240877fe4553f58.tar.gz |
Convert dashboard ajax code from Prototype to jQuery
Diffstat (limited to 'usr/local/www')
-rwxr-xr-x | usr/local/www/index.php | 17 | ||||
-rw-r--r-- | usr/local/www/javascript/index/ajax.js | 96 |
2 files changed, 58 insertions, 55 deletions
diff --git a/usr/local/www/index.php b/usr/local/www/index.php index 1638196..d763230 100755 --- a/usr/local/www/index.php +++ b/usr/local/www/index.php @@ -261,24 +261,27 @@ function widgetAjax(widget) { uri = "widgets/widgets/" + widget + ".widget.php"; var opt = { // Use GET - method: 'get', + type: 'get', evalScripts: 'true', - asynchronous: true, + async: true, // Handle 404 - on404: function(t) { - alert('Error 404: location "' + t.statusText + '" was not found.'); + statusCode: { + 404: function(t) { + alert('Error 404: location "' + t.statusText + '" was not found.'); + } }, // Handle other errors - onFailure: function(t) { + error: function(t) { alert('Error ' + t.status + ' -- ' + t.statusText); }, - onSuccess: function(t) { + success: function(data) { widget2 = widget + "-loader"; Effect.Fade(widget2, {queue:'front'}); Effect.Appear(widget, {queue:'end'}); + jQuery('#' + widget).html(data); } } - new Ajax.Updater(widget, uri, opt); + jQuery.ajax(uri, opt); } diff --git a/usr/local/www/javascript/index/ajax.js b/usr/local/www/javascript/index/ajax.js index 5b18480..6fd26d7 100644 --- a/usr/local/www/javascript/index/ajax.js +++ b/usr/local/www/javascript/index/ajax.js @@ -6,14 +6,14 @@ var update_interval = 11000; function updateMeters() { - url = '/getstats.php' + url = '/getstats.php'; - new Ajax.Request(url, { - method: 'get', - onSuccess: function(transport) { - response = transport.responseText || ""; + jQuery.ajax(url, { + type: 'get', + success: function(data) { + response = data || ""; if (response != "") - stats(transport.responseText); + stats(data); } }); setTimeout('updateMeters()', update_interval); @@ -41,21 +41,21 @@ function stats(x) { } function updateMemory(x) { - if($('memusagemeter')) - $("memusagemeter").value = x + '%'; - if($('memwidtha')) - $("memwidtha").style.width = x + 'px'; - if($('memwidthb')) - $("memwidthb").style.width = (100 - x) + 'px'; + if(jQuery('#memusagemeter')) + jQuery("#memusagemeter").val(x + '%'); + if(jQuery('#memwidtha')) + jQuery("#memwidtha").css('width',x + 'px'); + if(jQuery('#memwidthb')) + jQuery("#memwidthb").css('width', (100 - x) + 'px'); } function updateCPU(x) { - if($('cpumeter')) - $("cpumeter").value = x + '%'; - if($('cpuwidtha')) - $("cpuwidtha").style.width = x + 'px'; - if($('cpuwidthb')) - $("cpuwidthb").style.width = (100 - x) + 'px'; + if(jQuery('#cpumeter')) + jQuery("#cpumeter").val(x + '%'); + if(jQuery('#cpuwidtha')) + jQuery("#cpuwidtha").css('width',x + 'px'); + if(jQuery('#cpuwidthb')) + jQuery("#cpuwidthb").css('width',(100 - x) + 'px'); /* Load CPU Graph widget if enabled */ if(widgetActive('cpu_graphs')) { GraphValue(graph[0], x); @@ -63,34 +63,34 @@ function updateCPU(x) { } function updateTemp(x) { - if($("tempmeter")) { - $("tempmeter").value = x + 'C'; - $("tempwidtha").style.width = x + 'px'; - $("tempwidthb").style.width = (100 - x) + 'px'; + if(jQuery("#tempmeter")) { + jQuery("#tempmeter").val(x + 'C'); + jQuery("#tempwidtha").css('width',x + 'px'); + jQuery("#tempwidthb").css('width',(100 - x) + 'px'); } } function updateDateTime(x) { - if($('datetime')) - $("datetime").firstChild.data = x; + if(jQuery('#datetime')) + jQuery("#datetime").html(x); } function updateUptime(x) { - if($('uptime')) - $("uptime").value = x; + if(jQuery('#uptime')) + jQuery("#uptime").val(x); } function updateState(x) { - if($('pfstate')) - $("pfstate").value = x; + if(jQuery('#pfstate')) + jQuery("#pfstate").val(x); } function updateGatewayStats(x){ if (widgetActive("gateways")){ gateways_split = x.split(","); for (var y=0; y<gateways_split.length; y++){ - if($('gateway' + (y + 1))) { - $('gateway' + (y + 1)).update(gateways_split[y]); + if(jQuery('#gateway' + (y + 1))) { + jQuery('#gateway' + (y + 1)).html(gateways_split[y]); } } } @@ -101,8 +101,8 @@ function updateInterfaceStats(x){ statistics_split = x.split(","); var counter = 1; for (var y=0; y<statistics_split.length-1; y++){ - if($('stat' + counter)) { - $('stat' + counter).update(statistics_split[y]); + if(jQuery('#stat' + counter)) { + jQuery('#stat' + counter).html(statistics_split[y]); counter++; } } @@ -116,23 +116,23 @@ function updateInterfaces(x){ details = iface.split(","); switch(details[1]) { case "up": - $(details[0] + '-up').style.display = "inline"; - $(details[0] + '-down').style.display = "none"; - $(details[0] + '-block').style.display = "none"; - $(details[0] + '-ip').update(details[2]); - $(details[0] + '-media').update(details[3]); + jQuery('#' + details[0] + '-up').css("display","inline"); + jQuery('#' + details[0] + '-down').css("display","none"); + jQuery('#' + details[0] + '-block').css("display","none"); + jQuery('#' + details[0] + '-ip').html(details[2]); + jQuery('#' + details[0] + '-media').html(details[3]); break; case "down": - $(details[0] + '-down').style.display = "inline"; - $(details[0] + '-up').style.display = "none"; - $(details[0] + '-block').style.display = "none"; - $(details[0] + '-ip').update(details[2]); - $(details[0] + '-media').update(details[3]); + jQuery('#' + details[0] + '-down').css("display","inline"); + jQuery('#' + details[0] + '-up').css("display","none"); + jQuery('#' + details[0] + '-block').css("display","none"); + jQuery('#' + details[0] + '-ip').html(details[2]); + jQuery('#' + details[0] + '-media').html(details[3]); break; case "block": - $(details[0] + '-block').style.display = "inline"; - $(details[0] + '-down').style.display = "none"; - $(details[0] + '-up').style.display = "none"; + jQuery('#' + details[0] + '-block').css("display","inline"); + jQuery('#' + details[0] + '-down').css("display","none"); + jQuery('#' + details[0] + '-up').css("display","none"); break; } }); @@ -140,15 +140,15 @@ function updateInterfaces(x){ } function widgetActive(x) { - var widget = $(x + '-container'); - if ((widget != null) && (widget.style.display != "none")) + var widget = jQuery('#' + x + '-container'); + if ((widget != null) && (widget.css('display') != "none")) return true; else return false; } /* start updater */ -document.observe('dom:loaded', function(){ +jQuery(document).ready(function(){ setTimeout('updateMeters()', update_interval); }); |