Commit 37ff22d0 authored by Sven Franck's avatar Sven Franck

merged put/post into storage.write method, cleanup old methods

parent ea43ce63
...@@ -1061,25 +1061,16 @@ ...@@ -1061,25 +1061,16 @@
* @param {object} obj Action Object * @param {object} obj Action Object
**/ **/
"new": function (obj) { "new": function (obj) {
storage.save(obj); storage.write(obj);
},
/**
* Add a server
* @method submit
* @param {object} obj Action Object
**/
"update_configuration": function (obj) {
storage.add(obj);
}, },
/** /**
* Add a user to the storage * Update an object
* @method submit * @method submit
* @param {object} obj Action Object * @param {object} obj Action Object
**/ **/
"add": function (obj) { "update": function (obj) {
storage.add(obj); storage.write(obj);
}, },
/** /**
...@@ -5528,23 +5519,36 @@ ...@@ -5528,23 +5519,36 @@
storage = {}; storage = {};
/** /**
* Generate a new object * Write to storage = POST or PUT
* @method newStore * @method write
* @param {object} obj Action object * @param {object} obj Action object
*/ */
storage.save = function (obj) { storage.write = function (obj) {
var form, data, valid, prefix, decode, id, answer, goto, type; var form, data, valid, prefix, decode, id, answer, goto, config, method;
form = document.getElementById(obj.id); form = document.getElementById(obj.id);
type = obj.state.url_pointer[obj.element.getAttribute("data-action")];
prefix = obj.id + "_"; prefix = obj.id + "_";
valid = storage.validate(obj); valid = storage.validate(obj);
data = storage.parseForm(valid, prefix, true); data = storage.parseForm(valid, prefix, true);
// post or put
if (form.identifier) {
method = "put";
config = {
"_view": obj.state.view
};
data._id = form.identifier.value;
} else {
config = {
"call": obj.state.url_pointer[obj.element.getAttribute("data-action")]
};
}
RSVP.resolve( RSVP.resolve(
app.storage_dict.items.post(data, {"call": type}) app.storage_dict.items[method || "post"](data, config)
) )
.then(function (response) { .then(function (response) {
util.loader("", "status_dict.saved", "check");
if (obj.state.callback) { if (obj.state.callback) {
answer = util.parse(response); answer = util.parse(response);
id = answer.id; id = answer.id;
...@@ -5845,7 +5849,6 @@ ...@@ -5845,7 +5849,6 @@
} else { } else {
replace = form_to_submit.id + "_"; replace = form_to_submit.id + "_";
obj = {}; obj = {};
// force portal_type // force portal_type
if (config.gadget.state.force_type) { if (config.gadget.state.force_type) {
config.gadget.state.type = config.gadget.state.force_type; config.gadget.state.type = config.gadget.state.force_type;
...@@ -7068,7 +7071,7 @@ ...@@ -7068,7 +7071,7 @@
// set callback and pointer on state // set callback and pointer on state
pass.state.callback = pass.config.property_dict.submit_to; pass.state.callback = pass.config.property_dict.submit_to;
pass.state.url_pointer = pass.config.property_dict.url_pointer; pass.state.url_pointer = pass.config.property_dict.url_pointer || {};
// tuck to gadget // tuck to gadget
...@@ -7332,84 +7335,42 @@ ...@@ -7332,84 +7335,42 @@
} }
} }
// if we have form_data we continue // loop over item and create a JIO record
if (pass.form_data === undefined) { for (i = 0; i < pass.items.length; i += 1) {
// loop over item and create a JIO record record = pass.items[i];
for (i = 0; i < pass.items.length; i += 1) { obj = {};
record = pass.items[i]; for (key in record) {
obj = {}; if (record.hasOwnProperty(key)) {
for (key in record) { if (validate) {
if (record.hasOwnProperty(key)) { if (answer.response[key]) {
if (validate) {
if (answer.response[key]) {
obj[key] = record[key];
} else {
util.error("store: field " + key +
" not defined for type = " + pass.type);
}
} else {
obj[key] = record[key]; obj[key] = record[key];
} else {
util.error("store: field " + key +
" not defined for type = " + pass.type);
} }
} else {
obj[key] = record[key];
} }
} }
}
// add portal type // add portal type
// obj.portal_type = pass.type; // obj.portal_type = pass.type;
// if an object identifier was set in the form, we PUT, else POST
if (obj.identifier) {
method = "put";
hacked_view = {"_view": pass.view};
obj._id = obj.identifier;
delete obj.identifier;
}
// store // if an object identifier was set in the form, we PUT, else POST
promises[i] = store[method || "post"](obj, hacked_view || {}) if (obj.identifier) {
.then(function (answer) { method = "put";
return answer; hacked_view = {"_view": pass.view};
}) obj._id = obj.identifier;
.fail(util.error); delete obj.identifier;
} }
} else {
console.log("SHOULD BE REDUNDANT") // store
promises[i] = store[method || "post"](obj, hacked_view || {})
// // do it again, Sam... .then(function (answer) {
// promises[0] = jIO.util.ajax({ return answer;
// "url": app.storage_dict.property_dict.items.storage_list[0].url, })
// "type": "GET", .fail(util.error);
// "xhrFields": {
// "withCredentials": true
// }
// })
// .then(function(response) {
// return jIO.util.ajax({
// "url": util.parse(response.target.responseText)._links.me.href,
// "xhrFields": {
// "withCredentials": true
// }
// });
// })
// .then(function (answer) {
// return jIO.util.ajax({
// "url": util.parse(answer.target.responseText)._actions[pass.fetch].href,
// "type": "POST",
// "data": pass.form_data,
// "xhrFields": {
// "withCredentials": true
// }
// });
// })
// .then(function (erp5_response) {
// header = erp5_response.target.getResponseHeader("Location");
// return RSVP.resolve({
// "status": 200,
// "foo": "bar",
// "location": header
// });
// })
// .fail(util.error);
} }
return RSVP.all(promises) return RSVP.all(promises)
......
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