1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 08:43:27 +00:00

part two of r8358. patch by kjg

This commit is contained in:
Charles Kerr 2009-05-08 15:02:22 +00:00
parent 6559fbbd16
commit 3b06df5e1a

View file

@ -35,13 +35,23 @@ TransmissionRemote.prototype =
initialize: function(controller) { initialize: function(controller) {
this._controller = controller; this._controller = controller;
this._error = ''; this._error = '';
this._token = '';
}, },
/* /*
* Display an error if an ajax request fails, and stop sending requests * Display an error if an ajax request fails, and stop sending requests
* or on a 409, globally set the X-Transmission-Session-Id and resend
*/ */
ajaxError: function(request, error_string, exception) { ajaxError: function(request, error_string, exception, ajaxObject) {
remote = this; remote = this;
// set the Transmission-Session-Id on a 409
if(request.status == 409 && (token = request.getResponseHeader('X-Transmission-Session-Id'))){
remote._token = token;
$.ajax(ajaxObject);
return;
}
remote._error = request.responseText remote._error = request.responseText
? request.responseText.trim().replace(/(<([^>]+)>)/ig,"") ? request.responseText.trim().replace(/(<([^>]+)>)/ig,"")
: ""; : "";
@ -57,6 +67,10 @@ TransmissionRemote.prototype =
remote._controller.togglePeriodicRefresh(false); remote._controller.togglePeriodicRefresh(false);
}, },
appendSessionId: function(XHR) {
XHR.setRequestHeader('X-Transmission-Session-Id', this._token);
},
sendRequest: function( data, success ) { sendRequest: function( data, success ) {
remote = this; remote = this;
$.ajax( { $.ajax( {
@ -66,7 +80,8 @@ TransmissionRemote.prototype =
dataType: 'json', dataType: 'json',
cache: false, cache: false,
data: $.toJSON(data), data: $.toJSON(data),
error: function(request, error_string, exception){ remote.ajaxError(request, error_string, exception) }, beforeSend: function(XHR){ remote.appendSessionId(XHR) },
error: function(request, error_string, exception){ remote.ajaxError(request, error_string, exception, this) },
success: success success: success
} ); } );
}, },