return false;
},
- refreshTorrents = function () {
+ refreshTorrents = function (callback) {
var fields,
ids = $.map(data.torrents.slice(0), function (t) {
return t.getId();
$.merge(fields, Torrent.Fields.InfoExtra);
}
- data.controller.updateTorrents(ids, fields);
+ data.controller.updateTorrents(ids, fields, callback);
}
},
****/
this.setTorrents = function (torrents) {
- var d = data;
+ var d = data,
+ that = this;
// update the inspector when a selected torrent's data changes.
$(d.torrents).unbind('dataChanged.inspector');
d.torrents = torrents;
// periodically ask for updates to the inspector's torrents
- clearInterval(d.refreshInterval);
- d.refreshInterval = setInterval($.proxy(refreshTorrents, this), 2000);
+ clearTimeout(d.refreshTimeout);
+
+ function callback() {
+ refreshTorrents(rescheduleTimeout);
+ }
+
+ function rescheduleTimeout() {
+ d.refreshTimeout = setTimeout(callback, 2000);
+ }
+
+ rescheduleTimeout();
refreshTorrents();
// refresh the inspector's UI
this.updateButtonsSoon();
},
- loadDaemonPrefs: function (async) {
+ loadDaemonPrefs: function (async, callback) {
this.remote.loadDaemonPrefs(function (data) {
var o = data['arguments'];
Prefs.getClutchPrefs(o);
this.updateGuiFromSession(o);
this.sessionProperties = o;
+
+ if (callback) {
+ callback();
+ }
}, this, async);
},
// turn the periodic ajax session refresh on & off
togglePeriodicSessionRefresh: function (enabled) {
- clearInterval(this.sessionInterval);
- delete this.sessionInterval;
- if (enabled) {
- var callback = $.proxy(this.loadDaemonPrefs, this);
- var msec = 8000;
+ var that = this,
+ msec = 8000;
- this.sessionInterval = setInterval(callback, msec);
- };
+ function callback() {
+ that.loadDaemonPrefs(undefined, rescheduleTimeout);
+ }
+
+ function rescheduleTimeout() {
+ that.sessionTimeout = setTimeout(callback, msec);
+ }
+
+ clearTimeout(this.sessionTimeout);
+ delete this.sessionTimeout;
+
+ if (enabled) {
+ rescheduleTimeout();
+ }
},
toggleTurtleClicked: function () {
}
},
- updateTorrents: function (ids, fields) {
- this.remote.updateTorrents(ids, fields, this.updateFromTorrentGet, this);
+ updateTorrents: function (ids, fields, callback) {
+ var that = this;
+
+ function f(updates, removedIds) {
+ if (callback) {
+ callback();
+ }
+
+ that.updateFromTorrentGet(updates, removedIds);
+ }
+
+ this.remote.updateTorrents(ids, fields, f);
},
refreshTorrents: function () {
// turn the periodic ajax stats refresh on & off
togglePeriodicStatsRefresh: function (enabled) {
- clearInterval(this.statsInterval);
- delete this.statsInterval;
+ var that = this,
+ msec = 5000;
- if (enabled) {
- var callback = $.proxy(this.loadDaemonStats, this);
- var msec = 5000;
+ function callback() {
+ that.loadDaemonStats(undefined, rescheduleTimeout);
+ }
- this.statsInterval = setInterval(callback, msec);
- };
+ function rescheduleTimeout() {
+ that.statsTimeout = setTimeout(callback, msec);
+ }
+
+ clearTimeout(this.statsTimeout);
+ delete this.statsTimeout;
+
+ if (enabled) {
+ rescheduleTimeout();
+ }
},
- loadDaemonStats: function (async) {
+ loadDaemonStats: function (async, callback) {
this.remote.loadDaemonStats(function (data) {
this.updateStats(data['arguments']);
+
+ if (callback) {
+ callback();
+ }
}, this, async);
},