(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

@ -63,7 +63,7 @@
</div>
<div id="torrent_inspector" style="display:none;">
<div style="display:none;" class="inspector_close" id="inspector_close"><img id="inspector_close_image" src="./images/buttons/cancel.png"/></div>
<div style="display:none;" class="inspector_close" id="inspector_close"><img id="inspector_close_image" src="./images/buttons/cancel.png"/></div>
<div id="inspector_tabs">
<div class="inspector_tab selected" id="inspector_tab_info"><a href="#info"><img src="images/buttons/info_general.png" alt="Information"/></a></div>
@ -174,7 +174,12 @@
</div><!-- id="inspector_tab_activity_container" -->
<div style="display:none;" class="inspector_container" id="inspector_tab_files_container">
<div id="inspector_file_list"></div>
<div id="inspector_file_list">
<ul id="select_all_button_container">
<li id="files_deselect_all" class="select_all_button">Deselect All</li>
<li id="files_select_all" class="select_all_button">Select All</li>
</ul>
</div>
</div><!-- id="inspector_tab_files_container" -->
</div>

View File

@ -808,18 +808,20 @@ TorrentFile.prototype = {
}
},
setWanted: function(wanted) {
setWanted: function(wanted, process) {
this._dirty = true;
this._wanted = wanted;
if(!iPhone)
this.element().toggleClass( 'skip', !wanted );
var command = wanted ? 'files-wanted' : 'files-unwanted';
this._torrent._controller.changeFileCommand(command, this._torrent, this);
if (process) {
var command = wanted ? 'files-wanted' : 'files-unwanted';
this._torrent._controller.changeFileCommand(command, this._torrent, this);
}
},
toggleWanted: function() {
if (this.isEditable())
this.setWanted( !this._wanted );
this.setWanted( !this._wanted, true );
},
refreshHTML: function() {

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();
}
}
},

View File

@ -154,10 +154,12 @@ TransmissionRemote.prototype =
} );
},
sendTorrentActionRequests: function( method, torrent_ids, callback ) {
sendTorrentSetRequests: function( method, torrent_ids, args, callback ) {
if (!args) args = { };
args['ids'] = torrent_ids;
var o = {
method: method,
arguments: { ids: torrent_ids }
arguments: args
};
this.sendRequest( o, function( data ) {
@ -165,6 +167,10 @@ TransmissionRemote.prototype =
});
},
sendTorrentActionRequests: function( method, torrent_ids, callback ) {
this.sendTorrentSetRequests( method, torrent_ids, null, callback );
},
startTorrents: function( torrent_ids, callback ) {
this.sendTorrentActionRequests( 'torrent-start', torrent_ids, callback );
},
@ -217,5 +223,11 @@ TransmissionRemote.prototype =
this.sendRequest( o, function() {
remote._controller.loadDaemonPrefs();
} );
},
filesSelectAll: function( torrent_ids, files, callback ) {
this.sendTorrentSetRequests( 'torrent-set', torrent_ids, { 'files-wanted': files }, callback );
},
filesDeselectAll: function( torrent_ids, files, callback ) {
this.sendTorrentSetRequests( 'torrent-set', torrent_ids, { 'files-unwanted': files }, callback );
}
};

View File

@ -566,7 +566,7 @@ div#inspector_tabs {
background-position: left -26px; /* the highlighted part of the image */
}
.inspector_container {
margin: 3%;
margin: 0 3%;
width: 96%;
}
.inspector_group {
@ -601,6 +601,19 @@ div#inspector_tabs {
cursor: default;
overflow: hidden;
}
#inspector_file_list #select_all_button_container {
margin: 0;
}
#inspector_file_list ul li.select_all_button {
background: transparent url(../images/buttons/tab_backgrounds.png) repeat-x scroll left -6px;
border: 1px solid #888888;
cursor: pointer;
float: right;
list-style-type: none;
margin: 2px;
padding: 2px 5px;
}
ul.inspector_torrent_file_list {
width: 100%;
margin: 0 0 0 0;
@ -611,6 +624,7 @@ ul.inspector_torrent_file_list {
list-style-type: none;
list-style: none;
list-style-image: none;
clear: both;
}
li.inspector_torrent_file_list_entry {
padding: 3px 0 3px 2px;
@ -633,9 +647,6 @@ div.inspector_torrent_file_list_entry_name {
li.inspector_torrent_file_list_entry.skip>.inspector_torrent_file_list_entry_name {
color: #666;
}
li.inspector_torrent_file_list_entry.even {
background-color: #EEEEEE;
}
div.inspector_torrent_file_list_entry_progress {
font-size: 1em;
color: #666;