Changeset 391

Show
Ignore:
Timestamp:
06/27/08 17:03:47 (2 months ago)
Author:
charles
Message:

silence an error message when removing torrents. remove some dead code.

Files:

Legend:

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

    r390 r391  
    144144 
    145145 
    146 /** 
    147  *   Array convenience method to remove element. 
    148  * 
    149  *   @param object element 
    150  *   @returns boolean 
    151  */ 
    152 Array.prototype.remove = function (element) { 
    153         var result = false; 
    154         var array = []; 
    155         for (var i = 0; i < this.length; i++) { 
    156                 if (this[i] == element) { 
    157                         result = true; 
    158                 } else { 
    159                         array.push(this[i]); 
    160                 } 
    161         } 
    162         this.clear(); 
    163         for (var i = 0; i < array.length; i++) { 
    164                 this.push(array[i]); 
    165         } 
    166         array = null; 
    167         return result; 
    168 }; 
    169  
    170  
    171146/* 
    172147 *   Converts file & folder byte size values to more   
     
    228203 *   @returns string 
    229204 */ 
    230 Math.formatSeconds = function(seconds) { 
    231     var result; 
    232     var days; 
    233     var hours; 
    234     var minutes; 
    235     var seconds; 
    236      
    237     days = Math.floor(seconds / 86400); 
    238     hours = Math.floor((seconds % 86400) / 3600); 
    239     minutes = Math.floor((seconds % 3600) / 60); 
    240     seconds = Math.floor((seconds % 3600) % 60);     
    241      
    242     if (days > 0 && hours == 0) { 
    243         result = days + ' days';     
    244     } else if (days > 0 && hours > 0) { 
    245         result = days + ' days ' + hours + ' hr'; 
    246     } else if (hours > 0 && minutes == 0) { 
    247         result = hours + ' hr';    
    248     } else if (hours > 0 && minutes > 0) { 
    249         result = hours + ' hr ' + minutes + ' min'; 
    250     } else if (minutes > 0 && seconds == 0) { 
    251         result = minutes + ' min'; 
    252     } else if (minutes > 0 && seconds > 0) { 
    253         result = minutes + ' min ' + seconds + ' seconds'; 
    254     } else { 
    255         result = seconds + ' seconds';   
    256     } 
    257      
    258     return result; 
     205Math.formatSeconds = function(seconds) 
     206
     207        var result; 
     208        var days = Math.floor(seconds / 86400); 
     209        var hours = Math.floor((seconds % 86400) / 3600); 
     210        var minutes = Math.floor((seconds % 3600) / 60); 
     211        var seconds = Math.floor((seconds % 3600) % 60);     
     212 
     213        if (days > 0 && hours == 0) 
     214                result = days + ' days'; 
     215        else if (days > 0 && hours > 0) 
     216                result = days + ' days ' + hours + ' hr'; 
     217        else if (hours > 0 && minutes == 0) 
     218                result = hours + ' hr';    
     219        else if (hours > 0 && minutes > 0) 
     220                result = hours + ' hr ' + minutes + ' min'; 
     221        else if (minutes > 0 && seconds == 0) 
     222                result = minutes + ' min'; 
     223        else if (minutes > 0 && seconds > 0) 
     224                result = minutes + ' min ' + seconds + ' seconds'; 
     225        else 
     226                result = seconds + ' seconds';   
     227 
     228        return result; 
    259229} 
    260230 
  • branches/rpc/web/javascript/transmission.js

    r390 r391  
    120120         */ 
    121121        setupPrefConstraints: function() { 
    122                 // Make sure only integers are input for speed limit & port options 
     122                // only allow integers for speed limit & port options 
    123123                $('div.preference input[@type=text]:not(#download_location)').blur( function() { 
    124124                        this.value = this.value.replace(/[^0-9]/gi, ''); 
     
    230230                }); 
    231231                 
    232                 // Make initial menu selections (TODO - do this with data from the daemon?) 
    233232                $('#unlimited_download_rate').selectMenuItem(); 
    234233                $('#unlimited_upload_rate').selectMenuItem(); 
     
    440439        }, 
    441440 
    442         cancelUploadClicked: function(event) { 
     441        hideUploadDialog: function( ) { 
    443442                $('body.open_showing').removeClass('open_showing'); 
    444443                if (!iPhone && Safari3) { 
     
    451450        }, 
    452451 
     452        cancelUploadClicked: function(event) { 
     453                transmission.hideUploadDialog( ); 
     454        }, 
     455 
    453456        confirmUploadClicked: function(event) { 
    454                 $('body.open_showing').removeClass('open_showing'); 
    455457                var url_data = jQuery.fieldValue($("#torrent_upload_url")[0]); 
    456458                if( url_data.length ) 
     
    458460                else 
    459461                        transmission.uploadTorrentFile(true); 
    460                 if (!iPhone && Safari3) { 
    461                         $('div#upload_container div.dialog_window').css('top', '-205px'); 
    462                         setTimeout("$('#upload_container').hide();",500); 
    463                 } else { 
    464                         $('#upload_container').hide(); 
    465                 } 
    466                 transmission.updateButtonStates(); 
     462                transmission.hideUploadDialog( ); 
    467463        }, 
    468464 
     
    491487                o[RPC._UpSpeedLimited]   = $('#prefs_form #limit_upload')[0].checked; 
    492488                o[RPC._DownSpeedLimited] = $('#prefs_form #limit_download')[0].checked; 
    493                 o[RPC._Encryption]       = $('#prefs_form #encryption')[0].checked ? RPC._EncryptionRequired 
    494                                                                                    : RPC._EncryptionPreferred; 
     489                o[RPC._Encryption]       = $('#prefs_form #encryption')[0].checked 
     490                                               ? RPC._EncryptionRequired 
     491                                               : RPC._EncryptionPreferred; 
    495492                tr.remote.savePrefs( o ); 
    496493                 
     
    943940                var torrent_ids = []; 
    944941                var handled = []; 
    945  
     942                 
    946943                // refresh existing torrents 
    947944                for( var i=0, len=torrent_list.length; i<len; ++i ) { 
     
    950947                        if( !t ) 
    951948                                new_torrents.push( data ); 
    952                         else 
     949                        else { 
    953950                                t.refresh( data ); 
    954                         handled.push( t ); 
    955                 } 
    956  
     951                                handled.push( t ); 
     952                        } 
     953                } 
     954                 
    957955                // Add any torrents that aren't already being displayed 
    958956                if( new_torrents.length ) { 
    959                         for( var i=0, len=new_torrents.length; i<len; ++i ) 
    960                                 this._torrents.push( new Torrent( this, new_torrents[i] ) ); 
     957                        for( var i=0, len=new_torrents.length; i<len; ++i ) { 
     958                                var t = new Torrent( this, new_torrents[i] ); 
     959                                this._torrents.push( t ); 
     960                                handled.push( t ); 
     961                        } 
    961962                        this._torrents.sort( Torrent.compareById );  
    962963                } 
    963  
     964                 
    964965                // Remove any torrents that weren't in the refresh list 
    965966                var removedAny = false; 
     
    968969                for( var i=0, len=allTorrents.length; i<len; ++i ) { 
    969970                        var t = allTorrents[i]; 
    970                         var wasHandled = Torrent.indexOf( handled, t.id() ) != -1; 
    971                         if( !wasHandled ) { 
     971                        if( Torrent.indexOf( handled, t.id() ) == -1 ) { 
    972972                                var pos = Torrent.indexOf( this._torrents, t.id( ) ); 
    973                                 this._torrents[pos].element().remove(); 
     973                                var e = this._torrents[pos].element(); 
     974                                if( e ) e.remove( ); 
    974975                                this._torrents.slice( pos, 1 ); 
    975976                                removedAny = true; 
    976977                        } 
    977978                } 
    978  
     979                 
    979980                if( ( new_torrents.length != 0 ) || removedAny ) { 
    980981                        this.hideiPhoneAddressbar(); 
    981982                        this.deselectAll( true ); 
    982983                } 
    983  
     984                 
    984985                // FIXME: not sure if this is possible in RPC 
    985986                // Update the disk space remaining 
     
    988989                //+ ' (' + data.free_space_percent + '% )'; 
    989990                //$('div#disk_space_container')[0].innerHTML = disk_space_msg; 
    990  
     991                 
    991992                this.refilter( ); 
    992993                this.resort( ); 
     
    10121013                var torrentCount = torrents.length; 
    10131014                var visibleCount = this.getVisibleTorrents().length; 
    1014  
     1015                 
    10151016                // calculate the overall speed 
    10161017                var upSpeed = 0; 
     
    10201021                        downSpeed += torrents[i].downloadSpeed( ); 
    10211022                } 
    1022  
     1023                 
    10231024                // update torrent count label 
    10241025                var s; 
     
    10281029                        s = visibleCount + ' of ' + torrentCount + ' Transfers'; 
    10291030                $('#torrent_global_transfer')[0].innerHTML = s; 
    1030  
     1031                 
    10311032                // update the speeds 
    10321033                s = Math.formatBytes( upSpeed ) + '/s'; 
    10331034                if( iPhone ) s = 'UL: ' + s; 
    10341035                $('#torrent_global_upload')[0].innerHTML = s; 
    1035  
     1036                 
    10361037                // download speeds 
    10371038                s = Math.formatBytes( downSpeed ) + '/s'; 
     
    10441045         * FIXME 
    10451046         */ 
    1046         uploadTorrentFile: function(confirmed) { 
    1047          
     1047        uploadTorrentFile: function(confirmed) 
     1048        { 
    10481049                // Display the upload dialog 
    10491050                if (! confirmed) { 
     
    11741175                        torrents[i].setElement( rows[i] ); 
    11751176 
    1176                 // sync the selection style 
     1177                // sync the selection class names 
    11771178                if( sel.length ) { 
    11781179                        sel.sort( Torrent.compareById ); // for Torrent.indexOf 
  • branches/rpc/web/javascript/transmission.remote.js

    r390 r391  
    11/* 
    2  *     Copyright © Dave Perrett and Malcolm Jarvis 
    3  *     This code is licensed under the GPL version 2. 
    4  *     For more details, see http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     2 * Copyright © Dave Perrett and Malcolm Jarvis 
     3 * This code is licensed under the GPL version 2. 
     4 * For details, see http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
    55 * 
    66 * Class TransmissionRemote 
     
    4242         * Perform a generic remote request 
    4343         */ 
    44         request: function(action, param, filter, sort_method, sort_direction, search) { 
     44        request: function(action, param ) { 
    4545                if (param == null) { 
    4646                        param = '0'; 
    47                 } 
    48                  
    49                 if (filter == null) { 
    50                         filter = this._controller.currentFilter(); 
    51                 } 
    52                  
    53                 if (sort_method == null) { 
    54                         sort_method = this._controller.currentSortMethod(); 
    55                 } 
    56                  
    57                 if (sort_direction == null) { 
    58                         sort_direction = this._controller.currentSortDirection(); 
    59                 } 
    60                  
    61                 if (search == null) { 
    62                         search = this._controller.currentSearch(); 
    6347                } 
    6448                 
     
    6650                        type: 'GET', 
    6751                        url: 'remote/index.php?action=' + action +  
    68                                 '&param=' + param +  
    69                                 '&filter=' + filter +  
    70                                 '&sort_method=' + sort_method +  
    71                                 '&sort_direction=' + sort_direction +  
    72                                 '&search=' + search, 
     52                                '&param=' + param, 
    7353                        dataType: "script", 
    7454                        error: this.ajaxError 
     
    10383        loadDaemonPrefs: function() { 
    10484                var tr = this._controller; 
    105                 $.getJSON( RPC._Root + "?method=session-get", 
    106                            function( data ) { 
    107                                var o = data.arguments.session; 
    108                                Prefs.getClutchPrefs( o ); 
    109                                tr.updatePrefs( o ); 
    110                            } ); 
     85                var o = { }; 
     86                o.method = 'session-get'; 
     87                $.post( RPC._Root, $.toJSON(o), function(data) { 
     88                        var o = data.arguments.session; 
     89                        Prefs.getClutchPrefs( o ); 
     90                        tr.updatePrefs( o ); 
     91                }, "json" ); 
    11192        }, 
    11293 
    113         buildTorrentURL: function( method, torrents ) { 
    114                 var url = RPC._Root + "?method=" + method; 
    115                 if( torrents && torrents.length ) { 
    116                         url += '&ids='; 
    117                         for( var i=0, len=torrents.length; i<len; ++i ) 
    118                                 url += torrents[i]._id + ',' 
    119                         url = url.substring( 0, url.length-1 ); // last comma 
    120                 } 
    121                 console.log ("url is [%s]", url ); 
    122                 return url; 
    123         }, 
    124          
    12594        loadTorrents: function() { 
    126                 var t = this._controller; 
    127                 var url = this.buildTorrentURL( "torrent-get", null ); 
    128                 url += "&fields=6197"; 
    129                 $.getJSON( url, function(data) { 
    130                                t.updateTorrents(data.arguments.torrents); 
    131                            } ); 
     95                var tr = this._controller; 
     96                var o = { }; 
     97                o.method = 'torrent-get' 
     98                o.arguments = { }; 
     99                o.arguments.fields = 6197; 
     100                $.post( RPC._Root, $.toJSON(o), function(data) { 
     101                        tr.updateTorrents( data.arguments.torrents ); 
     102                }, "json" ); 
    132103        }, 
    133104 
     
    141112                        for( var i=0, len=torrents.length; i<len; ++i ) 
    142113                                o.arguments.ids.push( torrents[i].id() ); 
    143                 $.post( RPC._Root, $.toJSON(o), function(){remote.loadTorrents();}, "json" ); 
     114        $.post( RPC._Root, $.toJSON(o), function( ) { 
     115                        remote.loadTorrents(); 
     116                }, "json" ); 
    144117        }, 
    145118        startTorrents: function( torrents ) { 
     
    158131                o.method = 'session-set'; 
    159132                o.arguments = args; 
    160               $.post( RPC._Root, $.toJSON(o), function(){remote.loadDaemonPrefs();}, "json" ); 
    161         }, 
     133              $.post( RPC._Root, $.toJSON(o), function(){remote.loadDaemonPrefs();}, "json" ); 
     134       }, 
    162135 
    163136/* 
     
    192165                                '&sort_direction=' + this._controller.currentSortDirection() + 
    193166                                '&search=' + this._controller.currentSearch(); 
    194  
    195167                $('#torrent_upload_form').ajaxSubmit({dataType: 'script', type: 'POST'}); 
    196168        },