diff --git a/src/usr/local/www/index.php b/src/usr/local/www/index.php index a7dde79bb7..2a053f7609 100644 --- a/src/usr/local/www/index.php +++ b/src/usr/local/www/index.php @@ -529,6 +529,19 @@ function set_widget_checkbox_events(checkbox_panel_ref, all_none_button_id) { }); } +// --------------------- EXPERIMENTAL centralized widget refresh system ------------------------------ +// These need to live outsie of the events.push() function to enable the widgets to see them +var ajaxspecs = new Array(); // Array to hold widget refresh specifications (objects ) +var ajaxidx = 0; +var ajaxmutex = false; +var ajaxcntr = 0; + +// Add a widget refresh object to the array list +function register_ajax(ws) { + ajaxspecs.push(ws); +} +// --------------------------------------------------------------------------------------------------- + events.push(function() { // Make panels destroyable @@ -585,6 +598,55 @@ events.push(function() { $('#btnstore').removeClass("invisible"); } }); + + // --------------------- EXPERIMENTAL centralized widget refresh system ------------------------------ + function make_ajax_call(wd) { + ajaxmutex = true; + + $.ajax({ + type: 'POST', + url: wd.url, + dataType: 'html', + data: wd.parms, + + success: function(data){ + wd.callback(data); + ajaxmutex = false; + }, + + error: function(e){ +// alert("Error: " + e); + ajaxmutex = false; + } + }); + } + + // Loop through each AJAX widget refresh object, make the AJAX call and pass the + // results back to the widget's callback function + function executewidget() { + if (ajaxspecs.length > 0) { + var freq = ajaxspecs[ajaxidx].freq; // widget can specifify it should be called freq times around hte loop + + if (!ajaxmutex) { + if (((ajaxcntr % freq) === 0) && (typeof ajaxspecs[ajaxidx].callback === "function" )) { + make_ajax_call(ajaxspecs[ajaxidx]); + } + + if (++ajaxidx >= ajaxspecs.length) { + ajaxidx = 0; + + if (++ajaxcntr >= 4096) { + ajaxcntr = 0; + } + } + } + + setTimeout(function() { executewidget(); }, 1000); + } + } + + // Kick it off + executewidget(); }); //]]> diff --git a/src/usr/local/www/widgets/widgets/gateways.widget.php b/src/usr/local/www/widgets/widgets/gateways.widget.php index f4408b8374..35abec8668 100644 --- a/src/usr/local/www/widgets/widgets/gateways.widget.php +++ b/src/usr/local/www/widgets/widgets/gateways.widget.php @@ -199,36 +199,6 @@ $widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period - - + + diff --git a/src/usr/local/www/widgets/widgets/interface_statistics.widget.php b/src/usr/local/www/widgets/widgets/interface_statistics.widget.php index ff2cc29c8a..f4e349f2d2 100644 --- a/src/usr/local/www/widgets/widgets/interface_statistics.widget.php +++ b/src/usr/local/www/widgets/widgets/interface_statistics.widget.php @@ -201,31 +201,57 @@ $widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period + diff --git a/src/usr/local/www/widgets/widgets/interfaces.widget.php b/src/usr/local/www/widgets/widgets/interfaces.widget.php index df3b7172db..1337c1ce0e 100644 --- a/src/usr/local/www/widgets/widgets/interfaces.widget.php +++ b/src/usr/local/www/widgets/widgets/interfaces.widget.php @@ -61,7 +61,7 @@ require_once("/usr/local/www/widgets/include/interfaces.inc"); $ifdescrs = get_configured_interface_with_descr(); -if ($_POST) { +if ($_POST && !$_REQUEST['ajax']) { $validNames = array(); @@ -79,9 +79,11 @@ if ($_POST) { header("Location: /index.php"); } +if (!$_REQUEST['ajax']) { ?> -