--- a/static/dhcp/hosts.js Tue Feb 24 12:47:09 2015 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,114 +0,0 @@
-/* http://fgnass.github.com/spin.js/ */
-$.fn.spin = function(opts) {
- this.each(function() {
- var $this = $(this),
- data = $this.data();
-
- if (data.spinner) {
- data.spinner.stop();
- delete data.spinner;
- }
- if (opts !== false) {
- data.spinner = new Spinner($.extend({color: $this.css('color')}, opts)).spin(this);
- }
- });
- return this;
-};
-
-$.fn.disabled = function (disabled) {
- if (disabled)
- this.attr('disabled', 'disabled');
- else
- this.removeAttr('disabled');
-
- return this;
-};
-
-var Timer = function (interval, cb) {
- var handle = null;
-
- this.enable = function () {
- if (handle) return;
-
- handle = window.setInterval(cb, interval);
- };
-
- this.disable = function () {
- if (!handle) return;
-
- window.clearInterval(handle);
- handle = null;
- };
-
- return this;
-};
-
-/*
- * Initialize the realtime host table.
- *
- * table - Table to manipulate
- * url - base URL for ?t=...
- * filters - { attr: value } for ?t=...
- * t - ?t=... to poll for
- *
- * $(document).ready(HostsRealtime(Table(...), ...));
- *
- */
-function HostsRealtime (table, params) {
- var t = params.t;
- var refreshTimer = Timer(2 * 1000, refresh);
-
- // XXX: refresh > interval?
- function refresh () {
- console.log("refresh: " + t);
-
- var refresh = $('#refresh').disabled(true);
- var spinner = $('#wrapper').spin();
-
- var url = params.url;
- var query = $.param($.extend(params.filters, {t: t }), true); // using traditional encoding for multi-values
-
- $.getJSON(url, query, function (data) {
- var t1 = data.t;
- var hosts = data.hosts;
-
- console.log("refresh: " + t + " -> " + t1 + ": " + hosts.length);
-
- $.each(hosts, function (i, host) {
- table.update(host);
- });
-
- // update
- t = t1;
-
- }).error(function () {
- alert("Error :(");
-
- // disable auto-refresh
- refreshTimer.disable();
-
- }).complete(function () {
- spinner.spin(false);
- refresh.disabled(false);
- });
- }
-
- return function () {
- // init
- $("#refresh").click(function () {
- // in case diabled on error
- refreshTimer.enable();
- refresh();
- $("#pause").disabled(false);
- });
-
- $("#pause").click(function () {
- console.log("pause");
- refreshTimer.disable();
- $("#pause").disabled(true);
- });
-
- // start auto-refresh
- refreshTimer.enable();
- }
-}