Commit d1895b24 authored by Aurélien Vermylen's avatar Aurélien Vermylen

Make tests pass (except usual CryptStorage and stringify) and build.

parent 0e69426d
This diff is collapsed.
This diff is collapsed.
......@@ -11,7 +11,7 @@
/*jslint nomen: true, unparam: true */
/*global jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery, btoa*/
SimpleQuery, ComplexQuery*/
(function (jIO, UriTemplate, FormData, RSVP, URI, Blob,
SimpleQuery, ComplexQuery) {
......@@ -24,9 +24,8 @@
"type": "GET",
"url": storage._url,
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
})
.push(function (event) {
......@@ -51,9 +50,8 @@
view: options._view
}),
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
})
.push(undefined, function (error) {
......@@ -130,8 +128,8 @@
});
}
function extractPropertyFromForm(storage, id) {
return storage.getAttachment(id, "view")
function extractPropertyFromForm(context, id) {
return context.getAttachment(id, "view")
.push(function (blob) {
return jIO.util.readBlobAsText(blob);
})
......@@ -151,17 +149,20 @@
}
this._url = spec.url;
this._default_view_reference = spec.default_view_reference;
this._headers = null;
this._thisCredentials = true;
if (spec.login !== undefined && spec.password !== undefined) {
this._headers = {"Authorization": "Basic "
+ btoa(spec.login + ":" + spec.password)};
this._thisCredentials = false;
}
}
function convertJSONToGet(json) {
return json.data;
var key,
result = json.data;
// Remove all ERP5 hateoas links / convert them into jIO ID
for (key in result) {
if (result.hasOwnProperty(key)) {
if (!result[key]) {
delete result[key];
}
}
}
return result;
}
ERP5Storage.prototype.get = function (id) {
......@@ -172,7 +173,7 @@
};
ERP5Storage.prototype.post = function (data) {
var storage = this,
var context = this,
new_id;
return getSiteDocument(this)
......@@ -185,16 +186,15 @@
url: site_hal._actions.add.href,
data: form_data,
xhrFields: {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
})
.push(function (evt) {
var location = evt.target.getResponseHeader("X-Location"),
uri = new URI(location);
new_id = uri.segment(2);
return storage.put(new_id, data);
return context.put(new_id, data);
})
.push(function () {
return new_id;
......@@ -202,9 +202,9 @@
};
ERP5Storage.prototype.put = function (id, data) {
var storage = this;
var context = this;
return extractPropertyFromForm(storage, id)
return extractPropertyFromForm(context, id)
.push(function (result) {
var key,
json = result.form_data,
......@@ -237,7 +237,7 @@
403
);
}
return storage.putAttachment(
return context.putAttachment(
id,
result.action_href,
new Blob([JSON.stringify(form_data)], {type: "application/json"})
......@@ -246,10 +246,10 @@
};
ERP5Storage.prototype.allAttachments = function (id) {
var storage = this;
var context = this;
return getDocumentAndHateoas(this, id)
.push(function () {
if (storage._default_view_reference === undefined) {
if (context._default_view_reference === undefined) {
return {
links: {}
};
......@@ -262,7 +262,6 @@
};
ERP5Storage.prototype.getAttachment = function (id, action, options) {
var storage = this;
if (options === undefined) {
options = {};
}
......@@ -309,9 +308,8 @@
"dataType": "blob",
"url": action,
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
};
if (options.start !== undefined || options.end !== undefined) {
start = options.start || 0;
......@@ -331,11 +329,7 @@
}
range = "bytes=" + start + "-" + end;
}
if (storage._headers === undefined) {
request_options.headers = {Range: range};
} else {
request_options.headers.Range = range;
}
request_options.headers = {Range: range};
}
return jIO.util.ajax(request_options);
})
......@@ -354,7 +348,6 @@
};
ERP5Storage.prototype.putAttachment = function (id, name, blob) {
var storage = this;
// Assert we use a callable on a document from the ERP5 site
if (name.indexOf(this._url) !== 0) {
throw new jIO.util.jIOError("Can not store outside ERP5: " +
......@@ -396,9 +389,8 @@
"data": data,
"dataType": "blob",
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
});
};
......@@ -447,7 +439,6 @@
// jIO.Query.objectToSearchText(options.query) :
// undefined);
// }
var storage = this;
return getSiteDocument(this)
.push(function (site_hal) {
var query = options.query,
......@@ -516,9 +507,8 @@
local_roles: local_roles
}),
"xhrFields": {
withCredentials: storage._thisCredentials
},
"headers": storage._headers
withCredentials: true
}
});
})
.push(function (response) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment