Commit 1d52853b authored by Sven Franck's avatar Sven Franck

added custom handler for portal_type person

parent 026d9e34
......@@ -17,6 +17,65 @@
**/
map = {};
/**
* Custom handlers necessary to make calls to ERP5 storage. These should
* not be needed, but are currently necessary.
* @object map.handlers
**/
// TODO: remove!
map.handlers = {
/**
* @method person
* @param {object} reply Object received from previous chain element
* @param {object} response Object object passed on to next element
**/
"person": function (reply) {
var config, property, props, pass = reply.pass;
if (storage) {
config = {
"url": storage.items.dict.url,
"type": "GET",
"data": JSON.stringify({"_id":""})
};
// access storage
return jIO.util.ajax(config)
.then(function(response) {
return jIO.util.ajax({
"url": util.parse(response.target.responseText)._links.me.href
})
.then(function(answer){
if (pass.config.initial_query) {
for (property in pass.config.initial_query) {
if (pass.config.initial_query.hasOwnProperty(property)) {
delete pass.config.initial_query[property];
}
}
pass.config.initial_query.query = {
"_id": util.parse(answer.target.responseText)._relative_url
};
// pass hacked query back into chain
if (reply.response) {
return {
"response": util.parse(reply.response),
"pass": pass
};
}
return {
"pass": pass
}
}
}).fail(util.error);
}).fail(util.error);
}
return (reply);
}
};
/**
* Add connection to application standard actions or add own actions here
* @object map.actions
......@@ -1208,6 +1267,8 @@
if (content_dict.property_dict.definition) {
storage[content_dict.property_dict.definition.application_name] =
jIO.createJIO(content_dict.property_dict.definition);
storage[content_dict.property_dict.definition.application_name].dict =
content_dict.property_dict.definition;
} else {
util.error("makeStorage: Missing storage definition");
}
......@@ -5270,13 +5331,14 @@
// WARNING: complex_queries dependency!
app.generateQueryObject = function (query, type, key, value, field_list, restore) {
var property, wrap, query_object, query_clean, default_query, obj,
is_value, i;
is_value, i, is_id;
is_value = value && value !== "";
is_id = query && query.query && query.query._id;
// "id" = "bar" => THIS SHOULD BE GET!
if (is_value && key && key === "_id") {
obj = {"_id": value};
if (is_value && key && key === "_id" || is_id) {
obj = {"_id": is_id ? query.query._id : value};
// ALLDOCS
} else {
......@@ -5724,7 +5786,6 @@
pass.field_list = storage.makeSelectList(pass.config.scheme);
}
}
pass.state.query = app.generateQueryObject(
pass.config.initial_query,
pass.type,
......@@ -5736,6 +5797,7 @@
// get an item?
if (pass.mode !== "new" || pass.config.initial_query !== undefined) {
console.log("ALORE")
return app.fetchData({
"storage": "items",
"query": pass.state.query,
......@@ -5748,6 +5810,36 @@
};
};
/**
* Run any mappings required for this datatype to correctly access data
* @method mapToStorage
**/
app.mapToStorage = function (reply) {
var pass = reply.pass, answer;
if (reply.response) {
// mapping required for this portal_type
if (pass.config && pass.config.portal_type_mapper) {
return map.handlers[pass.config.portal_type_mapper](reply);
}
// standard procedure
answer = util.parse(answer);
return {
"response": answer,
"pass": pass
};
}
// mapping
if (pass.config && pass.config.portal_type_mapper) {
return map.handlers[pass.config.portal_type_mapper](reply);
}
// standard
return {
"pass": pass
};
};
/**
* Fetch total number of records
* @method fetchPortalTypeDataTotal
......@@ -5915,7 +6007,7 @@
}
// 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) {
......@@ -6166,6 +6258,7 @@
.then(app.fetchFields)
.then(app.store)
.then(app.fetchDataTotal)
.then(app.mapToStorage)
.then(app.fetchDataQuery)
.then(app.makeContent)
.fail(util.error);
......@@ -6987,7 +7080,7 @@
/**
* parse to JSON if element is not in JSON
* @parseIfNeeded
* @parse
* @param {object/string} data Data to parse
* @return {object} object Parsed object
*/
......
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