From 53547a05e07294ef32f2db90e456e009058e1ef5 Mon Sep 17 00:00:00 2001 From: Steve Beaver Date: Tue, 8 Aug 2017 15:51:06 -0400 Subject: [PATCH] Add ipsec widget to new centralized refresh system --- src/usr/local/www/index.php | 4 +- .../www/widgets/widgets/interfaces.widget.php | 3 +- .../www/widgets/widgets/ipsec.widget.php | 49 +++++++++---------- .../netgate_services_and_support.widget.php | 2 +- 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/usr/local/www/index.php b/src/usr/local/www/index.php index c8ea9ce169..e14f2a3367 100644 --- a/src/usr/local/www/index.php +++ b/src/usr/local/www/index.php @@ -569,7 +569,7 @@ 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 each widget refresh specification (object) +var ajaxspecs = new Array(); // Array to hold widget refresh specifications (objects ) var ajaxidx = 0; var ajaxmutex = false; @@ -658,7 +658,7 @@ events.push(function() { } // Loop through each AJAX widget refresh object, make the AJAX call and pass the - //results back to the widget's callback function + // results back to the widget's callback function function executewidget() { if (ajaxspecs.length > 0) { if (!ajaxmutex) { diff --git a/src/usr/local/www/widgets/widgets/interfaces.widget.php b/src/usr/local/www/widgets/widgets/interfaces.widget.php index 60d1240964..fdec201d42 100644 --- a/src/usr/local/www/widgets/widgets/interfaces.widget.php +++ b/src/usr/local/www/widgets/widgets/interfaces.widget.php @@ -221,9 +221,8 @@ if ($_REQUEST['widgetkey']) { // POST data to send via AJAX var postdata = '{"widgetkey":""}'; - // Create aN object defining widget refresh AJAX call + // Create an object defining the widget refresh AJAX call var interfacesObject = new Object(); - interfacesObject.name = "Interfaces"; interfacesObject.url = "/widgets/widgets/interfaces.widget.php"; interfacesObject.callback = interfaces_callback; diff --git a/src/usr/local/www/widgets/widgets/ipsec.widget.php b/src/usr/local/www/widgets/widgets/ipsec.widget.php index ff577b72d3..e1d86a585a 100644 --- a/src/usr/local/www/widgets/widgets/ipsec.widget.php +++ b/src/usr/local/www/widgets/widgets/ipsec.widget.php @@ -291,32 +291,31 @@ function changeTabDIV(selectedDiv) { } } -function get_ipsec_stats_() { - var ajaxRequest; - - ajaxRequest = $.ajax({ - url: "/widgets/widgets/ipsec.widget.php", - type: "post", - data: { - ajax: "ajax", - tab: curtab - } - }); - - // Deal with the results of the above ajax call - ajaxRequest.done(function (response, textStatus, jqXHR) { - - $('tbody', '#-' + curtab).html(response); - - // and do it again - setTimeout(get_ipsec_stats_, ""); - }); -} - events.push(function(){ - // Start polling for updates some small random number of seconds from now (so that all the widgets don't - // hit the server at exactly the same time) - setTimeout(get_ipsec_stats_, Math.floor((Math.random() * 10000) + 1000)); + // --------------------- EXPERIMENTAL centralized widget refresh system ------------------------------ + + // Callback function called by refresh system when data is retrieved + function ipsec_callback(s) { + $('tbody', '#-' + curtab).html(s); + } + + // POST data to send via AJAX + var postdata = { + ajax: "ajax", + tab : curtab + }; + + // Create an object defining the widget refresh AJAX call + var ipsecObject = new Object(); + ipsecObject.name = "IPsec"; + ipsecObject.url = "/widgets/widgets/ipsec.widget.php"; + ipsecObject.callback = ipsec_callback; + ipsecObject.parms = postdata; + + // Register the AJAX object + register_ajax(ipsecObject); + + // --------------------------------------------------------------------------------------------------- }); //]]> diff --git a/src/usr/local/www/widgets/widgets/netgate_services_and_support.widget.php b/src/usr/local/www/widgets/widgets/netgate_services_and_support.widget.php index 8e5066802c..4a045a1b39 100644 --- a/src/usr/local/www/widgets/widgets/netgate_services_and_support.widget.php +++ b/src/usr/local/www/widgets/widgets/netgate_services_and_support.widget.php @@ -1,6 +1,6 @@