Commit 67e51cea authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_web_renderjs_ui: set graphic type in the URL and render it automatically if exists

parent fd66974a
...@@ -520,62 +520,67 @@ ...@@ -520,62 +520,67 @@
} }
} }
} }
return gadget.getUrlParameter("graphic_type")
return gadget.changeState({ .push(function (graphic_type) {
key: field_json.key, return gadget.changeState({
title: field_json.title, key: field_json.key,
editable: field_json.editable, title: field_json.title,
editable: field_json.editable,
begin_from: parseInt(result_list[0] || '0', 10) || 0,
begin_from: parseInt(result_list[0] || '0', 10) || 0,
// sorting is either specified in URL per listbox or we take default sorting from JSON's 'sort' attribute
sort_list_json: JSON.stringify(result_list[1] || field_json.sort.map(jioize_sort)), // sorting is either specified in URL per listbox or we take default sorting from JSON's 'sort' attribute
sort_list_json: JSON.stringify(result_list[1] || field_json.sort.map(jioize_sort)),
selection_name: field_json.selection_name,
checked_uid_list: field_json.checked_uid_list || [], selection_name: field_json.selection_name,
checked_uid_list: field_json.checked_uid_list || [],
show_anchor: field_json.show_anchor,
show_stat: field_json.show_stat, show_anchor: field_json.show_anchor,
show_count: field_json.show_count, show_stat: field_json.show_stat,
show_select: field_json.show_select, show_count: field_json.show_count,
form_id: result_list[3].pt, show_select: field_json.show_select,
form_id: result_list[3].pt,
line_icon: field_json.line_icon,
query: field_json.query, line_icon: field_json.line_icon,
query_string: query_string, query: field_json.query,
lines: field_json.lines, query_string: query_string,
list_method: field_json.list_method, lines: field_json.lines,
list_method_template: field_json.list_method_template, list_method: field_json.list_method,
list_method_template: field_json.list_method_template,
option_list: option_list,
domain_list_json: JSON.stringify(field_json.domain_root_list || []), option_list: option_list,
domain_dict_json: JSON.stringify(field_json.domain_dict || {}), domain_list_json: JSON.stringify(field_json.domain_root_list || []),
domain_dict_json: JSON.stringify(field_json.domain_dict || {}),
column_list_json: JSON.stringify(displayed_column_item_list),
displayable_column_list_json: column_list_json: JSON.stringify(displayed_column_item_list),
JSON.stringify(displayable_column_item_list), displayable_column_list_json:
JSON.stringify(displayable_column_item_list),
sort_column_list_json: JSON.stringify(sort_column_list),
search_column_list_json: JSON.stringify(search_column_list), sort_column_list_json: JSON.stringify(sort_column_list),
sort_class: field_json.sort_column_list.length ? "" : "ui-disabled", search_column_list_json: JSON.stringify(search_column_list),
sort_class: field_json.sort_column_list.length ? "" : "ui-disabled",
field_id: options.field_id,
extended_search: options.extended_search, field_id: options.field_id,
hide_class: options.hide_enabled ? "" : "ui-disabled", extended_search: options.extended_search,
configure_class: options.configure_enabled ? "" : "ui-disabled", hide_class: options.hide_enabled ? "" : "ui-disabled",
command: field_json.command || 'index', configure_class: options.configure_enabled ? "" : "ui-disabled",
command: field_json.command || 'index',
// Force line calculation in any case
render_timestamp: new Date().getTime(), // Force line calculation in any case
allDocs_result: undefined, render_timestamp: new Date().getTime(),
default_value: field_json.default, allDocs_result: undefined,
default_value: field_json["default"],
// No error message
has_error: false, // No error message
show_line_selector: false, has_error: false,
show_select_action: false, show_line_selector: false,
show_clipboard_action: false show_select_action: false,
}); show_clipboard_action: false,
// graphic
graphic_type: graphic_type
});
});
}); });
return queue; return queue;
}) })
...@@ -1186,97 +1191,99 @@ ...@@ -1186,97 +1191,99 @@
); );
} }
domsugar(gadget.element.querySelector(".graphic_section"), [ domsugar(gadget.element.querySelector(".graphic_section"), [
domsugar("select", sub_element_list), domsugar("select", {
"name": "GraphicSelect",
"value": gadget.state.graphic_type
}, sub_element_list),
domsugar("div", {"class": "graphic_area"}) domsugar("div", {"class": "graphic_area"})
]); ]);
}); });
}); });
} else if (modification_dict.hasOwnProperty("graphic_type") && if (gadget.state.graphic_type && gadget.state.graphic_type !== "") {
modification_dict.graphic_type !== "") { result_queue
return result_queue .push(function () {
.push(function () { return gadget.declareGadget('gadget_graphic.html', {
return gadget.declareGadget('gadget_graphic.html', { scope: 'gadget_graphic',
scope: 'gadget_graphic', element: gadget.element.querySelector(".graphic_area")
element: gadget.element.querySelector(".graphic_area") });
}); })
}) .push(function (graphic_gadget) {
.push(function (graphic_gadget) { var group_by,
var group_by, group_by_title,
group_by_title, column_list_json = JSON.parse(gadget.state.column_list_json),
column_list_json = JSON.parse(gadget.state.column_list_json), domain_dict = JSON.parse(gadget.state.domain_dict_json),
domain_dict = JSON.parse(gadget.state.domain_dict_json), domain_list = [],
domain_list = [], domain_id,
domain_id, domain;
domain;
for (i = 0; i < column_list_json.length; i += 1) {
for (i = 0; i < column_list_json.length; i += 1) { if (column_list_json[i][0] === gadget.state.graphic_type) {
if (column_list_json[i][0] === modification_dict.graphic_type) { group_by = column_list_json[i][0];
group_by = column_list_json[i][0]; group_by_title = column_list_json[i][1];
group_by_title = column_list_json[i][1]; return graphic_gadget.render({
return graphic_gadget.render({ group_by: group_by,
group_by: group_by, query_by: {},
query_by: {}, title: group_by_title,
title: group_by_title, list_method_template: gadget.state.list_method_template,
list_method_template: gadget.state.list_method_template, list_method: gadget.state.list_method,
list_method: gadget.state.list_method, layout: {
layout: { x: {
x: { "title": group_by_title,
"title": group_by_title, "key": group_by
"key": group_by },
}, y: {
y: { "title": "Quantity"
"title": "Quantity" }
} }
} });
}); }
} }
} for (domain_id in domain_dict) {
if (domain_dict.hasOwnProperty(domain_id)) {
for (domain_id in domain_dict) { domain = {
if (domain_dict.hasOwnProperty(domain_id)) { "domain_id": domain_id,
domain = { "domain_list": [],
"domain_id": domain_id, "column_list": []
"domain_list": [], };
"column_list": [] for (i = 0; i < domain_dict[domain_id].length; i += 1) {
}; domain.column_list.push(domain_dict[domain_id][i][0]);
for (i = 0; i < domain_dict[domain_id].length; i += 1) { domain.domain_list.push(domain_dict[domain_id][i][1]);
domain.column_list.push(domain_dict[domain_id][i][0]); }
domain.domain_list.push(domain_dict[domain_id][i][1]); domain_list.push(domain);
} }
domain_list.push(domain);
} }
} for (i = 0; i < column_list_json.length; i += 1) {
for (i = 0; i < column_list_json.length; i += 1) { if (column_list_json[i][0].indexOf("_state") !== -1) {
if (column_list_json[i][0].indexOf("_state") !== -1) { group_by = column_list_json[i][0];
group_by = column_list_json[i][0]; group_by_title = column_list_json[i][1];
group_by_title = column_list_json[i][1]; }
} }
} for (i = 0; i < domain_list.length; i += 1) {
for (i = 0; i < domain_list.length; i += 1) { if (domain_list[i].domain_id === gadget.state.graphic_type) {
if (domain_list[i].domain_id === modification_dict.graphic_type) { return graphic_gadget.render({
return graphic_gadget.render({ group_by: group_by,
group_by: group_by, query_by: {},
query_by: {}, title: gadget.state.title,
title: gadget.state.title, list_method_template: gadget.state.list_method_template,
list_method_template: gadget.state.list_method_template, list_method: gadget.state.list_method,
list_method: gadget.state.list_method, layout: {
layout: { x: {
x: { "title": group_by_title,
"title": group_by_title, "key": group_by,
"key": group_by, "domain_id": domain_list[i].domain_id,
"domain_id": domain_list[i].domain_id, "domain_list": domain_list[i].domain_list,
"domain_list": domain_list[i].domain_list, "column_list": domain_list[i].column_list
"column_list": domain_list[i].column_list },
}, y: {
y: { "title": "Quantity"
"title": "Quantity" }
} }
} });
}); }
} }
} });
}); }
} }
return result_queue; return result_queue;
}) })
...@@ -1458,6 +1465,21 @@ ...@@ -1458,6 +1465,21 @@
return result; return result;
}); });
}, {mutex: 'changestate'}) }, {mutex: 'changestate'})
.onEvent('change', function change(evt) {
var gadget = this,
graphic_select = gadget.element.querySelector(
'select[name="GraphicSelect"]'
);
if (evt.target == graphic_select) {
return gadget.redirect({
command: 'change',
options: {
graphic_type: evt.target.value
}
});
}
})
.onEvent('click', function click(evt) { .onEvent('click', function click(evt) {
// For some reason, Zelenium can click even if button has the disabled // For some reason, Zelenium can click even if button has the disabled
// attribute. So, it is needed for now to manually checks // attribute. So, it is needed for now to manually checks
...@@ -1521,13 +1543,6 @@ ...@@ -1521,13 +1543,6 @@
}); });
} }
if (evt.target.type === "select-one") {
// XXX Move it to onEvent > "change" probably
return gadget.changeState({
"graphic_type": evt.target.value
});
}
if ((evt.target.type === 'button') && if ((evt.target.type === 'button') &&
((evt.target.name === 'SelectAction') || (evt.target.name === 'ClipboardAction'))) { ((evt.target.name === 'SelectAction') || (evt.target.name === 'ClipboardAction'))) {
evt.preventDefault(); evt.preventDefault();
......
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>994.25329.16170.62481</string> </value> <value> <string>997.9256.52516.32426</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -258,7 +258,7 @@ ...@@ -258,7 +258,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1630077204.4</float> <float>1640736604.19</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -179,8 +179,13 @@ ...@@ -179,8 +179,13 @@
"select_list": select_list "select_list": select_list
}; };
} }
return gadget.getUrlParameter('extended_search') return new RSVP.Queue(RSVP.all([
.push(function (extended_search) { gadget.getUrlParameter('extended_search'),
gadget.getUrlParameter('graphic_select_id')
]))
.push(function (result_list) {
var extended_search = result_list[0],
graphic_select_id = result_list[1];
if (extended_search) { if (extended_search) {
jio_query_list.push(Query.parseStringToObject(extended_search)); jio_query_list.push(Query.parseStringToObject(extended_search));
} }
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>997.7486.55612.53862</string> </value> <value> <string>997.9171.49361.29986</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -264,7 +264,7 @@ ...@@ -264,7 +264,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1640630356.79</float> <float>1640731509.5</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