mirror of
https://github.com/transmission/transmission
synced 2025-02-20 21:26:53 +00:00
(trunk web) a batch of code cleanups that were too minor for individual commits
This commit is contained in:
parent
8192c38fcc
commit
c113975ec9
1 changed files with 61 additions and 84 deletions
|
@ -73,7 +73,7 @@ Transmission.prototype =
|
||||||
} else {
|
} else {
|
||||||
$(document).bind('keydown', function(e) { tr.keyDown(e); });
|
$(document).bind('keydown', function(e) { tr.keyDown(e); });
|
||||||
$(document).bind('keyup', function(e) { tr.keyUp(e); });
|
$(document).bind('keyup', function(e) { tr.keyUp(e); });
|
||||||
$('#torrent_container').click(function() { tr.deselectAll(true); });
|
$('#torrent_container').click(function() { tr.deselectAll(); });
|
||||||
$('#inspector_link').click(function(e) { tr.toggleInspector(); });
|
$('#inspector_link').click(function(e) { tr.toggleInspector(); });
|
||||||
|
|
||||||
this.setupSearchBox();
|
this.setupSearchBox();
|
||||||
|
@ -213,14 +213,16 @@ Transmission.prototype =
|
||||||
// include transmenu js to save some bandwidth; if we
|
// include transmenu js to save some bandwidth; if we
|
||||||
// start using prefs on iPhone we need to weed
|
// start using prefs on iPhone we need to weed
|
||||||
// transmenu refs out of that too.
|
// transmenu refs out of that too.
|
||||||
|
if (!iPhone)
|
||||||
|
{
|
||||||
|
$('#sort_by_' + this[Prefs._SortMethod]).selectMenuItem();
|
||||||
|
|
||||||
if (!iPhone) $('#sort_by_' + this[Prefs._SortMethod]).selectMenuItem();
|
if (this[Prefs._SortDirection] === Prefs._SortDescending)
|
||||||
|
$('#reverse_sort_order').selectMenuItem();
|
||||||
|
|
||||||
if (!iPhone && (this[Prefs._SortDirection] == Prefs._SortDescending))
|
if (this[Prefs._ShowInspector])
|
||||||
$('#reverse_sort_order').selectMenuItem();
|
this.setInspectorVisible(true);
|
||||||
|
}
|
||||||
if (!iPhone && this[Prefs._ShowInspector])
|
|
||||||
this.setInspectorVisible(true);
|
|
||||||
|
|
||||||
this.initCompactMode();
|
this.initCompactMode();
|
||||||
},
|
},
|
||||||
|
@ -340,15 +342,7 @@ Transmission.prototype =
|
||||||
{
|
{
|
||||||
var torrents = [];
|
var torrents = [];
|
||||||
for (var key in this._torrents)
|
for (var key in this._torrents)
|
||||||
torrents.push(this._torrents[key]);
|
torrents.push(this._torrents[key]);
|
||||||
return torrents;
|
|
||||||
},
|
|
||||||
|
|
||||||
getVisibleTorrents: function()
|
|
||||||
{
|
|
||||||
var torrents = [];
|
|
||||||
for (var i=0, row; row=this._rows[i]; ++i)
|
|
||||||
torrents.push(row.getTorrent());
|
|
||||||
return torrents;
|
return torrents;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -374,8 +368,7 @@ Transmission.prototype =
|
||||||
seedRatioLimit: function() {
|
seedRatioLimit: function() {
|
||||||
if (this._prefs && this._prefs['seedRatioLimited'])
|
if (this._prefs && this._prefs['seedRatioLimited'])
|
||||||
return this._prefs['seedRatioLimit'];
|
return this._prefs['seedRatioLimit'];
|
||||||
else
|
return -1;
|
||||||
return -1;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setPref: function(key, val)
|
setPref: function(key, val)
|
||||||
|
@ -391,32 +384,19 @@ Transmission.prototype =
|
||||||
****/
|
****/
|
||||||
|
|
||||||
getSelectedRows: function() {
|
getSelectedRows: function() {
|
||||||
var s = [];
|
return $.grep(this._rows, function(r) {return r.isSelected();});
|
||||||
for (var i=0, row; row=this._rows[i]; ++i)
|
|
||||||
if (row.isSelected())
|
|
||||||
s.push(row);
|
|
||||||
return s;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getSelectedTorrents: function() {
|
getSelectedTorrents: function() {
|
||||||
var s = this.getSelectedRows();
|
return $.map(this.getSelectedRows(),function(r) {return r.getTorrent();});
|
||||||
for (var i=0, row; row=s[i]; ++i)
|
|
||||||
s[i] = s[i].getTorrent();
|
|
||||||
return s;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getSelectedTorrentIds: function() {
|
getSelectedTorrentIds: function() {
|
||||||
var s = [];
|
return $.map(this.getSelectedRows(),function(r) {return r.getTorrentId();});
|
||||||
for (var i=0, row; row=this._rows[i]; ++i)
|
|
||||||
if (row.isSelected())
|
|
||||||
s.push(row.getTorrentId());
|
|
||||||
return s;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setSelectedRow: function(row) {
|
setSelectedRow: function(row) {
|
||||||
var rows = this.getSelectedRows();
|
$.each(this.getSelectedRows(),function(i,r) {r.setSelected(false);});
|
||||||
for (var i=0, r; r=rows[i]; ++i)
|
|
||||||
this.deselectRow(r);
|
|
||||||
this.selectRow(row);
|
this.selectRow(row);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -431,13 +411,11 @@ Transmission.prototype =
|
||||||
},
|
},
|
||||||
|
|
||||||
selectAll: function() {
|
selectAll: function() {
|
||||||
for (var i=0, row; row=this._rows[i]; ++i)
|
$.each(this._rows, function(i,r) {r.setSelected(true);});
|
||||||
this.selectRow(row);
|
|
||||||
this.callSelectionChangedSoon();
|
this.callSelectionChangedSoon();
|
||||||
},
|
},
|
||||||
deselectAll: function() {
|
deselectAll: function() {
|
||||||
for (var i=0, row; row=this._rows[i]; ++i)
|
$.each(this._rows, function(i,r) {r.setSelected(false);});
|
||||||
this.deselectRow(row);
|
|
||||||
this.callSelectionChangedSoon();
|
this.callSelectionChangedSoon();
|
||||||
delete this._last_torrent_clicked;
|
delete this._last_torrent_clicked;
|
||||||
},
|
},
|
||||||
|
@ -521,16 +499,17 @@ Transmission.prototype =
|
||||||
i = (i || rows.length) - 1;
|
i = (i || rows.length) - 1;
|
||||||
var r = rows[i];
|
var r = rows[i];
|
||||||
|
|
||||||
if (this._shift_index >= 0)
|
var anchor = this._shift_index;
|
||||||
|
if (anchor >= 0)
|
||||||
{
|
{
|
||||||
// user is extending the selection with the shift + arrow keys...
|
// user is extending the selection with the shift + arrow keys...
|
||||||
if ( ((this._shift_index <= last) && (last < i))
|
if ( ((anchor <= last) && (last < i))
|
||||||
|| ((this._shift_index >= last) && (last > i)))
|
|| ((anchor >= last) && (last > i)))
|
||||||
{
|
{
|
||||||
this.selectRow(r);
|
this.selectRow(r);
|
||||||
}
|
}
|
||||||
else if (((this._shift_index >= last) && (i > last))
|
else if (((anchor >= last) && (i > last))
|
||||||
|| ((this._shift_index <= last) && (last > i)))
|
|| ((anchor <= last) && (last > i)))
|
||||||
{
|
{
|
||||||
this.deselectRow(rows[last]);
|
this.deselectRow(rows[last]);
|
||||||
}
|
}
|
||||||
|
@ -720,27 +699,6 @@ Transmission.prototype =
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
filesSelectAllClicked: function() {
|
|
||||||
var t = this._file_torrent;
|
|
||||||
if (t)
|
|
||||||
this.toggleFilesWantedDisplay(t, true);
|
|
||||||
},
|
|
||||||
filesDeselectAllClicked: function() {
|
|
||||||
var t = this._file_torrent;
|
|
||||||
if (t)
|
|
||||||
this.toggleFilesWantedDisplay(t, false);
|
|
||||||
},
|
|
||||||
toggleFilesWantedDisplay: function(torrent, wanted) {
|
|
||||||
var rows = [ ];
|
|
||||||
for (var i=0, row; row=this._file_rows[i]; ++i)
|
|
||||||
if (row.isEditable() && (torrent.getFile(i).wanted !== wanted))
|
|
||||||
rows.push(row);
|
|
||||||
if (rows.length > 0) {
|
|
||||||
var command = wanted ? 'files-wanted' : 'files-unwanted';
|
|
||||||
this.changeFileCommand(command, rows);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 'Clutch Preferences' was clicked (iPhone only)
|
* 'Clutch Preferences' was clicked (iPhone only)
|
||||||
*/
|
*/
|
||||||
|
@ -955,22 +913,20 @@ Transmission.prototype =
|
||||||
*/
|
*/
|
||||||
updateStats: function(stats)
|
updateStats: function(stats)
|
||||||
{
|
{
|
||||||
// can't think of a reason to remember this
|
|
||||||
//this._stats = stats;
|
|
||||||
|
|
||||||
var fmt = Transmission.fmt;
|
var fmt = Transmission.fmt;
|
||||||
var session = stats["current-stats"];
|
|
||||||
var total = stats["cumulative-stats"];
|
|
||||||
|
|
||||||
setInnerHTML($('#stats_session_uploaded')[0], fmt.size(session["uploadedBytes"]));
|
var s = stats["current-stats"];
|
||||||
setInnerHTML($('#stats_session_downloaded')[0], fmt.size(session["downloadedBytes"]));
|
$('#stats_session_uploaded').html(fmt.size(s.uploadedBytes));
|
||||||
setInnerHTML($('#stats_session_ratio')[0], fmt.ratioString(Math.ratio(session["uploadedBytes"],session["downloadedBytes"])));
|
$('#stats_session_downloaded').html(fmt.size(s.downloadedBytes));
|
||||||
setInnerHTML($('#stats_session_duration')[0], fmt.timeInterval(session["secondsActive"]));
|
$('#stats_session_ratio').html(fmt.ratioString(Math.ratio(s.uploadedBytes,s.downloadedBytes)));
|
||||||
setInnerHTML($('#stats_total_count')[0], total["sessionCount"] + " times");
|
$('#stats_session_duration').html(fmt.timeInterval(s.secondsActive));
|
||||||
setInnerHTML($('#stats_total_uploaded')[0], fmt.size(total["uploadedBytes"]));
|
|
||||||
setInnerHTML($('#stats_total_downloaded')[0], fmt.size(total["downloadedBytes"]));
|
var t = stats["cumulative-stats"];
|
||||||
setInnerHTML($('#stats_total_ratio')[0], fmt.ratioString(Math.ratio(total["uploadedBytes"],total["downloadedBytes"])));
|
$('#stats_total_count').html(t.sessionCount + " times");
|
||||||
setInnerHTML($('#stats_total_duration')[0], fmt.timeInterval(total["secondsActive"]));
|
$('#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));
|
||||||
},
|
},
|
||||||
|
|
||||||
setSearch: function(search) {
|
setSearch: function(search) {
|
||||||
|
@ -1477,6 +1433,27 @@ Transmission.prototype =
|
||||||
*****
|
*****
|
||||||
****/
|
****/
|
||||||
|
|
||||||
|
filesSelectAllClicked: function() {
|
||||||
|
var t = this._file_torrent;
|
||||||
|
if (t)
|
||||||
|
this.toggleFilesWantedDisplay(t, true);
|
||||||
|
},
|
||||||
|
filesDeselectAllClicked: function() {
|
||||||
|
var t = this._file_torrent;
|
||||||
|
if (t)
|
||||||
|
this.toggleFilesWantedDisplay(t, false);
|
||||||
|
},
|
||||||
|
toggleFilesWantedDisplay: function(torrent, wanted) {
|
||||||
|
var rows = [ ];
|
||||||
|
for (var i=0, row; row=this._file_rows[i]; ++i)
|
||||||
|
if (row.isEditable() && (torrent.getFile(i).wanted !== wanted))
|
||||||
|
rows.push(row);
|
||||||
|
if (rows.length > 0) {
|
||||||
|
var command = wanted ? 'files-wanted' : 'files-unwanted';
|
||||||
|
this.changeFileCommand(command, rows);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
inspectorTabClicked: function(ev, tab)
|
inspectorTabClicked: function(ev, tab)
|
||||||
{
|
{
|
||||||
if (iPhone) ev.stopPropagation();
|
if (iPhone) ev.stopPropagation();
|
||||||
|
@ -1531,6 +1508,7 @@ Transmission.prototype =
|
||||||
var total_verified = 0;
|
var total_verified = 0;
|
||||||
var na = 'N/A';
|
var na = 'N/A';
|
||||||
var tab = this._inspector._info_tab;
|
var tab = this._inspector._info_tab;
|
||||||
|
var fmt = Transmission.fmt;
|
||||||
|
|
||||||
$("#torrent_inspector_size, .inspector_row div").css('color', '#222');
|
$("#torrent_inspector_size, .inspector_row div").css('color', '#222');
|
||||||
|
|
||||||
|
@ -1583,8 +1561,8 @@ Transmission.prototype =
|
||||||
download_dir = text;
|
download_dir = text;
|
||||||
|
|
||||||
hash = t.getHashString();
|
hash = t.getHashString();
|
||||||
pieces = [ t.getPieceCount(), 'pieces @', Transmission.fmt.mem(t.getPieceSize()) ].join(' ');
|
pieces = [ t.getPieceCount(), 'pieces @', fmt.mem(t.getPieceSize()) ].join(' ');
|
||||||
date_created = Transmission.fmt.timestamp(t.getDateCreated());
|
date_created = fmt.timestamp(t.getDateCreated());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i=0, t; t=torrents[i]; ++i) {
|
for (var i=0, t; t=torrents[i]; ++i) {
|
||||||
|
@ -1614,7 +1592,6 @@ Transmission.prototype =
|
||||||
}
|
}
|
||||||
|
|
||||||
var private_string = '';
|
var private_string = '';
|
||||||
var fmt = Transmission.fmt;
|
|
||||||
if (have_private && have_public) private_string = 'Mixed';
|
if (have_private && have_public) private_string = 'Mixed';
|
||||||
else if (have_private) private_string = 'Private Torrent';
|
else if (have_private) private_string = 'Private Torrent';
|
||||||
else if (have_public) private_string = 'Public Torrent';
|
else if (have_public) private_string = 'Public Torrent';
|
||||||
|
@ -1943,8 +1920,8 @@ Transmission.prototype =
|
||||||
else
|
else
|
||||||
text = 'Show <span class="filter-selection">' + state_string + '</span> at <span class="filter-selection">' + tracker_string + '</span>';
|
text = 'Show <span class="filter-selection">' + state_string + '</span> at <span class="filter-selection">' + tracker_string + '</span>';
|
||||||
|
|
||||||
var torrent_count = this.getAllTorrents().length;
|
var torrent_count = Object.keys(this._torrents).length;
|
||||||
var visible_count = this.getVisibleTorrents().length;
|
var visible_count = this._rows.length;
|
||||||
if (torrent_count === visible_count)
|
if (torrent_count === visible_count)
|
||||||
text += ' — ' + torrent_count + ' Transfers';
|
text += ' — ' + torrent_count + ' Transfers';
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue