Changeset 8500


Ignore:
Timestamp:
May 23, 2009, 8:39:55 PM (14 years ago)
Author:
charles
Message:

(trunk web) #2052: "warning: unresponsive script". what's new in this iteration: http://trac.transmissionbt.com/ticket/2052#comment:10

Location:
trunk/web/javascript
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/javascript/torrent.js

    r8498 r8500  
    3737                this._name          = data.name;
    3838                this._name_lc       = this._name.toLowerCase( );
    39 
     39                this._file_model    = [ ];
     40                this._file_view     = [ ];
    4041
    4142                // Create a new <li> element
     
    105106                this._controller._torrent_list.appendChild( top_e );
    106107
    107                 this._files = [];
    108108                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;
    124119                }
    125120
     
    199194        uploadSpeed: function() { return this._upload_speed; },
    200195        uploadTotal: function() { return this._upload_total; },
    201         showFileList: function() { this.refreshFiles(); this.fileList().show(); },
     196        showFileList: function() { this.ensureFileListExists(); this.refreshFileView(); this.fileList().show(); },
    202197        hideFileList: function() { this.fileList().hide(); },
    203198       
     
    316311                this._total_seeders         = Math.max( 0, data.seeders );
    317312                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;
    338327                }
    339328        },
     
    470459                setInnerHTML( root._peer_details_container, peer_details );
    471460       
    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                }
    479480        },
    480481
     
    644645TorrentFile.prototype = {
    645646        initialize: function(file_data) {
     647                //console.log( 'new TorrentFile ' + file_data.name );
    646648                this._dirty = true;
    647649                this._torrent = file_data.torrent;
     
    680682                this._priority_control.bind('click', { file: this }, this.filePriorityControlClicked);
    681683        },
     684
     685        update: function(file_data) {
     686                this.readAttributes(file_data);
     687                this.refreshHTML();
     688        },
    682689       
    683690        readAttributes: function(file_data) {
     
    713720       
    714721        setPriority: function(priority) {
    715                 if(this.element().hasClass('complete') || this._torrent._files.length == 1)
     722                if(this.element().hasClass('complete') || this._torrent._file_model.length == 1)
    716723                  return;
    717724                var priority_level = { high: 1, normal: 0, low: -1 }[priority];
     
    731738       
    732739        toggleWanted: function() {
    733                 if(this.element().hasClass('complete') || this._torrent._files.length == 1)
     740                if(this.element().hasClass('complete') || this._torrent._file_model.length == 1)
    734741                  return;
    735742                this.setWanted(!this._wanted);
  • trunk/web/javascript/transmission.js

    r8494 r8500  
    7878                this._torrent_list = $('#torrent_list')[0];
    7979                this._inspector_file_list = $('#inspector_file_list')[0];
     80                this._inspector_tab_files = $('#inspector_tab_files')[0];
    8081               
    8182                // Setup the preference box
     
    612613                }
    613614                this.hideiPhoneAddressbar();
     615       
     616                this.updateVisibleFileLists();
    614617        },
    615618       
     
    10111014                this.updateVisibleFileLists();
    10121015        },
     1016
     1017        fileListIsVisible: function() {
     1018                return this._inspector_tab_files.className.indexOf('selected') != -1;
     1019        },
    10131020       
    10141021        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                }
    10211026        },
    10221027   
     
    11321137        updateTorrentsFileData: function( torrents ){
    11331138                var tr = this;
     1139                var listIsVisible = tr.fileListIsVisible( );
    11341140                jQuery.each( torrents, function() {
    11351141                        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                        }
    11381147                } );
    11391148        },
Note: See TracChangeset for help on using the changeset viewer.