// Initialize the implementation fields
this.filterText = '';
- this._torrents = { };
- this._rows = [ ];
- this.dirtyTorrents = { };
+ this._torrents = {};
+ this._rows = [];
+ this.dirtyTorrents = {};
// Initialize the clutch preferences
Prefs.getClutchPrefs(this);
});
},
- /*
- * Create the footer settings menu
- */
createSettingsMenu: function() {
$('#settings_menu').transMenu({
selected_char: '✔',
return torrents;
},
+ getTorrentIds: function(torrents)
+ {
+ return $.map(torrents.slice(0), function(t) {return t.getId();});
+ },
+
scrollToRow: function(row)
{
if (isMobileDevice) // FIXME: why?
},
getSelectedTorrentIds: function() {
- return $.map(this.getSelectedRows(),function(r) {
- return r.getTorrentId();
- });
+ return this.getTorrentIds(this.getSelectedTorrents());
},
setSelectedRow: function(row) {
return -1;
},
- /* Select a range from this torrent to the last clicked torrent */
+ // Select a range from this row to the last clicked torrent
selectRange: function(row)
{
var last = this.indexOfLastTorrent();
callSelectionChangedSoon: function()
{
if (!this.selectionChangedTimer)
- this.selectionChangedTimer =
- setTimeout($.proxy(this.selectionChanged,this),200);
+ {
+ var callback = $.proxy(this.selectionChanged,this),
+ msec = 200;
+ this.selectionChangedTimer = setTimeout(callback, msec);
+ }
},
/*--------------------------------------------
return !handled;
},
- keyUp: function(ev)
- {
+ keyUp: function(ev) {
if (ev.keyCode === 16) // shift key pressed
delete this._shift_index;
},
return true;
},
- drop: function(ev) {
- if (!ev.dataTransfer || !ev.dataTransfer.types) {
+ drop: function(ev)
+ {
+ var i, uri, uris=null,
+ types = ["text/uri-list", "text/plain"];
+ paused = this.shouldAddedTorrentsStart();
+
+ if (!ev.dataTransfer || !ev.dataTransfer.types)
return true;
- }
- ev.preventDefault();
- var uris = null;
- var types = ["text/uri-list", "text/plain"];
- for (var i = 0; i < types.length; ++i) {
- if (ev.dataTransfer.types.contains(types[i])) {
+
+ for (i=0; !uris && i<types.length; ++i)
+ if (ev.dataTransfer.types.contains(types[i]))
uris = ev.dataTransfer.getData(types[i]).split("\n");
- break;
- }
- }
- var paused = this.shouldAddedTorrentsStart();
- for (i = 0; i < uris.length; ++i) {
- var uri = uris[i];
- if (/^#/.test(uri)) {
- // lines which start with "#" are comments
+
+ for (i=0; uri=uris[i]; ++i) {
+ if (/^#/.test(uri)) // lines which start with "#" are comments
continue;
- }
- if (/^[a-z-]+:/i.test(uri)) {
- // close enough to a url
+ if (/^[a-z-]+:/i.test(uri)) // close enough to a url
this.remote.addTorrentByUrl(uri, paused);
- }
}
+
+ ev.preventDefault();
return false;
},
}
},
+ // turn the periodic ajax session refresh on & off
togglePeriodicSessionRefresh: function(enabled) {
- /* Turn the periodic ajax session refresh on & off */
clearInterval(this.sessionInterval);
delete this.sessionInterval;
if (enabled) {
}
},
- /* Turn the periodic ajax stats refresh on & off */
+ // turn the periodic ajax stats refresh on & off
togglePeriodicStatsRefresh: function(enabled) {
clearInterval(this.statsInterval);
delete this.statsInterval;
this.loadDaemonStats();
$('#stats_container').fadeIn();
this.hideMobileAddressbar();
- this.updateButtonStates();
this.togglePeriodicStatsRefresh(true);
},
hideStatsDialog: function() {
$('#stats_container').fadeOut();
this.hideMobileAddressbar();
- this.updateButtonStates();
this.togglePeriodicStatsRefresh(false);
},
- /*
- * Process got some new session stats from the server
- */
+ // Process new session stats from the server
updateStats: function(stats)
{
- var fmt = Transmission.fmt;
+ var s, ratio,
+ fmt = Transmission.fmt;
- var s = stats["current-stats"];
+ s = stats["current-stats"];
+ ratio = Math.ratio(s.uploadedBytes,s.downloadedBytes);
$('#stats_session_uploaded').html(fmt.size(s.uploadedBytes));
$('#stats_session_downloaded').html(fmt.size(s.downloadedBytes));
- $('#stats_session_ratio').html(fmt.ratioString(Math.ratio(s.uploadedBytes,s.downloadedBytes)));
+ $('#stats_session_ratio').html(fmt.ratioString(ratio));
$('#stats_session_duration').html(fmt.timeInterval(s.secondsActive));
- var t = stats["cumulative-stats"];
- $('#stats_total_count').html(t.sessionCount + " times");
- $('#stats_total_uploaded').html(fmt.size(t.uploadedBytes));
- $('#stats_total_downloaded').html(fmt.size(t.downloadedBytes));
- $('#stats_total_ratio').html(fmt.ratioString(Math.ratio(t.uploadedBytes,t.downloadedBytes)));
- $('#stats_total_duration').html(fmt.timeInterval(t.secondsActive));
+ s = stats["cumulative-stats"];
+ ratio = Math.ratio(s.uploadedBytes,s.downloadedBytes);
+ $('#stats_total_count').html(s.sessionCount + " times");
+ $('#stats_total_uploaded').html(fmt.size(s.uploadedBytes));
+ $('#stats_total_downloaded').html(fmt.size(s.downloadedBytes));
+ $('#stats_total_ratio').html(fmt.ratioString(ratio));
+ $('#stats_total_duration').html(fmt.timeInterval(s.secondsActive));
},
setFilterText: function(search) {
{
b = o[RPC._TurtleState];
e = $('#turtle-button');
- text = [ 'Click to ', (b?'disable':'enable'), ' Temporary Speed Limits (',
- fmt.speed(o[RPC._TurtleUpSpeedLimit]), ' up,',
- fmt.speed(o[RPC._TurtleDownSpeedLimit]), ' down)' ].join('');
+ text = [ 'Click to ', (b?'disable':'enable'),
+ ' Temporary Speed Limits (',
+ fmt.speed(o[RPC._TurtleUpSpeedLimit]),
+ ' up,',
+ fmt.speed(o[RPC._TurtleDownSpeedLimit]),
+ ' down)' ].join('');
e.toggleClass('enabled', b);
e.attr('title', text);
}
break;
case 'unlimited_download_rate':
- o = { };
+ o = {};
o[RPC._DownSpeedLimited] = false;
remote.savePrefs(o);
break;
case 'limited_download_rate':
- o = { };
+ o = {};
o[RPC._DownSpeedLimited] = true;
remote.savePrefs(o);
break;
updateFromTorrentGet: function(updates, removed_ids)
{
- var i, o, t, id, needed, needinfo = [];
+ var i, o, t, id, needed, needinfo = [],
+ callback, fields;
for (i=0; o=updates[i]; ++i)
{
else {
t = this._torrents[id] = new Torrent(o);
this.dirtyTorrents[id] = true;
- $(t).bind('dataChanged',$.proxy(this.onTorrentChanged,this));
- // if we need them, ask for fields from the server...
+ callback = $.proxy(this.onTorrentChanged,this);
+ $(t).bind('dataChanged',callback);
+ // do we need more info for this torrent?
if(!('name' in t.fields) || !('status' in t.fields))
needinfo.push(id);
}
if (needinfo.length) {
// whee, new torrents! get their initial information.
- this.updateTorrents(needinfo, ['id'].concat(Torrent.Fields.Metadata, Torrent.Fields.Stats));
+ fields = ['id'].concat(Torrent.Fields.Metadata,
+ Torrent.Fields.Stats);
+ this.updateTorrents(needinfo, fields);
this.refilterSoon();
}
updateTorrents: function(ids, fields)
{
- this.remote.updateTorrents(ids, fields, this.updateFromTorrentGet, this);
+ this.remote.updateTorrents(ids, fields,
+ this.updateFromTorrentGet, this);
},
refreshTorrents: function()
// schedule the next request
clearTimeout(this.refreshTorrentsTimeout);
- this.refreshTorrentsTimeout = setTimeout(callback,msec);
+ this.refreshTorrentsTimeout = setTimeout(callback, msec);
},
initializeTorrents: function()
onRowClicked: function(ev)
{
- var row = ev.currentTarget.row;
+ var meta_key = ev.metaKey || ev.ctrlKey,
+ row = ev.currentTarget.row;
// handle the per-row "torrent_resume" button
if (ev.target.className === 'torrent_resume') {
// but still hide the context menu if it is showing
$('#jqContextMenu').hide();
- // 'Apple' button emulation on PC :
- // Need settable meta-key and ctrl-key variables for mac emulation
- var meta_key = ev.metaKey;
- if (ev.ctrlKey && navigator.appVersion.toLowerCase().indexOf("mac") === -1)
- meta_key = true;
-
- // Shift-Click - selects a range from the last-clicked row to this one
if (isMobileDevice) {
if (row.isSelected())
this.setInspectorVisible(true);
deleteTorrents: function(ids)
{
+ var i, id;
+
if (ids && ids.length)
{
- for (var i=0, id; id=ids[i]; ++i) {
+ for (i=0; id=ids[i]; ++i) {
this.dirtyTorrents[id] = true;
delete this._torrents[id];
}
// Submit the upload form
} else {
- var args = { };
+ var args = {};
var remote = this.remote;
var paused = !$('#torrent_auto_start').is(':checked');
if ('' != $('#torrent_upload_url').val()) {
this.startTorrents([ torrent ], false);
},
- getTorrentIds: function(torrents) {
- return $.map(torrents.slice(0), function(t) {return t.getId();});
- },
startTorrents: function(torrents, force) {
this.remote.startTorrents(this.getTorrentIds(torrents), force,
this.refreshTorrents, this);
var e = this.elements,
haveActive = false,
havePaused = false,
- haveSelection = false,
- haveActiveSelection = false,
- havePausedSelection = false;
+ haveSel = false,
+ haveActiveSel = false,
+ havePausedSel = false;
clearTimeout(this.buttonRefreshTimer);
delete this.buttonRefreshTimer;
var isSelected = row.isSelected();
if (!isStopped) haveActive = true;
if (isStopped) havePaused = true;
- if (isSelected) haveSelection = true;
- if (isSelected && !isStopped) haveActiveSelection = true;
- if (isSelected && isStopped) havePausedSelection = true;
+ if (isSelected) haveSel = true;
+ if (isSelected && !isStopped) haveActiveSel = true;
+ if (isSelected && isStopped) havePausedSel = true;
}
- this.setEnabled(e.toolbar_pause_button, haveActiveSelection);
- this.setEnabled(e.context_pause_button, haveActiveSelection);
- this.setEnabled(e.toolbar_start_button, havePausedSelection);
- this.setEnabled(e.context_start_button, havePausedSelection);
- this.setEnabled(e.context_move_top_button, haveSelection);
- this.setEnabled(e.context_move_up_button, haveSelection);
- this.setEnabled(e.context_move_down_button, haveSelection);
- this.setEnabled(e.context_move_bottom_button, haveSelection);
- this.setEnabled(e.context_start_now_button, havePausedSelection);
- this.setEnabled(e.toolbar_remove_button, haveSelection);
+ this.setEnabled(e.toolbar_pause_button, haveActiveSel);
+ this.setEnabled(e.context_pause_button, haveActiveSel);
+ this.setEnabled(e.toolbar_start_button, havePausedSel);
+ this.setEnabled(e.context_start_button, havePausedSel);
+ this.setEnabled(e.context_move_top_button, haveSel);
+ this.setEnabled(e.context_move_up_button, haveSel);
+ this.setEnabled(e.context_move_down_button, haveSel);
+ this.setEnabled(e.context_move_bottom_button, haveSel);
+ this.setEnabled(e.context_start_now_button, havePausedSel);
+ this.setEnabled(e.toolbar_remove_button, haveSel);
this.setEnabled(e.toolbar_pause_all_button, haveActive);
this.setEnabled(e.toolbar_start_all_button, havePaused);
},
filterSetup: function()
{
- var popup = $('#filter-popup');
+ var tr = this,
+ popup = $('#filter-popup');
+
popup.dialog({
autoOpen: false,
position: isMobileDevice ? 'center' : [40,80],
title: 'Show',
width: 315
});
- var tr = this;
+
$('#filter-button').click(function() {
if (popup.is(":visible"))
popup.dialog('close');
list = this.elements.torrent_list,
old_sel_count = $(list).children('.selected').length;
-
clearTimeout(this.refilterTimer);
delete this.refilterTimer;
// update our implementation fields
this._rows = rows;
- this.dirtyTorrents = { };
+ this.dirtyTorrents = {};
// jquery's even/odd starts with 1 not 0, so invert its logic
e = []
refreshFilterPopup: function()
{
- var tr = this;
+ var i, j, o, s, state, states, counts,
+ sel_state, fragment, div,
+ tor, torrents, name, names,
+ trackers = this.getTrackers(),
+ tr = this;
/***
**** States
***/
- var counts = { };
- var states = [ Prefs._FilterAll,
- Prefs._FilterActive,
- Prefs._FilterDownloading,
- Prefs._FilterSeeding,
- Prefs._FilterPaused,
- Prefs._FilterFinished ];
- for (var i=0, state; state=states[i]; ++i)
+ states = [ Prefs._FilterAll,
+ Prefs._FilterActive,
+ Prefs._FilterDownloading,
+ Prefs._FilterSeeding,
+ Prefs._FilterPaused,
+ Prefs._FilterFinished ];
+
+ counts = {};
+ for (i=0; state=states[i]; ++i)
counts[state] = 0;
- var torrents = this.getAllTorrents();
- for (var i=0, tor; tor=torrents[i]; ++i)
- for (var j=0, s; s=states[j]; ++j)
- if (tor.testState(s))
- counts[s]++;
- var sel_state = tr[Prefs._FilterMode];
- var fragment = document.createDocumentFragment();
- for (var i=0, s; s=states[i]; ++i)
+
+ torrents = this.getAllTorrents();
+ for (i=0; tor=torrents[i]; ++i)
+ for (j=0; state=states[j]; ++j)
+ if (tor.testState(state))
+ counts[state]++;
+
+ sel_state = tr[Prefs._FilterMode];
+ fragment = document.createDocumentFragment();
+ for (i=0; s=states[i]; ++i)
{
- var div = document.createElement('div');
+ div = document.createElement('div');
div.id = 'show-state-' + s;
div.className = 'row' + (s === sel_state ? ' selected':'');
div.innerHTML = '<span class="filter-img"></span>'
**** Trackers
***/
- var trackers = this.getTrackers(),
- name, name=[],
- names = [];
+ names = [];
for (name in trackers)
names.push (name);
names.sort();
- var fragment = document.createDocumentFragment();
- var div = document.createElement('div');
+ fragment = document.createDocumentFragment();
+ div = document.createElement('div');
div.id = 'show-tracker-all';
div.className = 'row' + (tr.filterTracker ? '' : ' selected');
div.innerHTML = '<span class="filter-img"></span>'
$('#filter-popup').dialog('close');
});
fragment.appendChild(div);
- for (var i=0, name; name=names[i]; ++i) {
- var div = document.createElement('div');
- var o = trackers[name];
+ for (i=0; name=names[i]; ++i) {
+ o = trackers[name];
+ div = document.createElement('div');
div.id = 'show-tracker-' + name;
div.className = 'row' + (o.domain === tr.filterTracker ? ' selected':'');
div.innerHTML = '<img class="filter-img" src="http://'+o.domain+'/favicon.ico"/>'
setFilterTracker: function(domain)
{
- this.filterTracker = domain;
-
// update which tracker is selected in the popup
- var key = domain ? this.getReadableDomain(domain) : 'all';
- var id = '#show-tracker-' + key;
+ var key = domain ? this.getReadableDomain(domain) : 'all',
+ id = '#show-tracker-' + key;
$(id).addClass('selected').siblings().removeClass('selected');
+ this.filterTracker = domain;
this.refilter(true);
},
- /* example: "tracker.ubuntu.com" returns "ubuntu.com" */
+ // example: "tracker.ubuntu.com" returns "ubuntu.com"
getDomainName: function(host)
{
var dot = host.indexOf('.');
return host;
},
- /* example: "ubuntu.com" returns "Ubuntu" */
+ // example: "ubuntu.com" returns "Ubuntu"
getReadableDomain: function(name)
{
if (name.length)
var domain = this.getDomainName(uri.host);
var name = this.getReadableDomain(domain);
if (!(name in ret))
- ret[name] = { 'uri': uri, 'domain': domain, 'count': 0 };
+ ret[name] = { 'uri': uri,
+ 'domain': domain,
+ 'count': 0 };
if (names.indexOf(name) === -1)
names.push(name);
}