(trunk clutch) only update the file list's html elements when the model's contents actually require it.
This commit is contained in:
parent
acb3b443f7
commit
b18acea58d
|
@ -178,8 +178,8 @@ Torrent.prototype =
|
||||||
totalSeeders: function() { return this._total_seeders; },
|
totalSeeders: function() { return this._total_seeders; },
|
||||||
uploadSpeed: function() { return this._upload_speed; },
|
uploadSpeed: function() { return this._upload_speed; },
|
||||||
uploadTotal: function() { return this._upload_total; },
|
uploadTotal: function() { return this._upload_total; },
|
||||||
showFileList: function() { if (this.fileList()) return this.fileList().show(); },
|
showFileList: function() { this.refreshFiles(); this.fileList().show(); },
|
||||||
hideFileList: function() { if (this.fileList()) return this.fileList().hide(); },
|
hideFileList: function() { this.fileList().hide(); },
|
||||||
|
|
||||||
/*--------------------------------------------
|
/*--------------------------------------------
|
||||||
*
|
*
|
||||||
|
@ -459,11 +459,13 @@ Torrent.prototype =
|
||||||
|
|
||||||
setInnerHTML( root._peer_details_container[0], peer_details );
|
setInnerHTML( root._peer_details_container[0], peer_details );
|
||||||
|
|
||||||
// Update individual files within a torrent
|
this.refreshFiles( );
|
||||||
|
},
|
||||||
|
|
||||||
|
refreshFiles: function() {
|
||||||
jQuery.each(this._files, function () {
|
jQuery.each(this._files, function () {
|
||||||
this.refreshHTML();
|
this.refreshHTML();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -632,6 +634,7 @@ function TorrentFile(file_data) {
|
||||||
|
|
||||||
TorrentFile.prototype = {
|
TorrentFile.prototype = {
|
||||||
initialize: function(file_data) {
|
initialize: function(file_data) {
|
||||||
|
this._dirty = true;
|
||||||
this._torrent = file_data.torrent;
|
this._torrent = file_data.torrent;
|
||||||
var pos = file_data.name.indexOf('/');
|
var pos = file_data.name.indexOf('/');
|
||||||
if (pos >= 0)
|
if (pos >= 0)
|
||||||
|
@ -658,11 +661,26 @@ TorrentFile.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
readAttributes: function(file_data) {
|
readAttributes: function(file_data) {
|
||||||
if (undefined != file_data.index) this._index = file_data.index;
|
if( file_data.index != undefined && file_data.index != this._index ) {
|
||||||
if (undefined != file_data.bytesCompleted) this._done = file_data.bytesCompleted;
|
this._index = file_data.index;
|
||||||
if (undefined != file_data.length) this._size = file_data.length;
|
this._dirty = true;
|
||||||
if (undefined != file_data.priority) this._prio = file_data.priority;
|
}
|
||||||
if (undefined != file_data.wanted) this._wanted = file_data.wanted;
|
if( file_data.bytesCompleted != undefined && file_data.bytesCompleted != this._done ) {
|
||||||
|
this._done = file_data.bytesCompleted;
|
||||||
|
this._dirty = true;
|
||||||
|
}
|
||||||
|
if( file_data.length != undefined && file_data.length != this._size ) {
|
||||||
|
this._size = file_data.length;
|
||||||
|
this._dirty = true;
|
||||||
|
}
|
||||||
|
if( file_data.priority != undefined && file_data.priority != this._prio ) {
|
||||||
|
this._prio = file_data.priority;
|
||||||
|
this._dirty = true;
|
||||||
|
}
|
||||||
|
if( file_data.wanted != undefined && file_data.wanted != this._wanted ) {
|
||||||
|
this._wanted = file_data.wanted;
|
||||||
|
this._dirty = true;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
element: function() {
|
element: function() {
|
||||||
|
@ -676,20 +694,14 @@ TorrentFile.prototype = {
|
||||||
if (this._prio == priority_level) { return; }
|
if (this._prio == priority_level) { return; }
|
||||||
this._prio = priority_level;
|
this._prio = priority_level;
|
||||||
this._torrent._controller.changeFileCommand("priority-" + priority, this._torrent, this);
|
this._torrent._controller.changeFileCommand("priority-" + priority, this._torrent, this);
|
||||||
this.refreshPriorityHTML();
|
this._dirty = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
setWanted: function(wanted) {
|
setWanted: function(wanted) {
|
||||||
|
this._dirty = true;
|
||||||
this._wanted = wanted;
|
this._wanted = wanted;
|
||||||
var command;
|
this.element().toggleClass( 'skip', !wanted );
|
||||||
|
var command = wanted ? 'files-wanted' : 'files-unwanted';
|
||||||
if (wanted) {
|
|
||||||
this.element().removeClass('skip');
|
|
||||||
command = 'files-wanted'
|
|
||||||
} else {
|
|
||||||
this.element().addClass('skip');
|
|
||||||
command = 'files-unwanted';
|
|
||||||
}
|
|
||||||
this._torrent._controller.changeFileCommand(command, this._torrent, this);
|
this._torrent._controller.changeFileCommand(command, this._torrent, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -700,9 +712,14 @@ TorrentFile.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
refreshHTML: function() {
|
refreshHTML: function() {
|
||||||
|
if( this._dirty ) {
|
||||||
|
this._dirty = false;
|
||||||
this.refreshProgressHTML();
|
this.refreshProgressHTML();
|
||||||
this.refreshWantedHTML();
|
this.refreshWantedHTML();
|
||||||
this.refreshPriorityHTML();
|
this.refreshPriorityHTML();
|
||||||
|
} else {
|
||||||
|
console.log( "skipping because not dirty" );
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
refreshProgressHTML: function() {
|
refreshProgressHTML: function() {
|
||||||
|
@ -714,25 +731,16 @@ TorrentFile.prototype = {
|
||||||
|
|
||||||
refreshWantedHTML: function() {
|
refreshWantedHTML: function() {
|
||||||
var element = this.element();
|
var element = this.element();
|
||||||
if (this._wanted && element.hasClass('skip'))
|
this.element().toggleClass('skip', !this._wanted);
|
||||||
this.element().removeClass('skip');
|
this.element().toggleClass('complete', this._done>=this._size );
|
||||||
else if (!this._wanted && !element.hasClass('skip'))
|
|
||||||
this.element().addClass('skip');
|
|
||||||
|
|
||||||
if (this._done < this._size && this.element().hasClass('complete'))
|
|
||||||
this.element().removeClass('complete');
|
|
||||||
else if (!this.element().hasClass('complete'))
|
|
||||||
this.element().addClass('complete');
|
|
||||||
},
|
},
|
||||||
|
|
||||||
refreshPriorityHTML: function() {
|
refreshPriorityHTML: function() {
|
||||||
if (this['_last_refreshed_prio'] == this._prio) { return; }
|
|
||||||
var priority = { '1': 'high', '0': 'normal', '-1': 'low' }[new String(this._prio)];
|
var priority = { '1': 'high', '0': 'normal', '-1': 'low' }[new String(this._prio)];
|
||||||
var off_priorities = [ 'high', 'normal', 'low' ].sort(function(a,b) { return (a == priority) ? 1 : -1; } );
|
var off_priorities = [ 'high', 'normal', 'low' ].sort(function(a,b) { return (a == priority) ? 1 : -1; } );
|
||||||
this._priority_control.addClass(priority).
|
this._priority_control.addClass(priority).
|
||||||
removeClass(off_priorities[0]).
|
removeClass(off_priorities[0]).
|
||||||
removeClass(off_priorities[1]);
|
removeClass(off_priorities[1]);
|
||||||
this._last_refreshed_prio = this._prio;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
fileWantedControlClicked: function(event) {
|
fileWantedControlClicked: function(event) {
|
||||||
|
@ -751,5 +759,4 @@ TorrentFile.prototype = {
|
||||||
else if (x < 23) { file.setPriority('normal'); }
|
else if (x < 23) { file.setPriority('normal'); }
|
||||||
else { file.setPriority('high'); }
|
else { file.setPriority('high'); }
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue