mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 12:28:52 +00:00
add the rest of Clutch to m0k.org's svn
This commit is contained in:
135
web/javascript/transmission.remote.js
Normal file
135
web/javascript/transmission.remote.js
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright © Dave Perrett and Malcolm Jarvis
|
||||
* This code is licensed under the GPL version 2.
|
||||
* For details, see http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Class TransmissionRemote
|
||||
*/
|
||||
|
||||
function RPC() { }
|
||||
//Prefs.prototype = { }
|
||||
|
||||
// Constants
|
||||
RPC._Root = '/transmission/rpc';
|
||||
RPC._Encryption = 'encryption';
|
||||
RPC._EncryptionPreferred = 'preferred';
|
||||
RPC._EncryptionRequired = 'required';
|
||||
RPC._UpSpeedLimit = 'speed-limit-up';
|
||||
RPC._DownSpeedLimit = 'speed-limit-down';
|
||||
RPC._DownloadDir = 'download-dir';
|
||||
RPC._PeerPort = 'port';
|
||||
RPC._UpSpeedLimited = 'speed-limit-up-enabled';
|
||||
RPC._DownSpeedLimited = 'speed-limit-down-enabled';
|
||||
|
||||
function TransmissionRemote( controller )
|
||||
{
|
||||
this.initialize( controller );
|
||||
return this;
|
||||
}
|
||||
|
||||
TransmissionRemote.prototype =
|
||||
{
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
initialize: function(controller) {
|
||||
this._controller = controller;
|
||||
this._error = '';
|
||||
},
|
||||
|
||||
/*
|
||||
* Display an error if an ajax request fails, and stop sending requests
|
||||
*/
|
||||
ajaxError: function(request, error_string, exception) {
|
||||
this._error = request.responseText
|
||||
? request.responseText.trim().replace(/(<([^>]+)>)/ig,"")
|
||||
: "";
|
||||
if( !this._error.length )
|
||||
this._error = 'Server not responding';
|
||||
|
||||
dialog.confirm('Connection Failed',
|
||||
'Could not connect to the server. You may need to reload the page to reconnect.',
|
||||
'Details',
|
||||
'alert(transmission.remote._error);',
|
||||
null,
|
||||
'Dismiss');
|
||||
transmission.togglePeriodicRefresh(false);
|
||||
},
|
||||
|
||||
sendRequest: function( url, data, success, contentType )
|
||||
{
|
||||
var o = { };
|
||||
o.cache = false;
|
||||
o.contentType = contentType;
|
||||
o.data = data;
|
||||
o.dataType = 'json';
|
||||
o.error = this.ajaxError;
|
||||
o.success = success;
|
||||
o.type = 'POST';
|
||||
o.url = url;
|
||||
$.ajax( o );
|
||||
},
|
||||
|
||||
loadDaemonPrefs: function() {
|
||||
var tr = this._controller;
|
||||
var o = { };
|
||||
o.method = 'session-get';
|
||||
this.sendRequest( RPC._Root, $.toJSON(o), function(data) {
|
||||
var o = data.arguments.session;
|
||||
Prefs.getClutchPrefs( o );
|
||||
tr.updatePrefs( o );
|
||||
}, "json" );
|
||||
},
|
||||
|
||||
loadTorrents: function() {
|
||||
var tr = this._controller;
|
||||
var o = { };
|
||||
o.method = 'torrent-get'
|
||||
o.arguments = { };
|
||||
o.arguments.fields = 1+2+4+16+32+64+128+1024+2048+4096;
|
||||
this.sendRequest( RPC._Root, $.toJSON(o), function(data) {
|
||||
tr.updateTorrents( data.arguments.torrents );
|
||||
}, "json" );
|
||||
},
|
||||
|
||||
sendTorrentCommand: function( method, torrents ) {
|
||||
var remote = this;
|
||||
var o = { };
|
||||
o.method = method;
|
||||
o.arguments = { };
|
||||
o.arguments.ids = [ ];
|
||||
if( torrents != null )
|
||||
for( var i=0, len=torrents.length; i<len; ++i )
|
||||
o.arguments.ids.push( torrents[i].id() );
|
||||
this.sendRequest( RPC._Root, $.toJSON(o), function( ) {
|
||||
remote.loadTorrents();
|
||||
}, "json" );
|
||||
},
|
||||
startTorrents: function( torrents ) {
|
||||
this.sendTorrentCommand( 'torrent-start', torrents );
|
||||
},
|
||||
stopTorrents: function( torrents ) {
|
||||
this.sendTorrentCommand( 'torrent-stop', torrents );
|
||||
},
|
||||
removeTorrents: function( torrents ) {
|
||||
this.sendTorrentCommand( 'torrent-remove', torrents );
|
||||
},
|
||||
|
||||
savePrefs: function( args ) {
|
||||
var remote = this;
|
||||
var o = { };
|
||||
o.method = 'session-set';
|
||||
o.arguments = args;
|
||||
this.sendRequest( RPC._Root, $.toJSON(o), function(){
|
||||
remote.loadDaemonPrefs();
|
||||
}, "json" );
|
||||
},
|
||||
|
||||
/*
|
||||
* Upload Torrent by URL
|
||||
addTorrentByURL: function() {
|
||||
$('#torrent_upload_form')[0].action = 'remote/index.php?action=addTorrentByURL¶m=[]';
|
||||
$('#torrent_upload_form').ajaxSubmit({dataType: 'script', type: 'POST'});
|
||||
},
|
||||
*/
|
||||
};
|
||||
Reference in New Issue
Block a user