Commit d7b7edcc authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Create a function

This commit does not change the behaviour of the gadget.

The goal is only to make the next commit more readable.
parent 2eb01519
...@@ -120,113 +120,118 @@ ...@@ -120,113 +120,118 @@
}) })
.declareMethod('allDocs', function (options) { .declareMethod('allDocs', function (options) {
var context = this;
// throw new Error('do not use all docs'); // throw new Error('do not use all docs');
if (options.list_method_template === undefined) { if (options.list_method_template === undefined) {
return wrapJioCall(this, 'allDocs', arguments); return wrapJioCall(this, 'allDocs', arguments);
} }
var query = options.query, function triggerAllDocs() {
i, var query = options.query,
key, i,
parsed_query, key,
sub_query, parsed_query,
result_list, sub_query,
local_roles, result_list,
local_role_found = false, local_roles,
selection_domain, local_role_found = false,
sort_list = []; selection_domain,
if (options.query) { sort_list = [];
parsed_query = jIO.QueryFactory.create(options.query); if (options.query) {
result_list = isSingleLocalRoles(parsed_query); parsed_query = jIO.QueryFactory.create(options.query);
if (result_list) { result_list = isSingleLocalRoles(parsed_query);
query = undefined;
local_roles = result_list;
} else {
result_list = isSingleDomain(parsed_query);
if (result_list) { if (result_list) {
query = undefined; query = undefined;
selection_domain = result_list; local_roles = result_list;
} else { } else {
result_list = isSingleDomain(parsed_query);
result_list = isMultipleLocalRoles(parsed_query);
if (result_list) { if (result_list) {
query = undefined; query = undefined;
local_roles = result_list; selection_domain = result_list;
} else if ((parsed_query instanceof ComplexQuery) && } else {
(parsed_query.operator === 'AND')) {
// portal_type:"Person" AND local_roles:"Assignee" result_list = isMultipleLocalRoles(parsed_query);
// AND selection_domain_region:"europe/france" if (result_list) {
for (i = 0; i < parsed_query.query_list.length; i += 1) { query = undefined;
sub_query = parsed_query.query_list[i]; local_roles = result_list;
} else if ((parsed_query instanceof ComplexQuery) &&
(parsed_query.operator === 'AND')) {
if (!local_role_found) { // portal_type:"Person" AND local_roles:"Assignee"
result_list = isSingleLocalRoles(sub_query); // AND selection_domain_region:"europe/france"
if (result_list) { for (i = 0; i < parsed_query.query_list.length; i += 1) {
local_roles = result_list; sub_query = parsed_query.query_list[i];
parsed_query.query_list.splice(i, 1);
query = jIO.Query.objectToSearchText(parsed_query); if (!local_role_found) {
local_role_found = true; result_list = isSingleLocalRoles(sub_query);
} else {
result_list = isMultipleLocalRoles(sub_query);
if (result_list) { if (result_list) {
local_roles = result_list; local_roles = result_list;
parsed_query.query_list.splice(i, 1); parsed_query.query_list.splice(i, 1);
query = jIO.Query.objectToSearchText(parsed_query); query = jIO.Query.objectToSearchText(parsed_query);
local_role_found = true; local_role_found = true;
} else {
result_list = isMultipleLocalRoles(sub_query);
if (result_list) {
local_roles = result_list;
parsed_query.query_list.splice(i, 1);
query = jIO.Query.objectToSearchText(parsed_query);
local_role_found = true;
}
} }
} }
}
result_list = isSingleDomain(sub_query); result_list = isSingleDomain(sub_query);
if (result_list) { if (result_list) {
parsed_query.query_list.splice(i, 1); parsed_query.query_list.splice(i, 1);
query = jIO.Query.objectToSearchText(parsed_query); query = jIO.Query.objectToSearchText(parsed_query);
if (selection_domain) { if (selection_domain) {
for (key in result_list) { for (key in result_list) {
if (result_list.hasOwnProperty(key)) { if (result_list.hasOwnProperty(key)) {
selection_domain[key] = result_list[key]; selection_domain[key] = result_list[key];
}
} }
} else {
selection_domain = result_list;
} }
} else { i -= 1;
selection_domain = result_list;
} }
i -= 1;
}
}
} }
} }
} }
} }
}
if (options.sort_on) { if (options.sort_on) {
for (i = 0; i < options.sort_on.length; i += 1) { for (i = 0; i < options.sort_on.length; i += 1) {
sort_list.push(JSON.stringify(options.sort_on[i])); sort_list.push(JSON.stringify(options.sort_on[i]));
}
}
if (selection_domain) {
selection_domain = JSON.stringify(selection_domain);
} }
}
if (selection_domain) { options.query = query;
selection_domain = JSON.stringify(selection_domain); options.sort_on = sort_list;
} options.local_roles = local_roles;
options.selection_domain = selection_domain;
options.query = query; return wrapJioCall(
options.sort_on = sort_list; context,
options.local_roles = local_roles; 'getAttachment',
options.selection_domain = selection_domain; [
// XXX Ugly hardcoded meaningless id...
"erp5",
new UriTemplate.parse(options.list_method_template)
.expand(options),
{format: "json"}
]
);
}
return wrapJioCall( return triggerAllDocs()
this,
'getAttachment',
[
// XXX Ugly hardcoded meaningless id...
"erp5",
new UriTemplate.parse(options.list_method_template)
.expand(options),
{format: "json"}
]
)
.push(function (catalog_json) { .push(function (catalog_json) {
var data = catalog_json._embedded.contents || [], var data = catalog_json._embedded.contents || [],
summary = catalog_json._embedded.sum || [], summary = catalog_json._embedded.sum || [],
......
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>970.5239.3705.62003</string> </value> <value> <string>975.47596.63165.63232</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1536227971.17</float> <float>1557912100.81</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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