1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-20 21:26:53 +00:00

(trunk web) add context arguments for the RPC methods' callbacks.

This commit is contained in:
Jordan Lee 2011-08-28 06:05:46 +00:00
parent 02c0f7355b
commit 228e1064e1
2 changed files with 56 additions and 72 deletions

View file

@ -149,26 +149,23 @@ Transmission.prototype =
}, },
loadDaemonPrefs: function(async) { loadDaemonPrefs: function(async) {
var tr = this;
this.remote.loadDaemonPrefs(function(data) { this.remote.loadDaemonPrefs(function(data) {
var o = data['arguments']; var o = data['arguments'];
Prefs.getClutchPrefs(o); Prefs.getClutchPrefs(o);
tr.updatePrefs(o); this.updatePrefs(o);
}, async); }, this, async);
}, },
loadDaemonStats: function(async) { loadDaemonStats: function(async) {
var tr = this;
this.remote.loadDaemonStats(function(data) { this.remote.loadDaemonStats(function(data) {
tr.updateStats(data['arguments']); this.updateStats(data['arguments']);
}, async); }, this, async);
}, },
checkPort: function(async) { checkPort: function(async) {
$('#port_test').text('checking ...'); $('#port_test').text('checking ...');
var tr = this;
this.remote.checkPort(function(data) { this.remote.checkPort(function(data) {
tr.updatePortStatus(data['arguments']); this.updatePortStatus(data['arguments']);
}, async); }, this, async);
}, },
preloadImages: function() { preloadImages: function() {
@ -1278,9 +1275,8 @@ Transmission.prototype =
}, },
removeTorrents: function(torrents) { removeTorrents: function(torrents) {
var tr = this;
var ids = $.map(torrents, function(t) { return t.getId(); }); var ids = $.map(torrents, function(t) { return t.getId(); });
this.remote.removeTorrents(ids, function() { tr.refreshTorrents();}); this.remote.removeTorrents(ids, this.refreshTorrents, this);
}, },
removeTorrentsAndData: function(torrents) { removeTorrentsAndData: function(torrents) {
@ -1305,26 +1301,23 @@ Transmission.prototype =
this.startTorrents([ torrent ], false); this.startTorrents([ torrent ], false);
}, },
startTorrents: function(torrents, force) { startTorrents: function(torrents, force) {
var tr = this; this.remote.startTorrents($.map(torrents, function(t) {return t.getId();}),
var ids = $.map(torrents, function(t) { return t.getId(); }); force, this.refreshTorrents, this);
this.remote.startTorrents(ids, force, function() { tr.refreshTorrents(); });
}, },
verifyTorrent: function(torrent) { verifyTorrent: function(torrent) {
this.verifyTorrents([ torrent ]); this.verifyTorrents([ torrent ]);
}, },
verifyTorrents: function(torrents) { verifyTorrents: function(torrents) {
var tr = this; this.remote.verifyTorrents($.map(torrents, function(t) {return t.getId();}),
var ids = $.map(torrents, function(t) { return t.getId(); }); this.refreshTorrents, this);
this.remote.verifyTorrents(ids, function() { tr.refreshTorrents(); });
}, },
reannounceTorrent: function(torrent) { reannounceTorrent: function(torrent) {
this.reannounceTorrents([ torrent ]); this.reannounceTorrents([ torrent ]);
}, },
reannounceTorrents: function(torrents) { reannounceTorrents: function(torrents) {
var tr = this; this.remote.reannounceTorrents($.map(torrents, function(t) {return t.getId();}),
var ids = $.map(torrents, function(t) { return t.getId(); }); this.refreshTorrents, this);
this.remote.reannounceTorrents(ids, function() { tr.refreshTorrents(); });
}, },
stopSelectedTorrents: function() { stopSelectedTorrents: function() {
@ -1337,9 +1330,8 @@ Transmission.prototype =
this.stopTorrents([ torrent ]); this.stopTorrents([ torrent ]);
}, },
stopTorrents: function(torrents) { stopTorrents: function(torrents) {
var tr = this; this.remote.stopTorrents($.map(torrents.slice(0), function(t) {return t.getId();}),
var ids = $.map(torrents, function(t) { return t.getId(); }); this.refreshTorrents, this);
this.remote.stopTorrents(ids, function() { tr.refreshTorrents();});
}, },
changeFileCommand: function(command, rows) { changeFileCommand: function(command, rows) {
this.remote.changeFileCommand(command, rows); this.remote.changeFileCommand(command, rows);
@ -1362,27 +1354,22 @@ Transmission.prototype =
// Queue // Queue
moveTop: function() { moveTop: function() {
var tr = this; this.remote.moveTorrentsToTop(this.getSelectedTorrentIds(),
var ids = this.getSelectedTorrentIds(); this.refreshTorrents, this);
this.remote.moveTorrentsToTop(ids, function() { tr.refreshTorrents();});
}, },
moveUp: function() { moveUp: function() {
var tr = this; this.remote.moveTorrentsUp(this.getSelectedTorrentIds(),
var ids = this.getSelectedTorrentIds(); this.refreshTorrents, this);
this.remote.moveTorrentsUp(ids, function() { tr.refreshTorrents();});
}, },
moveDown: function() { moveDown: function() {
var tr = this; this.remote.moveTorrentsDown(this.getSelectedTorrentIds(),
var ids = this.getSelectedTorrentIds(); this.refreshTorrents, this);
this.remote.moveTorrentsDown(ids, function() { tr.refreshTorrents();});
}, },
moveBottom: function() { moveBottom: function() {
var tr = this; this.remote.moveTorrentsToBottom(this.getSelectedTorrentIds(),
var ids = this.getSelectedTorrentIds(); this.refreshTorrents, this);
this.remote.moveTorrentsToBottom(ids, function() { tr.refreshTorrents();});
}, },
/*** /***
**** ****
***/ ***/
@ -1739,7 +1726,6 @@ Transmission.prototype =
if (!$(this._inspector_trackers_list).is(':visible')) if (!$(this._inspector_trackers_list).is(':visible'))
return; return;
var tr = this;
var html = [ ]; var html = [ ];
var na = 'N/A'; var na = 'N/A';
var torrents = this.getSelectedTorrents(); var torrents = this.getSelectedTorrents();
@ -1769,9 +1755,9 @@ Transmission.prototype =
'<ul class="tier_list">'); '<ul class="tier_list">');
} }
var lastAnnounceStatusHash = tr.lastAnnounceStatus(tracker); var lastAnnounceStatusHash = this.lastAnnounceStatus(tracker);
var announceState = tr.announceState(tracker); var announceState = this.announceState(tracker);
var lastScrapeStatusHash = tr.lastScrapeStatus(tracker); var lastScrapeStatusHash = this.lastScrapeStatus(tracker);
// Display construction // Display construction
var parity = ((j+1) % 2 == 0 ? 'even' : 'odd'); var parity = ((j+1) % 2 == 0 ? 'even' : 'odd');

