1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-19 08:52:22 +01:00

On use jqXHR as argument to JSONResponse

This commit is contained in:
Thomas Tanghus 2014-03-23 14:14:36 +01:00
parent ccb7490630
commit f0ee17d22c
3 changed files with 16 additions and 15 deletions

View File

@ -301,7 +301,7 @@ OC.Contacts = OC.Contacts || {};
done: function (e, data) {
self.$importStatusText.text(t('contacts', 'Importing...'));
console.log('Upload done:', data);
self.doImport(self.storage.formatResponse(data.result, data.jqXHR));
self.doImport(self.storage.formatResponse(data.jqXHR));
},
fail: function(e, data) {
console.log('fail', data);

View File

@ -150,6 +150,8 @@ OC.notify = function(params) {
}
};
(function(window, $, OC) {
'use strict';
OC.Contacts = OC.Contacts || {
init:function() {
@ -815,7 +817,7 @@ OC.Contacts = OC.Contacts || {
},
fail: function(e, data) {
console.log('fail', data);
var response = self.storage.formatResponse(data.jqXHR.responseJSON, data.jqXHR);
var response = self.storage.formatResponse(data.jqXHR);
$(document).trigger('status.contacts.error', response);
}
});
@ -1537,7 +1539,7 @@ OC.Contacts = OC.Contacts || {
);
var jqXHR = $.getJSON(url, {path: path}, function(response) {
console.log('response', response);
response = self.storage.formatResponse(response, jqXHR);
response = self.storage.formatResponse(jqXHR);
if(!response.error) {
self.editPhoto(metadata, response.data.tmp);
} else {
@ -1553,7 +1555,7 @@ OC.Contacts = OC.Contacts || {
);
console.log('url', url);
var jqXHR = $.getJSON(url, function(response) {
response = self.storage.formatResponse(response, jqXHR);
response = self.storage.formatResponse(jqXHR);
if(!response.error) {
self.editPhoto(metadata, response.data.tmp);
} else {

View File

@ -3,10 +3,11 @@ OC.Contacts = OC.Contacts || {};
(function(window, $, OC) {
'use strict';
var JSONResponse = function(response, jqXHR) {
var JSONResponse = function(jqXHR) {
this.getAllResponseHeaders = jqXHR.getAllResponseHeaders;
this.getResponseHeader = jqXHR.getResponseHeader;
this.statusCode = jqXHR.status;
var response = jqXHR.responseJSON;
this.error = false;
// 204 == No content
// 304 == Not modified
@ -59,14 +60,11 @@ OC.Contacts = OC.Contacts || {};
/**
* When the response isn't returned from requestRoute(), you can
* wrap it in a JSONResponse so that it's parsable by other objects.
* FIXME: Reverse the order of the arguments as jqXHR should contain
* everything needed.
*
* @param object response The body of the response
* @param XMLHTTPRequest http://api.jquery.com/jQuery.ajax/#jqXHR
*/
Storage.prototype.formatResponse = function(response, jqXHR) {
return new JSONResponse(response, jqXHR);
Storage.prototype.formatResponse = function(jqXHR) {
return new JSONResponse(jqXHR);
};
/**
@ -621,13 +619,14 @@ OC.Contacts = OC.Contacts || {};
var jqxhr = $.ajax(ajaxParams)
.done(function(response, textStatus, jqXHR) {
defer.resolve(new JSONResponse(response, jqXHR));
console.log(jqXHR);
defer.resolve(new JSONResponse(jqXHR));
})
.fail(function(jqXHR/*, textStatus, error*/) {
console.log(jqXHR);
var response = jqXHR.responseText ? $.parseJSON(jqXHR.responseText) : null;
console.log('response', response);
defer.reject(new JSONResponse(response, jqXHR));
defer.reject(new JSONResponse(jqXHR));
});
return defer.promise();