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

View file

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