Changeset 392

Show
Ignore:
Timestamp:
06/28/08 06:39:33 (2 months ago)
Author:
charles
Message:

fix display errors with the torrent list. there's still something off with the filter, but updating to add/remove/resort/reselect is working better.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/rpc/web/javascript/torrent.js

    r389 r392  
    150150         * Process a right-click event on this torrent 
    151151         */ 
    152         rightClickTorrent: function(event) { 
    153                  
    154                 var torrent = event.data.element._torrent; 
    155                  
    156                 // Don't stop the event! need it for the right-click menu 
    157                 if (!torrent.isSelected()) { 
    158                         torrent._controller.deselectAll(); 
    159                         torrent.select(); 
    160                 } 
     152        rightClickTorrent: function(event) 
     153        { 
     154                // don't stop the event! need it for the right-click menu 
     155                 
     156                var t = event.data.element._torrent; 
     157                if ( !t.isSelected( ) ) 
     158                        t._controller.setSelectedTorrent( t ); 
    161159        }, 
    162160         
     
    164162         * Process a click event on this torrent 
    165163         */ 
    166         clickTorrent: function(event) { 
     164        clickTorrent: function( event ) 
     165        { 
    167166                // Prevents click carrying to parent element 
    168167                // which deselects all on click 
     
    179178                } 
    180179                 
    181                 var selectionChanged = false; 
    182                  
    183180                // Shift-Click - Highlight a range between this torrent and the last-clicked torrent 
    184181                if (iPhone) { 
    185                         torrent._controller.deselectAll(); 
    186                         torrent.select( ); 
    187                         selectionChanged = true; 
     182                        torrent._controller.setSelectedTorrent( torrent, true ); 
    188183                 
    189184                } else if (event.shiftKey) { 
    190                         torrent._controller.selectRange(torrent, true ); 
     185                        torrent._controller.selectRange( torrent, true ); 
    191186                        // Need to deselect any selected text 
    192187                        window.focus(); 
     
    194189                // Apple-Click, not selected 
    195190                } else if (!torrent.isSelected() && meta_key) { 
    196                         torrent.select( ); 
    197                         selectionChanged = true; 
     191                        torrent._controller.selectTorrent( torrent, true ); 
    198192                         
    199193                // Regular Click, not selected 
    200194                } else if (!torrent.isSelected()) { 
    201                         torrent._controller.deselectAll(); 
    202                         torrent.select( ); 
    203                         selectionChanged = true; 
     195                        torrent._controller.setSelectedTorrent( torrent, true ); 
    204196                 
    205197                // Apple-Click, selected         
    206198                } else if (torrent.isSelected() && meta_key) { 
    207                         torrent.deselect( ); 
    208                         selectionChanged = true; 
     199                        torrent._controller.deselectTorrent( torrent, true ); 
    209200                         
    210201                // Regular Click, selected 
    211202                } else if (torrent.isSelected()) { 
    212                         torrent._controller.deselectAll(); 
    213                         torrent.select( ); 
    214                         selectionChanged = true; 
     203                        torrent._controller.setSelectedTorrent( torrent, true ); 
    215204                } 
    216205                 
    217206                torrent._controller.setLastTorrentClicked(torrent); 
    218                  
    219                 if( selectionChanged ) 
    220                         torrent._controller.selectionChanged( ); 
    221207        }, 
    222208 
     
    420406 
    421407        /* 
    422          * Select this torrent 
    423          */ 
    424         select: function( doNotify ) 
    425         { 
    426                 // skipping height stuff on iPhone lets us omit dimensions.js; needs watching just in case 
    427                 if (!iPhone) { 
    428                         // Make sure it's visible in the torrent list (i.e. not too far down with the scrollbar all the way up) 
    429                         var container = $('#torrent_container'), 
    430                         offsetTop = this._element[0].offsetTop; 
    431                         scrollTop = container.scrollTop(), 
    432                         offsetHeight = this._element.outerHeight(), 
    433                         innerHeight = container.innerHeight(); 
    434                         if (offsetTop < scrollTop) { // torrent is too far up 
    435                                 container.scrollTop(offsetTop); 
    436                         } else if (innerHeight + scrollTop < offsetTop + offsetHeight) { // torrent is too far down 
    437                                 container.scrollTop(offsetTop + offsetHeight - innerHeight); 
    438                         } 
    439                 } 
    440                  
    441                 $.className.add( this.element()[0], 'selected' ); 
    442                  
    443                 if( doNotify ) 
    444                         this._controller.selectionChanged(); 
    445         }, 
    446  
    447         /* 
    448          * De-Select this torrent 
    449          */ 
    450         deselect: function( doNotify ) {         
    451                 $.className.remove( this.element()[0], 'selected' ); 
    452                 if( doNotify ) 
    453                         this._controller.selectionChanged(); 
    454         }, 
    455  
    456         /* 
    457408         * Return true if this torrent is selected 
    458409         */ 
    459410        isSelected: function() { 
    460                 return $.className.has( this.element()[0], 'selected' ); 
     411                var e = this.element( ); 
     412                return e && $.className.has( e[0], 'selected' ); 
    461413        }, 
    462414 
     
    576528                        high = mid; 
    577529        } 
    578         if( ( low < torrents.length ) && ( torrents[low].id() == id ) ) 
     530        if( ( low < torrents.length ) && ( torrents[low].id() == id ) ) { 
    579531                return low; 
    580         else 
     532        } else { 
    581533                return -1; // not found 
     534        } 
    582535} 
    583536 
  • branches/rpc/web/javascript/transmission.js

    r391 r392  
    184184        }, 
    185185 
    186         contextSelectAll: function() { 
    187                 transmission.selectAll(true); 
    188         }, 
    189  
    190         contextDeselectAll: function() { 
    191                 transmission.deselectAll(true); 
     186        contextSelectAll: function( ) { 
     187                transmission.selectAll( true ); 
     188        }, 
     189 
     190        contextDeselectAll: function( ) { 
     191                transmission.deselectAll( true ); 
    192192        }, 
    193193     
     
    250250                var torrents = [ ]; 
    251251                for( var i=0, len=this._rows.length; i<len; ++i ) 
    252                         if( this._rows[i][0].style.display != 'none' ) 
    253                                 torrents.push( this._rows[i]._torrent ); 
     252                        if( this._rows[i]._torrent ) 
     253                                if( this._rows[i][0].style.display != 'none' ) 
     254                                        torrents.push( this._rows[i]._torrent ); 
    254255                return torrents; 
    255256        }, 
     
    257258        getSelectedTorrents: function() 
    258259        { 
    259                 var torrents = [ ]; 
    260                 for( var i=0, len=this._rows.length; i<len; ++i ) 
    261                         if( this._rows[i]._torrent.isSelected( ) ) 
    262                                 torrents.push( this._rows[i]._torrent ); 
    263                 return torrents; 
     260                var v = this.getVisibleTorrents( ); 
     261                var s = [ ]; 
     262                for( var i=0, len=v.length; i<len; ++i ) 
     263                        if( v[i].isSelected( ) ) 
     264                                s.push( v[i] ); 
     265                return s; 
    264266        }, 
    265267 
     
    287289        }, 
    288290 
     291        scrollToElement: function( e ) 
     292        { 
     293                if( iPhone ) 
     294                        return; 
     295 
     296                var container = $('#torrent_container'); 
     297                var scrollTop = container.scrollTop( ); 
     298                var innerHeight = container.innerHeight( ); 
     299 
     300                var offsetTop = e[0].offsetTop; 
     301                var offsetHeight = e.outerHeight( ); 
     302 
     303                if( offsetTop < scrollTop ) 
     304                        container.scrollTop( offsetTop ); 
     305                else if( innerHeight + scrollTop < offsetTop + offsetHeight ) 
     306                        container.scrollTop( offsetTop + offsetHeight - innerHeight ); 
     307        }, 
     308 
    289309        /*-------------------------------------------- 
    290310         *  
     
    293313         *--------------------------------------------*/ 
    294314 
    295         selectRow: function( rowIndex, doUpdate ) 
    296         { 
    297                 var e = this._rows[rowIndex]; 
    298                 if( !e._torrent.isSelected( ) ) 
    299                         e._torrent.select( doUpdate ); 
    300         }, 
    301  
    302         deselectRow: function( rowIndex, doUpdate ) 
    303         { 
    304                 var e = this._rows[rowIndex]; 
    305                 if( e._torrent.isSelected( ) ) 
    306                         e._torrent.deselect( doUpdate ); 
    307         }, 
    308      
    309         selectionChanged: function() 
    310         { 
    311                 this.updateButtonStates(); 
    312                 this.updateInspector(); 
     315        setSelectedTorrent: function( torrent, doUpdate ) { 
     316                this.deselectAll( ); 
     317                this.selectTorrent( torrent, doUpdate ); 
     318        }, 
     319 
     320        selectElement: function( e, doUpdate ) { 
     321                $.className.add( e[0], 'selected' ); 
     322                this.scrollToElement( e ); 
     323                if( doUpdate ) 
     324                        this.selectionChanged( ); 
     325                $.className.add( e[0], 'selected' ); 
     326        }, 
     327        selectRow: function( rowIndex, doUpdate ) { 
     328                this.selectElement( this._rows[rowIndex], doUpdate ); 
     329        }, 
     330        selectTorrent: function( torrent, doUpdate ) { 
     331                if( torrent._element ) 
     332                        this.selectElement( torrent._element, doUpdate ); 
     333        }, 
     334 
     335        deselectElement: function( e, doUpdate ) { 
     336                $.className.remove( e[0], 'selected' ); 
     337                if( doUpdate ) 
     338                        this.selectionChanged( ); 
     339        }, 
     340        deselectTorrent: function( torrent, doUpdate ) { 
     341                if( torrent._element ) 
     342                        this.deselectElement( torrent._element, doUpdate ); 
    313343        }, 
    314344 
     
    316346                var tr = transmission; 
    317347                for( var i=0, len=tr._rows.length; i<len; ++i ) 
    318                         if( tr._rows[i].is(':visible') ) 
    319                                 tr.selectRow( i ); 
     348                        tr.selectElement( tr._rows[i] ); 
    320349                if( doUpdate ) 
    321350                        tr.selectionChanged(); 
    322351        }, 
    323  
    324352        deselectAll: function( doUpdate ) { 
    325353                var tr = transmission; 
    326354                for( var i=0, len=tr._rows.length; i<len; ++i ) 
    327                         if( tr._rows[i].is(':visible') ) 
    328                                 tr.deselectRow( i ); 
     355                        tr.deselectElement( tr._rows[i] ); 
    329356                tr._last_torrent_clicked = null; 
    330357                if( doUpdate ) 
     
    354381                if( doUpdate ) 
    355382                        this.selectionChanged( ); 
     383        }, 
     384     
     385        selectionChanged: function() 
     386        { 
     387                this.updateButtonStates(); 
     388                this.updateInspector(); 
    356389        }, 
    357390 
     
    653686        setSortMethod: function( sort_method ) { 
    654687                this.setPref( Prefs._SortMethod, sort_method ); 
    655                 this.resort( ); 
     688                this.refilter( ); 
    656689        }, 
    657690 
    658691        setSortDirection: function( direction ) { 
    659692                this.setPref( Prefs._SortDirection, direction ); 
    660                 this.resort( ); 
     693                this.refilter( ); 
    661694        }, 
    662695 
     
    9721005                                var pos = Torrent.indexOf( this._torrents, t.id( ) ); 
    9731006                                var e = this._torrents[pos].element(); 
    974                                 if( e ) e.remove( ); 
    975                                 this._torrents.slice( pos, 1 ); 
     1007                                if( e ) { 
     1008                                        delete e._torrent; 
     1009                                        e.hide( ); 
     1010                                } 
     1011                                this._torrents.splice( pos, 1 ); 
    9761012                                removedAny = true; 
    9771013                        } 
     
    9911027                 
    9921028                this.refilter( ); 
    993                 this.resort( ); 
    994                 this.selectionChanged( ); 
    9951029        }, 
    9961030 
     
    11401174        refilter: function() 
    11411175        { 
    1142                 var torrents = this.getAllTorrents( ); 
    1143  
    1144                 for( var i=0, len=torrents.length; i<len; ++i ) 
    1145                 { 
    1146                         var torrent = torrents[i]; 
    1147                         var element = torrent.element( ); 
    1148                         if( torrent.test( this[Prefs._FilterMode], 
    1149                                           this._current_search ) ) 
    1150                                 element[0].style.display = 'block'; 
    1151                         else { 
    1152                                 torrent.deselect(); 
    1153                                 element[0].style.display = 'none'; 
    1154                         } 
    1155                 } 
    1156  
     1176                // decide which torrents to keep showing 
     1177                var allTorrents = this.getAllTorrents( ); 
     1178                var keep = [ ]; 
     1179                for( var i=0, len=allTorrents.length; i<len; ++i ) { 
     1180                        var t = allTorrents[i]; 
     1181                        if( t.test( this[Prefs._FilterMode], this._current_search ) ) 
     1182                                keep.push( t ); 
     1183                } 
     1184 
     1185                // sort the keepers 
     1186                Torrent.sortTorrents( keep, this[Prefs._SortMethod], 
     1187                                            this[Prefs._SortDirection] ); 
     1188 
     1189                // make a backup of the selection 
     1190                var sel = this.getSelectedTorrents( ); 
     1191                this.deselectAll( ); 
     1192 
     1193                // hide the ones we're not keeping 
     1194                for( var i=keep.length; i<this._rows.length; ++i ) { 
     1195                        var e = this._rows[i]; 
     1196                        delete e._torrent; 
     1197                        e[0].style.display = 'none'; 
     1198                } 
     1199 
     1200                // show the ones we're keeping 
     1201                sel.sort( Torrent.compareById ); 
     1202                for( var i=0, len=keep.length; i<len; ++i ) { 
     1203                        var e = this._rows[i]; 
     1204                        e[0].style.display = 'block'; 
     1205                        var t = keep[i]; 
     1206                        t.setElement( e ); 
     1207                        if( Torrent.indexOf( sel, t.id() ) != -1 ) 
     1208                                this.selectElement( e ); 
     1209                } 
     1210 
     1211                // sync gui 
    11571212                this.setTorrentBgColors( ); 
    11581213                this.updateStatusbar( ); 
    11591214                this.selectionChanged( ); 
    1160         }, 
    1161  
    1162         resort: function() 
    1163         { 
    1164                 var torrents = this.getVisibleTorrents( ); 
    1165                 var sel = this.getSelectedTorrents( ); 
    1166                 var rows = this.getVisibleRows( ); 
    1167  
    1168                 // sort the local array of torrents 
    1169                 Torrent.sortTorrents( torrents, 
    1170                                       this[Prefs._SortMethod], 
    1171                                       this[Prefs._SortDirection] ); 
    1172  
    1173                 // sync the gui 
    1174                 for( var i=0, len=torrents.length; i<len; ++i ) 
    1175                         torrents[i].setElement( rows[i] ); 
    1176  
    1177                 // sync the selection class names 
    1178                 if( sel.length ) { 
    1179                         sel.sort( Torrent.compareById ); // for Torrent.indexOf 
    1180                         for( var i=0, len=rows.length; i<len; ++i ) { 
    1181                                 var t = rows[i]._torrent; 
    1182                                 if( Torrent.indexOf( sel, t.id() ) != -1 ) 
    1183                                         rows[i]._torrent.select( ); 
    1184                                 else 
    1185                                         rows[i]._torrent.deselect( ); 
    1186                         } 
    1187                 } 
    11881215        }, 
    11891216