(trunk web) Add Select / Deselect All buttons to the file listing. Patch from Grug. Fixes #2294

This commit is contained in:
Kevin Glowacz
2009-12-06 03:21:08 +00:00
parent d370222113
commit a53de0d430
5 changed files with 90 additions and 13 deletions

View File

@@ -49,6 +49,8 @@ Transmission.prototype =
$('.inspector_tab').bind('click', function(e){ tr.inspectorTabClicked(e, this); });
$('.file_wanted_control').live('click', function(e){ tr.fileWantedClicked(e, this); });
$('.file_priority_control').live('click', function(e){ tr.filePriorityClicked(e, this); });
$('#files_select_all').live('click', function(e){ tr.filesSelectAllClicked(e, this); });
$('#files_deselect_all').live('click', function(e){ tr.filesDeselectAllClicked(e, this); });
$('#open_link').bind('click', function(e){ tr.openTorrentClicked(e); });
$('#upload_confirm_button').bind('click', function(e){ tr.confirmUploadClicked(e); return false;});
$('#upload_cancel_button').bind('click', function(e){ tr.cancelUploadClicked(e); return false; });
@@ -687,6 +689,26 @@ Transmission.prototype =
this.extractFileFromElement(element).filePriorityControlClicked(event, element);
},
filesSelectAllClicked: function(event) {
var tr = this;
var ids = jQuery.map(this.getSelectedTorrents( ), function(t) { return t.id(); } );
var files_list = this.toggleFilesWantedDisplay(ids, true);
for (i = 0; i < ids.length; ++i) {
if (files_list[i].length)
this.remote.filesSelectAll( [ ids[i] ], files_list[i], function() { tr.refreshTorrents( ids ); } );
}
},
filesDeselectAllClicked: function(event) {
var tr = this;
var ids = jQuery.map(this.getSelectedTorrents( ), function(t) { return t.id(); } );
var files_list = this.toggleFilesWantedDisplay(ids, false);
for (i = 0; i < ids.length; ++i) {
if (files_list[i].length)
this.remote.filesDeselectAll( [ ids[i] ], files_list[i], function() { tr.refreshTorrents( ids ); } );
}
},
extractFileFromElement: function(element) {
var match = $(element).closest('.inspector_torrent_file_list_entry').attr('id').match(/^t(\d+)f(\d+)$/);
var torrent_id = match[1];
@@ -695,6 +717,22 @@ Transmission.prototype =
return torrent._file_view[file_id];
},
toggleFilesWantedDisplay: function(ids, wanted) {
var i, j, k, torrent, files_list = [ ];
for (i = 0; i < ids.length; ++i) {
torrent = this._torrents[ids[i]];
files_list[i] = [ ];
for (j = k = 0; j < torrent._file_view.length; ++j) {
if (torrent._file_view[j].isEditable() && torrent._file_view[j]._wanted != wanted) {
torrent._file_view[j].setWanted(wanted, false);
files_list[i][k++] = j;
}
}
torrent.refreshFileView;
}
return files_list;
},
toggleFilterClicked: function(event) {
if (this.isButtonEnabled(event))
this.toggleFilter();
@@ -1126,8 +1164,17 @@ Transmission.prototype =
updateVisibleFileLists: function() {
if( this.fileListIsVisible( ) === true ) {
jQuery.each( this.getSelectedTorrents(), function() { this.showFileList(); } );
var selected = this.getSelectedTorrents();
jQuery.each( selected, function() { this.showFileList(); } );
jQuery.each( this.getDeselectedTorrents(), function() { this.hideFileList(); } );
// Check if we need to display the select all buttions
if ( !selected.length ) {
if ( $("#select_all_button_container").is(':visible') )
$("#select_all_button_container").hide();
} else {
if ( !$("#select_all_button_container").is(':visible') )
$("#select_all_button_container").show();
}
}
},