Changeset 8500
- Timestamp:
- May 23, 2009, 8:39:55 PM (14 years ago)
- Location:
- trunk/web/javascript
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/javascript/torrent.js
r8498 r8500 37 37 this._name = data.name; 38 38 this._name_lc = this._name.toLowerCase( ); 39 39 this._file_model = [ ]; 40 this._file_view = [ ]; 40 41 41 42 // Create a new <li> element … … 105 106 this._controller._torrent_list.appendChild( top_e ); 106 107 107 this._files = [];108 108 this.initializeTorrentFilesInspectorGroup(); 109 if(data.files){ 110 if(data.files.length == 1) 111 this._fileList.className += ' single_file'; 112 for (var i = 0; i < data.files.length; i++) { 113 var file = data.files[i]; 114 file.index = i; 115 file.torrent = this; 116 file.priority = data.fileStats[i].priority; 117 file.wanted = data.fileStats[i].wanted; 118 var torrentFile = new TorrentFile(file); 119 this._files.push(torrentFile); 120 var e = torrentFile.domElement(); 121 e.className = (i % 2 ? 'even' : 'odd') + ' inspector_torrent_file_list_entry'; 122 this._fileList.appendChild( e ); 123 } 109 110 for( var i=0; data.files!=null && i<data.files.length; ++i ) { 111 var src = data.files[i]; 112 var tgt = this._file_model[i]; 113 if( !tgt ) 114 tgt = this._file_model[i] = { }; 115 tgt.index = i; 116 tgt.torrent = this; 117 tgt.length = src.length; 118 tgt.name = src.name; 124 119 } 125 120 … … 199 194 uploadSpeed: function() { return this._upload_speed; }, 200 195 uploadTotal: function() { return this._upload_total; }, 201 showFileList: function() { this. refreshFiles(); this.fileList().show(); },196 showFileList: function() { this.ensureFileListExists(); this.refreshFileView(); this.fileList().show(); }, 202 197 hideFileList: function() { this.fileList().hide(); }, 203 198 … … 316 311 this._total_seeders = Math.max( 0, data.seeders ); 317 312 this._state = data.status; 318 319 if (data.fileStats) { 320 for (var i = 0; i < data.fileStats.length; i++) { 321 var file_data = {}; 322 file_data.priority = data.fileStats[i].priority; 323 file_data.wanted = data.fileStats[i].wanted; 324 file_data.bytesCompleted = data.fileStats[i].bytesCompleted; 325 this._files[i].readAttributes(file_data); 326 } 327 } 328 }, 329 330 refreshFileData: function(data) { 331 for (var i = 0; i < data.fileStats.length; i++) { 332 var file_data = {}; 333 file_data.priority = data.fileStats[i].priority; 334 file_data.wanted = data.fileStats[i].wanted; 335 file_data.bytesCompleted = data.fileStats[i].bytesCompleted; 336 this._files[i].readAttributes(file_data); 337 this._files[i].refreshHTML(); 313 314 if (data.fileStats) 315 this.refreshFileModel( data ); 316 }, 317 318 refreshFileModel: function(data) { 319 for( var i=0; i<data.fileStats.length; ++i ) { 320 var src = data.fileStats[i]; 321 var tgt = this._file_model[i]; 322 if( !tgt ) 323 tgt = this._file_model[i] = { }; 324 tgt.wanted = src.wanted; 325 tgt.priority = src.priority; 326 tgt.bytesCompleted = src.bytesCompleted; 338 327 } 339 328 }, … … 470 459 setInnerHTML( root._peer_details_container, peer_details ); 471 460 472 this.refreshFiles( ); 473 }, 474 475 refreshFiles: function() { 476 jQuery.each(this._files, function () { 477 this.refreshHTML(); 478 } ); 461 this.refreshFileView( ); 462 }, 463 464 refreshFileView: function() { 465 if( this._file_view.length ) 466 for( var i=0; i<this._file_model.length; ++i ) 467 this._file_view[i].update( this._file_model[i] ); 468 }, 469 470 ensureFileListExists: function() { 471 if( this._file_view.length == 0 ) { 472 for( var i=0; i<this._file_model.length; ++i ) { 473 var v = new TorrentFile( this._file_model[i] ); 474 this._file_view[i] = v; 475 var e = v.domElement( ); 476 e.className = (i % 2 ? 'even' : 'odd') + ' inspector_torrent_file_list_entry'; 477 this._fileList.appendChild( e ); 478 } 479 } 479 480 }, 480 481 … … 644 645 TorrentFile.prototype = { 645 646 initialize: function(file_data) { 647 //console.log( 'new TorrentFile ' + file_data.name ); 646 648 this._dirty = true; 647 649 this._torrent = file_data.torrent; … … 680 682 this._priority_control.bind('click', { file: this }, this.filePriorityControlClicked); 681 683 }, 684 685 update: function(file_data) { 686 this.readAttributes(file_data); 687 this.refreshHTML(); 688 }, 682 689 683 690 readAttributes: function(file_data) { … … 713 720 714 721 setPriority: function(priority) { 715 if(this.element().hasClass('complete') || this._torrent._file s.length == 1)722 if(this.element().hasClass('complete') || this._torrent._file_model.length == 1) 716 723 return; 717 724 var priority_level = { high: 1, normal: 0, low: -1 }[priority]; … … 731 738 732 739 toggleWanted: function() { 733 if(this.element().hasClass('complete') || this._torrent._file s.length == 1)740 if(this.element().hasClass('complete') || this._torrent._file_model.length == 1) 734 741 return; 735 742 this.setWanted(!this._wanted); -
trunk/web/javascript/transmission.js
r8494 r8500 78 78 this._torrent_list = $('#torrent_list')[0]; 79 79 this._inspector_file_list = $('#inspector_file_list')[0]; 80 this._inspector_tab_files = $('#inspector_tab_files')[0]; 80 81 81 82 // Setup the preference box … … 612 613 } 613 614 this.hideiPhoneAddressbar(); 615 616 this.updateVisibleFileLists(); 614 617 }, 615 618 … … 1011 1014 this.updateVisibleFileLists(); 1012 1015 }, 1016 1017 fileListIsVisible: function() { 1018 return this._inspector_tab_files.className.indexOf('selected') != -1; 1019 }, 1013 1020 1014 1021 updateVisibleFileLists: function() { 1015 jQuery.each( this.getSelectedTorrents(), function() { 1016 this.showFileList(); 1017 } ); 1018 jQuery.each( this.getDeselectedTorrents(), function() { 1019 this.hideFileList(); 1020 } ); 1022 if( this.fileListIsVisible( ) === true ) { 1023 jQuery.each( this.getSelectedTorrents(), function() { this.showFileList(); } ); 1024 jQuery.each( this.getDeselectedTorrents(), function() { this.hideFileList(); } ); 1025 } 1021 1026 }, 1022 1027 … … 1132 1137 updateTorrentsFileData: function( torrents ){ 1133 1138 var tr = this; 1139 var listIsVisible = tr.fileListIsVisible( ); 1134 1140 jQuery.each( torrents, function() { 1135 1141 var t = Torrent.lookup(tr._torrents, this.id); 1136 if (t) 1137 t.refreshFileData(this); 1142 if (t) { 1143 t.refreshFileModel(this); 1144 if( listIsVisible && t.isSelected()) 1145 t.refreshFileView(); 1146 } 1138 1147 } ); 1139 1148 },
Note: See TracChangeset
for help on using the changeset viewer.