Changeset 12778


Ignore:
Timestamp:
Aug 28, 2011, 6:05:46 AM (12 years ago)
Author:
jordan
Message:

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

Location:
trunk/web/javascript
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/javascript/transmission.js

    r12777 r12778  
    150150
    151151        loadDaemonPrefs: function(async) {
    152                 var tr = this;
    153152                this.remote.loadDaemonPrefs(function(data) {
    154153                        var o = data['arguments'];
    155154                        Prefs.getClutchPrefs(o);
    156                         tr.updatePrefs(o);
    157                 }, async);
     155                        this.updatePrefs(o);
     156                }, this, async);
    158157        },
    159158
    160159        loadDaemonStats: function(async) {
    161                 var tr = this;
    162160                this.remote.loadDaemonStats(function(data) {
    163                         tr.updateStats(data['arguments']);
    164                 }, async);
     161                        this.updateStats(data['arguments']);
     162                }, this, async);
    165163        },
    166164        checkPort: function(async) {
    167165                $('#port_test').text('checking ...');
    168                 var tr = this;
    169166                this.remote.checkPort(function(data) {
    170                         tr.updatePortStatus(data['arguments']);
    171                 }, async);
     167                        this.updatePortStatus(data['arguments']);
     168                }, this, async);
    172169        },
    173170
     
    12791276
    12801277        removeTorrents: function(torrents) {
    1281                 var tr = this;
    12821278                var ids = $.map(torrents, function(t) { return t.getId(); });
    1283                 this.remote.removeTorrents(ids, function() { tr.refreshTorrents();});
     1279                this.remote.removeTorrents(ids, this.refreshTorrents, this);
    12841280        },
    12851281
     
    13061302        },
    13071303        startTorrents: function(torrents, force) {
    1308                 var tr = this;
    1309                 var ids = $.map(torrents, function(t) { return t.getId(); });
    1310                 this.remote.startTorrents(ids, force, function() { tr.refreshTorrents(); });
     1304                this.remote.startTorrents($.map(torrents, function(t) {return t.getId();}),
     1305                                          force, this.refreshTorrents, this);
    13111306        },
    13121307        verifyTorrent: function(torrent) {
     
    13141309        },
    13151310        verifyTorrents: function(torrents) {
    1316                 var tr = this;
    1317                 var ids = $.map(torrents, function(t) { return t.getId(); });
    1318                 this.remote.verifyTorrents(ids, function() { tr.refreshTorrents(); });
     1311                this.remote.verifyTorrents($.map(torrents, function(t) {return t.getId();}),
     1312                                           this.refreshTorrents, this);
    13191313        },
    13201314
     
    13231317        },
    13241318        reannounceTorrents: function(torrents) {
    1325                 var tr = this;
    1326                 var ids = $.map(torrents, function(t) { return t.getId(); });
    1327                 this.remote.reannounceTorrents(ids, function() { tr.refreshTorrents(); });
     1319                this.remote.reannounceTorrents($.map(torrents, function(t) {return t.getId();}),
     1320                                               this.refreshTorrents, this);
    13281321        },
    13291322
     
    13381331        },
    13391332        stopTorrents: function(torrents) {
    1340                 var tr = this;
    1341                 var ids = $.map(torrents, function(t) { return t.getId(); });
    1342                 this.remote.stopTorrents(ids,   function() { tr.refreshTorrents();});
     1333                this.remote.stopTorrents($.map(torrents.slice(0), function(t) {return t.getId();}),
     1334                                         this.refreshTorrents, this);
    13431335        },
    13441336        changeFileCommand: function(command, rows) {
     
    13631355        // Queue
    13641356        moveTop: function() {
    1365                 var tr = this;
    1366                 var ids = this.getSelectedTorrentIds();
    1367                 this.remote.moveTorrentsToTop(ids, function() { tr.refreshTorrents();});
     1357                this.remote.moveTorrentsToTop(this.getSelectedTorrentIds(),
     1358                                              this.refreshTorrents, this);
    13681359        },
    13691360        moveUp: function() {
    1370                 var tr = this;
    1371                 var ids = this.getSelectedTorrentIds();
    1372                 this.remote.moveTorrentsUp(ids, function() { tr.refreshTorrents();});
     1361                this.remote.moveTorrentsUp(this.getSelectedTorrentIds(),
     1362                                           this.refreshTorrents, this);
    13731363        },
    13741364        moveDown: function() {
    1375                 var tr = this;
    1376                 var ids = this.getSelectedTorrentIds();
    1377                 this.remote.moveTorrentsDown(ids, function() { tr.refreshTorrents();});
     1365                this.remote.moveTorrentsDown(this.getSelectedTorrentIds(),
     1366                                             this.refreshTorrents, this);
    13781367        },
    13791368        moveBottom: function() {
    1380                 var tr = this;
    1381                 var ids = this.getSelectedTorrentIds();
    1382                 this.remote.moveTorrentsToBottom(ids, function() { tr.refreshTorrents();});
    1383         },
    1384 
     1369                this.remote.moveTorrentsToBottom(this.getSelectedTorrentIds(),
     1370                                                 this.refreshTorrents, this);
     1371        },
    13851372
    13861373        /***
     
    17401727                        return;
    17411728
    1742                 var tr = this;
    17431729                var html = [ ];
    17441730                var na = 'N/A';
     
    17701756                                }
    17711757
    1772                                 var lastAnnounceStatusHash = tr.lastAnnounceStatus(tracker);
    1773                                 var announceState = tr.announceState(tracker);
    1774                                 var lastScrapeStatusHash = tr.lastScrapeStatus(tracker);
     1758                                var lastAnnounceStatusHash = this.lastAnnounceStatus(tracker);
     1759                                var announceState = this.announceState(tracker);
     1760                                var lastScrapeStatusHash = this.lastScrapeStatus(tracker);
    17751761
    17761762                                // Display construction
  • trunk/web/javascript/transmission.remote.js

    r12767 r12778  
    9797        },
    9898
    99         sendRequest: function(data, success, async) {
     99        sendRequest: function(data, callback, context, async) {
    100100                remote = this;
    101101                if (typeof async != 'boolean')
     
    111111                        beforeSend: function(XHR){ remote.appendSessionId(XHR); },
    112112                        error: function(request, error_string, exception){ remote.ajaxError(request, error_string, exception, ajaxSettings); },
    113                         success: success,
     113                        success: callback,
     114                        context: context,
    114115                        async: async
    115116                };
     
    118119        },
    119120
    120         loadDaemonPrefs: function(callback, async) {
     121        loadDaemonPrefs: function(callback, context, async) {
    121122                var o = { method: 'session-get' };
    122                 this.sendRequest(o, callback, async);
     123                this.sendRequest(o, callback, context, async);
    123124        },
    124125       
    125         checkPort: function(callback, async) {
     126        checkPort: function(callback, context, async) {
    126127                var o = { method: 'port-test' };
    127                 this.sendRequest(o, callback, async);
     128                this.sendRequest(o, callback, context, async);
    128129        },
    129130       
    130         loadDaemonStats: function(callback, async) {
     131        loadDaemonStats: function(callback, context, async) {
    131132                var o = { method: 'session-stats' };
    132                 this.sendRequest(o, callback, async);
     133                this.sendRequest(o, callback, context, async);
    133134        },
    134135
     
    136137                var o = {
    137138                        method: 'torrent-get',
    138                         'arguments': {
     139                                'arguments': {
    139140                                'fields': fields,
    140141                        }
     
    164165        },
    165166
    166         sendTorrentSetRequests: function(method, torrent_ids, args, callback) {
     167        sendTorrentSetRequests: function(method, torrent_ids, args, callback, context) {
    167168                if (!args) args = { };
    168169                args['ids'] = torrent_ids;
     
    171172                        arguments: args
    172173                };
    173 
    174                 this.sendRequest(o, function(data) {
    175                         callback();
    176                 });
    177         },
    178 
    179         sendTorrentActionRequests: function(method, torrent_ids, callback) {
    180                 this.sendTorrentSetRequests(method, torrent_ids, null, callback);
    181         },
    182 
    183         startTorrents: function(torrent_ids, noqueue, callback) {
     174                this.sendRequest(o, callback, context);
     175        },
     176
     177        sendTorrentActionRequests: function(method, torrent_ids, callback, context) {
     178                this.sendTorrentSetRequests(method, torrent_ids, null, callback, context);
     179        },
     180
     181        startTorrents: function(torrent_ids, noqueue, callback, context) {
    184182                var name = noqueue ? 'torrent-start-now' : 'torrent-start';
    185                 this.sendTorrentActionRequests(name, torrent_ids, callback);
    186         },
    187         stopTorrents: function(torrent_ids, callback) {
    188                 this.sendTorrentActionRequests('torrent-stop', torrent_ids, callback);
    189         },
    190         removeTorrents: function(torrent_ids, callback) {
    191                 this.sendTorrentActionRequests('torrent-remove', torrent_ids, callback);
     183                this.sendTorrentActionRequests(name, torrent_ids, callback, context);
     184        },
     185        stopTorrents: function(torrent_ids, callback, context) {
     186                this.sendTorrentActionRequests('torrent-stop', torrent_ids, callback, context);
     187        },
     188        removeTorrents: function(torrent_ids, callback, context) {
     189                this.sendTorrentActionRequests('torrent-remove', torrent_ids, callback, context);
    192190        },
    193191        removeTorrentsAndData: function(torrents) {
     
    210208                });
    211209        },
    212         verifyTorrents: function(torrent_ids, callback) {
    213                 this.sendTorrentActionRequests('torrent-verify', torrent_ids, callback);
     210        verifyTorrents: function(torrent_ids, callback, context) {
     211                this.sendTorrentActionRequests('torrent-verify', torrent_ids, callback, context);
    214212        },
    215213        reannounceTorrents: function(torrent_ids, callback) {
     
    253251
    254252        // Added queue calls
    255         moveTorrentsToTop: function(torrent_ids, callback) {
    256                 this.sendTorrentActionRequests(RPC._QueueMoveTop, torrent_ids, callback);
    257         },
    258         moveTorrentsToBottom: function(torrent_ids, callback) {
    259                 this.sendTorrentActionRequests(RPC._QueueMoveBottom, torrent_ids, callback);
    260         },
    261         moveTorrentsUp: function(torrent_ids, callback) {
    262                 this.sendTorrentActionRequests(RPC._QueueMoveUp, torrent_ids, callback);
    263         },
    264         moveTorrentsDown: function(torrent_ids, callback) {
    265                 this.sendTorrentActionRequests(RPC._QueueMoveDown, torrent_ids, callback);
     253        moveTorrentsToTop: function(torrent_ids, callback, context) {
     254                this.sendTorrentActionRequests(RPC._QueueMoveTop, torrent_ids, callback, context);
     255        },
     256        moveTorrentsToBottom: function(torrent_ids, callback, context) {
     257                this.sendTorrentActionRequests(RPC._QueueMoveBottom, torrent_ids, callback, context);
     258        },
     259        moveTorrentsUp: function(torrent_ids, callback, context) {
     260                this.sendTorrentActionRequests(RPC._QueueMoveUp, torrent_ids, callback, context);
     261        },
     262        moveTorrentsDown: function(torrent_ids, callback, context) {
     263                this.sendTorrentActionRequests(RPC._QueueMoveDown, torrent_ids, callback, context);
    266264        }
    267265};
Note: See TracChangeset for help on using the changeset viewer.