mirror of
https://github.com/transmission/transmission
synced 2025-02-20 13:16:53 +00:00
(trunk web) code cleanup in torrent-row: (1) add a progressbar builder helper function to reduce redundant code between the different view types (2) decouple TorrentRow's constructor from transmission.js
This commit is contained in:
parent
7efc1af537
commit
2efb69dda3
2 changed files with 35 additions and 44 deletions
|
@ -44,15 +44,28 @@ TorrentRendererHelper.getProgressInfo = function( controller, t )
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentRendererHelper.renderProgressbar = function( controller, t, complete, incomplete )
|
TorrentRendererHelper.createProgressbar = function( classes )
|
||||||
|
{
|
||||||
|
var complete = document.createElement( 'div' );
|
||||||
|
complete.className = 'torrent_progress_bar complete';
|
||||||
|
var incomplete = document.createElement( 'div' );
|
||||||
|
incomplete.className = 'torrent_progress_bar incomplete';
|
||||||
|
var progressbar = document.createElement( 'div' );
|
||||||
|
progressbar.className = 'torrent_progress_bar_container ' + classes;
|
||||||
|
progressbar.appendChild( complete );
|
||||||
|
progressbar.appendChild( incomplete );
|
||||||
|
return { 'element': progressbar, 'complete': complete, 'incomplete': incomplete }
|
||||||
|
}
|
||||||
|
|
||||||
|
TorrentRendererHelper.renderProgressbar = function( controller, t, progressbar )
|
||||||
{
|
{
|
||||||
var info = TorrentRendererHelper.getProgressInfo( controller, t );
|
var info = TorrentRendererHelper.getProgressInfo( controller, t );
|
||||||
var e;
|
var e;
|
||||||
e = complete;
|
e = progressbar.complete;
|
||||||
e.style.width = '' + info.percent + "%";
|
e.style.width = '' + info.percent + "%";
|
||||||
e.className = info.complete;
|
e.className = info.complete;
|
||||||
e.style.display = info.percent<=0 ? 'none' : 'block';
|
e.style.display = info.percent<=0 ? 'none' : 'block';
|
||||||
e = incomplete;
|
e = progressbar.incomplete;
|
||||||
e.className = info.incomplete;
|
e.className = info.incomplete;
|
||||||
e.style.display = info.percent>=100 ? 'none' : 'block';
|
e.style.display = info.percent>=100 ? 'none' : 'block';
|
||||||
}
|
}
|
||||||
|
@ -88,14 +101,7 @@ TorrentRendererFull.prototype =
|
||||||
var peers = document.createElement( 'div' );
|
var peers = document.createElement( 'div' );
|
||||||
peers.className = 'torrent_peer_details';
|
peers.className = 'torrent_peer_details';
|
||||||
|
|
||||||
var complete = document.createElement( 'div' );
|
var progressbar = TorrentRendererHelper.createProgressbar( 'full' );
|
||||||
complete.className = 'torrent_progress_bar complete';
|
|
||||||
var incomplete = document.createElement( 'div' );
|
|
||||||
incomplete.className = 'torrent_progress_bar incomplete';
|
|
||||||
var progressbar = document.createElement( 'div' );
|
|
||||||
progressbar.className = 'torrent_progress_bar_container full';
|
|
||||||
progressbar.appendChild( complete );
|
|
||||||
progressbar.appendChild( incomplete );
|
|
||||||
|
|
||||||
var details = document.createElement( 'div' );
|
var details = document.createElement( 'div' );
|
||||||
details.className = 'torrent_progress_details';
|
details.className = 'torrent_progress_details';
|
||||||
|
@ -107,14 +113,13 @@ TorrentRendererFull.prototype =
|
||||||
root.appendChild( name );
|
root.appendChild( name );
|
||||||
root.appendChild( peers );
|
root.appendChild( peers );
|
||||||
root.appendChild( button );
|
root.appendChild( button );
|
||||||
root.appendChild( progressbar );
|
root.appendChild( progressbar.element );
|
||||||
root.appendChild( details );
|
root.appendChild( details );
|
||||||
|
|
||||||
root._name_container = name;
|
root._name_container = name;
|
||||||
root._peer_details_container = peers;
|
root._peer_details_container = peers;
|
||||||
root._progress_details_container = details;
|
root._progress_details_container = details;
|
||||||
root._progress_complete_container = complete;
|
root._progressbar = progressbar;
|
||||||
root._progress_incomplete_container = incomplete;
|
|
||||||
root._pause_resume_button_image = image;
|
root._pause_resume_button_image = image;
|
||||||
root._toggle_running_button = button;
|
root._toggle_running_button = button;
|
||||||
|
|
||||||
|
@ -205,10 +210,7 @@ TorrentRendererFull.prototype =
|
||||||
setInnerHTML( root._name_container, t.name() );
|
setInnerHTML( root._name_container, t.name() );
|
||||||
|
|
||||||
// progressbar
|
// progressbar
|
||||||
TorrentRendererHelper.renderProgressbar(
|
TorrentRendererHelper.renderProgressbar( controller, t, root._progressbar );
|
||||||
controller, t,
|
|
||||||
root._progress_complete_container,
|
|
||||||
root._progress_incomplete_container );
|
|
||||||
|
|
||||||
// peer details
|
// peer details
|
||||||
var has_error = t._error !== Torrent._ErrNone;
|
var has_error = t._error !== Torrent._ErrNone;
|
||||||
|
@ -240,14 +242,7 @@ TorrentRendererCompact.prototype =
|
||||||
{
|
{
|
||||||
createRow: function( )
|
createRow: function( )
|
||||||
{
|
{
|
||||||
var complete = document.createElement( 'div' );
|
var progressbar = TorrentRendererHelper.createProgressbar( 'compact' );
|
||||||
complete.className = 'torrent_progress_bar complete';
|
|
||||||
var incomplete = document.createElement( 'div' );
|
|
||||||
incomplete.className = 'torrent_progress_bar incomplete';
|
|
||||||
var progressbar = document.createElement( 'div' );
|
|
||||||
progressbar.className = 'torrent_progress_bar_container compact';
|
|
||||||
progressbar.appendChild( complete );
|
|
||||||
progressbar.appendChild( incomplete );
|
|
||||||
|
|
||||||
var details = document.createElement( 'div' );
|
var details = document.createElement( 'div' );
|
||||||
details.className = 'torrent_peer_details compact';
|
details.className = 'torrent_peer_details compact';
|
||||||
|
@ -256,12 +251,11 @@ TorrentRendererCompact.prototype =
|
||||||
name.className = 'torrent_name';
|
name.className = 'torrent_name';
|
||||||
|
|
||||||
var root = document.createElement( 'li' );
|
var root = document.createElement( 'li' );
|
||||||
root.appendChild( progressbar );
|
root.appendChild( progressbar.element );
|
||||||
root.appendChild( details );
|
root.appendChild( details );
|
||||||
root.appendChild( name );
|
root.appendChild( name );
|
||||||
root.className = 'torrent compact';
|
root.className = 'torrent compact';
|
||||||
root._progress_complete_container = complete;
|
root._progressbar = progressbar;
|
||||||
root._progress_incomplete_container = incomplete;
|
|
||||||
root._details_container = details;
|
root._details_container = details;
|
||||||
root._name_container = name;
|
root._name_container = name;
|
||||||
return root;
|
return root;
|
||||||
|
@ -295,10 +289,7 @@ TorrentRendererCompact.prototype =
|
||||||
setInnerHTML( e, this.getPeerDetails( t ) );
|
setInnerHTML( e, this.getPeerDetails( t ) );
|
||||||
|
|
||||||
// progressbar
|
// progressbar
|
||||||
TorrentRendererHelper.renderProgressbar(
|
TorrentRendererHelper.renderProgressbar( controller, t, root._progressbar );
|
||||||
controller, t,
|
|
||||||
root._progress_complete_container,
|
|
||||||
root._progress_incomplete_container );
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -307,17 +298,15 @@ TorrentRendererCompact.prototype =
|
||||||
*****
|
*****
|
||||||
****/
|
****/
|
||||||
|
|
||||||
function TorrentRow( controller, generator )
|
function TorrentRow( view )
|
||||||
{
|
{
|
||||||
this.initialize( controller, generator );
|
this.initialize( view );
|
||||||
}
|
}
|
||||||
TorrentRow.prototype =
|
TorrentRow.prototype =
|
||||||
{
|
{
|
||||||
initialize: function( controller, generator ) {
|
initialize: function( view ) {
|
||||||
this._generator = generator;
|
this._view = view;
|
||||||
var root = generator.createRow( );
|
this._element = view.createRow( );
|
||||||
this._element = root;
|
|
||||||
$(root).bind('dblclick', function(e) { controller.toggleInspector(); });
|
|
||||||
|
|
||||||
},
|
},
|
||||||
getElement: function( ) {
|
getElement: function( ) {
|
||||||
|
@ -326,7 +315,7 @@ TorrentRow.prototype =
|
||||||
render: function( controller ) {
|
render: function( controller ) {
|
||||||
var tor = this.getTorrent( );
|
var tor = this.getTorrent( );
|
||||||
if( tor !== null )
|
if( tor !== null )
|
||||||
this._generator.render( controller, tor, this.getElement( ) );
|
this._view.render( controller, tor, this.getElement( ) );
|
||||||
},
|
},
|
||||||
isSelected: function( ) {
|
isSelected: function( ) {
|
||||||
return this.getElement().className.indexOf('selected') != -1;
|
return this.getElement().className.indexOf('selected') != -1;
|
||||||
|
@ -351,10 +340,11 @@ TorrentRow.prototype =
|
||||||
|
|
||||||
setTorrent: function( controller, t ) {
|
setTorrent: function( controller, t ) {
|
||||||
if( this._torrent !== t ) {
|
if( this._torrent !== t ) {
|
||||||
|
var key = 'dataChanged.renderer';
|
||||||
if( this._torrent )
|
if( this._torrent )
|
||||||
$(this).unbind('dataChanged.renderer');
|
$(this).unbind(key);
|
||||||
if(( this._torrent = t ))
|
if(( this._torrent = t ))
|
||||||
$(this).bind('dataChanged.renderer',this.render(controller));
|
$(this).bind(key,this.render(controller));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getTorrent: function() {
|
getTorrent: function() {
|
||||||
|
|
|
@ -2204,7 +2204,7 @@ Transmission.prototype =
|
||||||
var tr = this;
|
var tr = this;
|
||||||
var fragment = document.createDocumentFragment( );
|
var fragment = document.createDocumentFragment( );
|
||||||
while( this._rows.length < keep.length ) {
|
while( this._rows.length < keep.length ) {
|
||||||
var row = new TorrentRow( this, this.torrentRenderer );
|
var row = new TorrentRow( this.torrentRenderer );
|
||||||
if( !iPhone ) {
|
if( !iPhone ) {
|
||||||
var b = row.getToggleRunningButton( );
|
var b = row.getToggleRunningButton( );
|
||||||
if( b !== null ) {
|
if( b !== null ) {
|
||||||
|
@ -2212,6 +2212,7 @@ Transmission.prototype =
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$(row.getElement()).bind('click',{r: row}, function(ev){ tr.onRowClicked(ev,ev.data.r);});
|
$(row.getElement()).bind('click',{r: row}, function(ev){ tr.onRowClicked(ev,ev.data.r);});
|
||||||
|
$(row.getElement()).bind('dblclick', function(e) { tr.toggleInspector(); });
|
||||||
fragment.appendChild( row.getElement() );
|
fragment.appendChild( row.getElement() );
|
||||||
this._rows.push( row );
|
this._rows.push( row );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue