Commit dbd5c0d0 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Replicate jio 3.27.0 changes

parent 59622856
/*global window, rJS, RSVP, UriTemplate, URI, Query, SimpleQuery, ComplexQuery, jIO */ /*global window, rJS, RSVP, UriTemplate, URI, SimpleQuery, ComplexQuery, jIO */
/*jslint indent: 2, maxerr: 3, nomen: true */ /*jslint indent: 2, maxerr: 3, nomen: true */
(function (window, rJS, RSVP, UriTemplate, URI, Query, SimpleQuery, ComplexQuery, jIO) { (function (window, rJS, RSVP, UriTemplate, URI, SimpleQuery, ComplexQuery, jIO) {
"use strict"; "use strict";
function wrapJioCall(gadget, method_name, argument_list) { function wrapJioCall(gadget, method_name, argument_list) {
...@@ -42,12 +42,26 @@ ...@@ -42,12 +42,26 @@
function isSingleLocalRoles(parsed_query) { function isSingleLocalRoles(parsed_query) {
if ((parsed_query instanceof SimpleQuery) && if ((parsed_query instanceof SimpleQuery) &&
(parsed_query.operator === undefined) &&
(parsed_query.key === 'local_roles')) { (parsed_query.key === 'local_roles')) {
// local_roles:"Assignee" // local_roles:"Assignee"
return parsed_query.value; return parsed_query.value;
} }
} }
function isSingleDomain(parsed_query) {
if ((parsed_query instanceof SimpleQuery) &&
(parsed_query.operator === undefined) &&
(parsed_query.key !== undefined) &&
(parsed_query.key.indexOf('selection_domain_') === 0)) {
// domain_region:"europe/france"
var result = {};
result[parsed_query.key.slice('selection_domain_'.length)] =
parsed_query.value;
return result;
}
}
function isMultipleLocalRoles(parsed_query) { function isMultipleLocalRoles(parsed_query) {
var i, var i,
sub_query, sub_query,
...@@ -59,6 +73,7 @@ ...@@ -59,6 +73,7 @@
for (i = 0; i < parsed_query.query_list.length; i += 1) { for (i = 0; i < parsed_query.query_list.length; i += 1) {
sub_query = parsed_query.query_list[i]; sub_query = parsed_query.query_list[i];
if ((sub_query instanceof SimpleQuery) && if ((sub_query instanceof SimpleQuery) &&
(sub_query.key !== undefined) &&
(sub_query.key === 'local_roles')) { (sub_query.key === 'local_roles')) {
local_role_list.push(sub_query.value); local_role_list.push(sub_query.value);
} else { } else {
...@@ -104,28 +119,35 @@ ...@@ -104,28 +119,35 @@
}); });
}) })
.declareMethod('allDocs', function (option_dict) { .declareMethod('allDocs', function (options) {
// throw new Error('do not use all docs'); // throw new Error('do not use all docs');
if (option_dict.list_method_template === undefined) { if (options.list_method_template === undefined) {
return wrapJioCall(this, 'allDocs', arguments); return wrapJioCall(this, 'allDocs', arguments);
} }
var query = option_dict.query, var query = options.query,
i, i,
key,
parsed_query, parsed_query,
sub_query, sub_query,
result_list, result_list,
tmp_list = [], local_roles,
local_roles; local_role_found = false,
if (option_dict.query) { selection_domain,
parsed_query = jIO.QueryFactory.create(option_dict.query); sort_list = [];
if (options.query) {
parsed_query = jIO.QueryFactory.create(options.query);
result_list = isSingleLocalRoles(parsed_query); result_list = isSingleLocalRoles(parsed_query);
if (result_list) { if (result_list) {
query = undefined; query = undefined;
local_roles = result_list; local_roles = result_list;
} else { } else {
result_list = isSingleDomain(parsed_query);
if (result_list) {
query = undefined;
selection_domain = result_list;
} else {
result_list = isMultipleLocalRoles(parsed_query); result_list = isMultipleLocalRoles(parsed_query);
if (result_list) { if (result_list) {
...@@ -135,45 +157,73 @@ ...@@ -135,45 +157,73 @@
(parsed_query.operator === 'AND')) { (parsed_query.operator === 'AND')) {
// portal_type:"Person" AND local_roles:"Assignee" // portal_type:"Person" AND local_roles:"Assignee"
// AND selection_domain_region:"europe/france"
for (i = 0; i < parsed_query.query_list.length; i += 1) { for (i = 0; i < parsed_query.query_list.length; i += 1) {
sub_query = parsed_query.query_list[i]; sub_query = parsed_query.query_list[i];
if (!local_role_found) {
result_list = isSingleLocalRoles(sub_query); result_list = isSingleLocalRoles(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 = Query.objectToSearchText(parsed_query); query = jIO.Query.objectToSearchText(parsed_query);
i = parsed_query.query_list.length; local_role_found = true;
} else { } else {
result_list = isMultipleLocalRoles(sub_query); 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 = Query.objectToSearchText(parsed_query); query = jIO.Query.objectToSearchText(parsed_query);
i = parsed_query.query_list.length; 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];
} }
} }
} else {
selection_domain = result_list;
}
i -= 1;
}
} }
option_dict.query = query;
option_dict.local_roles = local_roles;
} }
if (option_dict.sort_on) {
for (i = 0; i < option_dict.sort_on.length; i += 1) {
tmp_list.push(JSON.stringify(option_dict.sort_on[i]));
} }
option_dict.sort_on = tmp_list;
} }
}
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);
}
options.query = query;
options.sort_on = sort_list;
options.local_roles = local_roles;
options.selection_domain = selection_domain;
return wrapJioCall( return wrapJioCall(
this, this,
'getAttachment', 'getAttachment',
[ [
// XXX Ugly hardcoded meaningless id... // XXX Ugly hardcoded meaningless id...
"erp5", "erp5",
new UriTemplate.parse(option_dict.list_method_template) new UriTemplate.parse(options.list_method_template)
.expand(option_dict), .expand(options),
{format: "json"} {format: "json"}
] ]
) )
...@@ -224,4 +274,4 @@ ...@@ -224,4 +274,4 @@
return wrapJioCall(this, 'post', [doc]); return wrapJioCall(this, 'post', [doc]);
}); });
}(window, rJS, RSVP, UriTemplate, URI, Query, SimpleQuery, ComplexQuery, jIO)); }(window, rJS, RSVP, UriTemplate, URI, SimpleQuery, ComplexQuery, jIO));
\ No newline at end of file \ No newline at end of file
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.59331.40212.55432</string> </value> <value> <string>965.65535.18355.17288</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1512454358.33</float> <float>1520357812.73</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