Changeset 391
- Timestamp:
- 06/27/08 17:03:47 (2 months ago)
- Files:
-
- branches/rpc/web/javascript/common.js (modified) (2 diffs)
- branches/rpc/web/javascript/transmission.js (modified) (15 diffs)
- branches/rpc/web/javascript/transmission.remote.js (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/rpc/web/javascript/common.js
r390 r391 144 144 145 145 146 /**147 * Array convenience method to remove element.148 *149 * @param object element150 * @returns boolean151 */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 171 146 /* 172 147 * Converts file & folder byte size values to more … … 228 203 * @returns string 229 204 */ 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; 205 Math.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; 259 229 } 260 230 branches/rpc/web/javascript/transmission.js
r390 r391 120 120 */ 121 121 setupPrefConstraints: function() { 122 // Make sure only integers are inputfor speed limit & port options122 // only allow integers for speed limit & port options 123 123 $('div.preference input[@type=text]:not(#download_location)').blur( function() { 124 124 this.value = this.value.replace(/[^0-9]/gi, ''); … … 230 230 }); 231 231 232 // Make initial menu selections (TODO - do this with data from the daemon?)233 232 $('#unlimited_download_rate').selectMenuItem(); 234 233 $('#unlimited_upload_rate').selectMenuItem(); … … 440 439 }, 441 440 442 cancelUploadClicked: function(event) {441 hideUploadDialog: function( ) { 443 442 $('body.open_showing').removeClass('open_showing'); 444 443 if (!iPhone && Safari3) { … … 451 450 }, 452 451 452 cancelUploadClicked: function(event) { 453 transmission.hideUploadDialog( ); 454 }, 455 453 456 confirmUploadClicked: function(event) { 454 $('body.open_showing').removeClass('open_showing');455 457 var url_data = jQuery.fieldValue($("#torrent_upload_url")[0]); 456 458 if( url_data.length ) … … 458 460 else 459 461 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( ); 467 463 }, 468 464 … … 491 487 o[RPC._UpSpeedLimited] = $('#prefs_form #limit_upload')[0].checked; 492 488 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; 495 492 tr.remote.savePrefs( o ); 496 493 … … 943 940 var torrent_ids = []; 944 941 var handled = []; 945 942 946 943 // refresh existing torrents 947 944 for( var i=0, len=torrent_list.length; i<len; ++i ) { … … 950 947 if( !t ) 951 948 new_torrents.push( data ); 952 else 949 else { 953 950 t.refresh( data ); 954 handled.push( t ); 955 } 956 951 handled.push( t ); 952 } 953 } 954 957 955 // Add any torrents that aren't already being displayed 958 956 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 } 961 962 this._torrents.sort( Torrent.compareById ); 962 963 } 963 964 964 965 // Remove any torrents that weren't in the refresh list 965 966 var removedAny = false; … … 968 969 for( var i=0, len=allTorrents.length; i<len; ++i ) { 969 970 var t = allTorrents[i]; 970 var wasHandled = Torrent.indexOf( handled, t.id() ) != -1; 971 if( !wasHandled ) { 971 if( Torrent.indexOf( handled, t.id() ) == -1 ) { 972 972 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( ); 974 975 this._torrents.slice( pos, 1 ); 975 976 removedAny = true; 976 977 } 977 978 } 978 979 979 980 if( ( new_torrents.length != 0 ) || removedAny ) { 980 981 this.hideiPhoneAddressbar(); 981 982 this.deselectAll( true ); 982 983 } 983 984 984 985 // FIXME: not sure if this is possible in RPC 985 986 // Update the disk space remaining … … 988 989 //+ ' (' + data.free_space_percent + '% )'; 989 990 //$('div#disk_space_container')[0].innerHTML = disk_space_msg; 990 991 991 992 this.refilter( ); 992 993 this.resort( ); … … 1012 1013 var torrentCount = torrents.length; 1013 1014 var visibleCount = this.getVisibleTorrents().length; 1014 1015 1015 1016 // calculate the overall speed 1016 1017 var upSpeed = 0; … … 1020 1021 downSpeed += torrents[i].downloadSpeed( ); 1021 1022 } 1022 1023 1023 1024 // update torrent count label 1024 1025 var s; … … 1028 1029 s = visibleCount + ' of ' + torrentCount + ' Transfers'; 1029 1030 $('#torrent_global_transfer')[0].innerHTML = s; 1030 1031 1031 1032 // update the speeds 1032 1033 s = Math.formatBytes( upSpeed ) + '/s'; 1033 1034 if( iPhone ) s = 'UL: ' + s; 1034 1035 $('#torrent_global_upload')[0].innerHTML = s; 1035 1036 1036 1037 // download speeds 1037 1038 s = Math.formatBytes( downSpeed ) + '/s'; … … 1044 1045 * FIXME 1045 1046 */ 1046 uploadTorrentFile: function(confirmed) {1047 1047 uploadTorrentFile: function(confirmed) 1048 { 1048 1049 // Display the upload dialog 1049 1050 if (! confirmed) { … … 1174 1175 torrents[i].setElement( rows[i] ); 1175 1176 1176 // sync the selection style1177 // sync the selection class names 1177 1178 if( sel.length ) { 1178 1179 sel.sort( Torrent.compareById ); // for Torrent.indexOf branches/rpc/web/javascript/transmission.remote.js
r390 r391 1 1 /* 2 * Copyright © Dave Perrett and Malcolm Jarvis3 * This code is licensed under the GPL version 2.4 * For moredetails, see http://www.gnu.org/licenses/old-licenses/gpl-2.0.html2 * 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 5 5 * 6 6 * Class TransmissionRemote … … 42 42 * Perform a generic remote request 43 43 */ 44 request: function(action, param , filter, sort_method, sort_direction, search) {44 request: function(action, param ) { 45 45 if (param == null) { 46 46 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();63 47 } 64 48 … … 66 50 type: 'GET', 67 51 url: 'remote/index.php?action=' + action + 68 '¶m=' + param + 69 '&filter=' + filter + 70 '&sort_method=' + sort_method + 71 '&sort_direction=' + sort_direction + 72 '&search=' + search, 52 '¶m=' + param, 73 53 dataType: "script", 74 54 error: this.ajaxError … … 103 83 loadDaemonPrefs: function() { 104 84 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" ); 111 92 }, 112 93 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 comma120 }121 console.log ("url is [%s]", url );122 return url;123 },124 125 94 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" ); 132 103 }, 133 104 … … 141 112 for( var i=0, len=torrents.length; i<len; ++i ) 142 113 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" ); 144 117 }, 145 118 startTorrents: function( torrents ) { … … 158 131 o.method = 'session-set'; 159 132 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 }, 162 135 163 136 /* … … 192 165 '&sort_direction=' + this._controller.currentSortDirection() + 193 166 '&search=' + this._controller.currentSearch(); 194 195 167 $('#torrent_upload_form').ajaxSubmit({dataType: 'script', type: 'POST'}); 196 168 },
