From 55b54b0dcfac08d4776fc5ad1bea6c00aa921b9d Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 16 Mar 2011 12:13:27 +0100 Subject: [PATCH] fixed automatic refresh and options saving (broken by scope issues) --- htdocs/frontend/javascripts/options.js | 18 ++++++++-------- htdocs/frontend/javascripts/wui.js | 30 +++++++++++++++----------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/htdocs/frontend/javascripts/options.js b/htdocs/frontend/javascripts/options.js index dbc93e9..ab7200f 100644 --- a/htdocs/frontend/javascripts/options.js +++ b/htdocs/frontend/javascripts/options.js @@ -27,9 +27,9 @@ // default time interval to show vz.options = { language: 'de', - backendUrl: '../backend.php', + backendUrl: '../backend.php', // TODO default backend, store backend urls in cookies tuples: 300, - precission: 2, // gets updated via backend + precission: 2, // TODO update from backend capabilities? render: 'lines', refresh: false, defaultInterval: 24*60*60*1000, // 1 day @@ -76,13 +76,13 @@ vz.options.plot = { } vz.options.save = function() { - for (var key in this) { - if (this.hasOwnProperty(key) && - typeof this[key] != 'function' && - typeof this[key] != 'object' && - typeof this[key] != 'undefined') - { - $.setCookie('vz_' + key, this[key]); + for (var key in vz.options) { + if (vz.options.hasOwnProperty(key) && + typeof vz.options[key] != 'function' && + typeof vz.options[key] != 'object' && + typeof vz.options[key] != 'undefined' + ) { + $.setCookie('vz_' + key, vz.options[key]); } } }; diff --git a/htdocs/frontend/javascripts/wui.js b/htdocs/frontend/javascripts/wui.js index a69e1fe..7e6bb9e 100644 --- a/htdocs/frontend/javascripts/wui.js +++ b/htdocs/frontend/javascripts/wui.js @@ -81,15 +81,20 @@ vz.wui.init = function() { // auto refresh if (vz.options.refresh) { $('#refresh').attr('checked', true); - this.timeout = window.setTimeout(this.refresh, 3000); + + var delta = vz.options.plot.xaxis.max - vz.options.plot.xaxis.min; + this.timeout = window.setTimeout( + this.refresh, + (delta / 100 < 3000) ? 3000 : delta / 100 + ); } $('#refresh').change(function() { - if ($(this).attr('checked')) { - vz.options.refresh = true; - this.timeout = window.setTimeout(this.refresh, 3000); + vz.options.refresh = $(this).attr('checked'); + + if (vz.options.refresh) { + vz.wui.timeout = window.setTimeout(vz.wui.refresh, 3000); } else { - vz.options.refresh = false; window.clearTimeout(this.timeout); } }); @@ -245,9 +250,13 @@ vz.wui.refresh = function() { vz.options.plot.xaxis.max = new Date().getTime(); // move plot vz.options.plot.xaxis.min = vz.options.plot.xaxis.max - delta; // move plot - vz.entities.loadData().done(vz.wui.drawPlot); - - this.timeout = window.setTimeout(this.refresh, (delta / 100 < 3000) ? 3000 : delta / 100); // TODO update timeout after zooming + vz.entities.loadData().done(function() { + vz.wui.drawPlot(); + vz.wui.timeout = window.setTimeout( // restart refresh timeout + vz.wui.refresh, // self + (delta / 100 < 3000) ? 3000 : delta / 100 + ); + }); }; /** @@ -423,16 +432,13 @@ vz.entities.showTable = function() { 'Verschieben': function() { try { var queue = new Array; - console.log('moving...'); queue.push(to.addChild(child)); // add to new aggregator if (from !== undefined) { - console.log('remove from aggre'); queue.push(from.removeChild(child)); // remove from aggregator } else { - console.log('remove from cookies'); - queue.push(vz.uuids.remove(child.uuid)); // remove from cookies + vz.uuids.remove(child.uuid); // remove from cookies vz.uuids.save(); } } catch (e) {