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