Commit d0ac9f8f authored by Sven Franck's avatar Sven Franck

first pass at running requests through POST with all hacks in storage

parent 093bd8cb
......@@ -75,10 +75,22 @@
HateoasStorage.prototype.post = function (command, metadata, options) {
return this._getSiteDocument()
// HACK: get me... default _add, otherwise passed through options!
.then(function (site_hal) {
var post_action = site_hal._actions.add,
data = new FormData(),
key;
return jIO.util.ajax({
"url": site_hal._links.me.href,
"xhrFields": {
"withCredentials": true
}
})
})
.then(function (opts) {
var doc_hal, custom_action, post_action, data, key;
doc_hal = JSON.parse(opts.target.responseText);
custom_action = doc_hal._actions[options.call];
post_action = custom_action || site_hal._actions.add;
data = new FormData();
for (key in metadata) {
if (metadata.hasOwnProperty(key)) {
......@@ -86,22 +98,24 @@
data.append(key, metadata[key]);
}
}
return jIO.util.ajax({
"type": post_action.method,
"url": post_action.href,
"data": data,
"xhrFields": {
withCredentials: true
"withCredentials": true
}
});
}).then(function (doc) {
})
.then(function (doc) {
// XXX Really depend on server response...
var new_document_url = doc.target.getResponseHeader("Location");
return jIO.util.ajax({
"type": "GET",
"url": new_document_url,
"xhrFields": {
withCredentials: true
"withCredentials": true
}
});
}).then(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