View file

@ -96,7 +96,7 @@ TransmissionRemote.prototype =
XHR.setRequestHeader('X-Transmission-Session-Id', this._token); XHR.setRequestHeader('X-Transmission-Session-Id', this._token);
}, },
sendRequest: function(data, success, async) { sendRequest: function(data, callback, context, async) {
remote = this; remote = this;
if (typeof async != 'boolean') if (typeof async != 'boolean')
async = true; async = true;
@ -110,32 +110,33 @@ TransmissionRemote.prototype =
data: $.toJSON(data), data: $.toJSON(data),
beforeSend: function(XHR){ remote.appendSessionId(XHR); }, beforeSend: function(XHR){ remote.appendSessionId(XHR); },
error: function(request, error_string, exception){ remote.ajaxError(request, error_string, exception, ajaxSettings); }, error: function(request, error_string, exception){ remote.ajaxError(request, error_string, exception, ajaxSettings); },
success: success, success: callback,
context: context,
async: async async: async
}; };
$.ajax(ajaxSettings); $.ajax(ajaxSettings);
}, },
loadDaemonPrefs: function(callback, async) { loadDaemonPrefs: function(callback, context, async) {
var o = { method: 'session-get' }; var o = { method: 'session-get' };
this.sendRequest(o, callback, async); this.sendRequest(o, callback, context, async);
}, },
checkPort: function(callback, async) { checkPort: function(callback, context, async) {
var o = { method: 'port-test' }; var o = { method: 'port-test' };
this.sendRequest(o, callback, async); this.sendRequest(o, callback, context, async);
}, },
loadDaemonStats: function(callback, async) { loadDaemonStats: function(callback, context, async) {
var o = { method: 'session-stats' }; var o = { method: 'session-stats' };
this.sendRequest(o, callback, async); this.sendRequest(o, callback, context, async);
}, },
updateTorrents: function(torrentIds, fields, callback, context) { updateTorrents: function(torrentIds, fields, callback, context) {
var o = { var o = {
method: 'torrent-get', method: 'torrent-get',
'arguments': { 'arguments': {
'fields': fields, 'fields': fields,
} }
}; };
@ -163,32 +164,29 @@ TransmissionRemote.prototype =
}); });
}, },
sendTorrentSetRequests: function(method, torrent_ids, args, callback) { sendTorrentSetRequests: function(method, torrent_ids, args, callback, context) {
if (!args) args = { }; if (!args) args = { };
args['ids'] = torrent_ids; args['ids'] = torrent_ids;
var o = { var o = {
method: method, method: method,
arguments: args arguments: args
}; };
this.sendRequest(o, callback, context);
this.sendRequest(o, function(data) {
callback();
});
}, },
sendTorrentActionRequests: function(method, torrent_ids, callback) { sendTorrentActionRequests: function(method, torrent_ids, callback, context) {
this.sendTorrentSetRequests(method, torrent_ids, null, callback); this.sendTorrentSetRequests(method, torrent_ids, null, callback, context);
}, },
startTorrents: function(torrent_ids, noqueue, callback) { startTorrents: function(torrent_ids, noqueue, callback, context) {
var name = noqueue ? 'torrent-start-now' : 'torrent-start'; var name = noqueue ? 'torrent-start-now' : 'torrent-start';
this.sendTorrentActionRequests(name, torrent_ids, callback); this.sendTorrentActionRequests(name, torrent_ids, callback, context);
}, },
stopTorrents: function(torrent_ids, callback) { stopTorrents: function(torrent_ids, callback, context) {
this.sendTorrentActionRequests('torrent-stop', torrent_ids, callback); this.sendTorrentActionRequests('torrent-stop', torrent_ids, callback, context);
}, },
removeTorrents: function(torrent_ids, callback) { removeTorrents: function(torrent_ids, callback, context) {
this.sendTorrentActionRequests('torrent-remove', torrent_ids, callback); this.sendTorrentActionRequests('torrent-remove', torrent_ids, callback, context);
}, },
removeTorrentsAndData: function(torrents) { removeTorrentsAndData: function(torrents) {
var remote = this; var remote = this;
@ -209,8 +207,8 @@ TransmissionRemote.prototype =
remote._controller.refreshTorrents(); remote._controller.refreshTorrents();
}); });
}, },
verifyTorrents: function(torrent_ids, callback) { verifyTorrents: function(torrent_ids, callback, context) {
this.sendTorrentActionRequests('torrent-verify', torrent_ids, callback); this.sendTorrentActionRequests('torrent-verify', torrent_ids, callback, context);
}, },
reannounceTorrents: function(torrent_ids, callback) { reannounceTorrents: function(torrent_ids, callback) {
this.sendTorrentActionRequests('torrent-reannounce', torrent_ids, callback); this.sendTorrentActionRequests('torrent-reannounce', torrent_ids, callback);
@ -252,16 +250,16 @@ TransmissionRemote.prototype =
}, },
// Added queue calls // Added queue calls
moveTorrentsToTop: function(torrent_ids, callback) { moveTorrentsToTop: function(torrent_ids, callback, context) {
this.sendTorrentActionRequests(RPC._QueueMoveTop, torrent_ids, callback); this.sendTorrentActionRequests(RPC._QueueMoveTop, torrent_ids, callback, context);
}, },
moveTorrentsToBottom: function(torrent_ids, callback) { moveTorrentsToBottom: function(torrent_ids, callback, context) {
this.sendTorrentActionRequests(RPC._QueueMoveBottom, torrent_ids, callback); this.sendTorrentActionRequests(RPC._QueueMoveBottom, torrent_ids, callback, context);
}, },
moveTorrentsUp: function(torrent_ids, callback) { moveTorrentsUp: function(torrent_ids, callback, context) {
this.sendTorrentActionRequests(RPC._QueueMoveUp, torrent_ids, callback); this.sendTorrentActionRequests(RPC._QueueMoveUp, torrent_ids, callback, context);
}, },
moveTorrentsDown: function(torrent_ids, callback) { moveTorrentsDown: function(torrent_ids, callback, context) {
this.sendTorrentActionRequests(RPC._QueueMoveDown, torrent_ids, callback); this.sendTorrentActionRequests(RPC._QueueMoveDown, torrent_ids, callback, context);
} }
}; };