mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-18 10:35:27 +00:00
(dashboard) plugin new style ajax poller
use data-plugin to define the data collector (server side api/plugins/ plugin) and data-callback to define the javascript function to call after receiving data. The callback uses 2 parameters (sender, remote data), where sender is the dom attribute on which the data-plugin was defined
This commit is contained in:
parent
8e7bc1f679
commit
df5aa476dd
@ -207,6 +207,39 @@ include("fbegin.inc");?>
|
||||
$("#iform").submit();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* ajax update widget data, searches data-plugin attributes and use function in data-callback to update widget
|
||||
*/
|
||||
function process_widget_data()
|
||||
{
|
||||
var plugins = [];
|
||||
var callbacks = [];
|
||||
// collect plugins and callbacks
|
||||
$("[data-plugin]").each(function(){
|
||||
if (plugins.indexOf($(this).data('plugin')) < 0) {
|
||||
plugins.push($(this).data('plugin'));
|
||||
}
|
||||
if ($(this).data('callback') != undefined) {
|
||||
callbacks.push({'function' : $(this).data('callback'), 'plugin': $(this).data('plugin'), 'sender': $(this)});
|
||||
}
|
||||
})
|
||||
// collect data for provided plugins
|
||||
$.ajax("/widgets/api/get.php",{type: 'get', cache: false, dataType: "json", data: {'load': plugins.join(',')}})
|
||||
.done(function(response) {
|
||||
callbacks.map( function(callback) {
|
||||
try {
|
||||
if (response['data'][callback['plugin']] != undefined) {
|
||||
window[callback['function']](callback['sender'], response['data'][callback['plugin']]);
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
// schedule next update
|
||||
setTimeout('process_widget_data()', 30000);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -221,6 +254,7 @@ include("fbegin.inc");?>
|
||||
showSave();
|
||||
}
|
||||
});
|
||||
// select number of columns
|
||||
$("#column_count").change(function(){
|
||||
if ($("#column_count_input").val() != $("#column_count").val()) {
|
||||
showSave();
|
||||
@ -237,6 +271,8 @@ include("fbegin.inc");?>
|
||||
});
|
||||
});
|
||||
$("#column_count").change();
|
||||
// trigger initial ajax data poller
|
||||
process_widget_data();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user