Commit 41b64275 authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_web_renderjs_ui: refactoring code to display graphic

parent 7567a1b0
...@@ -300,6 +300,15 @@ ...@@ -300,6 +300,15 @@
begin_from: 0 begin_from: 0
}; };
}, {mutex: 'changestate'}) }, {mutex: 'changestate'})
.declareMethod("getGraphicType", function () {
var gadget = this;
if (gadget.props.listbox_gadget) {
return gadget.props.listbox_gadget.getGraphicType();
}
return;
}, {mutex: 'changestate'})
.declareMethod("getContent", function (options) { .declareMethod("getContent", function (options) {
var form_gadget = this, var form_gadget = this,
k, k,
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>997.31802.64350.38400</string> </value> <value> <string>997.49201.45822.48315</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1642089373.2</float> <float>1643133280.23</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -337,6 +337,14 @@ ...@@ -337,6 +337,14 @@
}); });
}, {mutex: 'changestate'}) }, {mutex: 'changestate'})
.declareMethod('getGraphicType', function getGraphicType() {
var argument_list = arguments;
return this.getDeclaredGadget(SCOPE)
.push(function (gadget) {
return gadget.getGraphicType.apply(gadget, argument_list);
});
}, {mutex: 'changestate'})
.allowPublicAcquisition("notifyFocus", function notifyFocus() { .allowPublicAcquisition("notifyFocus", function notifyFocus() {
return this.changeState({display_error_text: true}); return this.changeState({display_error_text: true});
}) })
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>991.31753.10689.19694</string> </value> <value> <string>997.7172.17438.7031</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1618839010.44</float> <float>1643134111.55</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -1202,10 +1202,8 @@ ...@@ -1202,10 +1202,8 @@
loading_element.textContent = '(' + pagination_message + ')'; loading_element.textContent = '(' + pagination_message + ')';
} }
if (gadget.state.option_list.length > 0 && if (gadget.state.option_list.length > 0 &&
gadget.state.enable_graphic &&
!gadget.state.extended_search) {
if (!gadget.state.extended_search &&
gadget.state.enable_graphic) { gadget.state.enable_graphic) {
if (gadget.state.enable_graphic) {
domsugar(gadget.element.querySelector(".graphic_section"), [ domsugar(gadget.element.querySelector(".graphic_section"), [
domsugar("div", {"class": "graphic_area"}) domsugar("div", {"class": "graphic_area"})
]); ]);
...@@ -1213,8 +1211,7 @@ ...@@ -1213,8 +1211,7 @@
} }
}); });
}); });
if (!gadget.state.extended_search && if (gadget.state.enable_graphic &&
gadget.state.enable_graphic &&
gadget.state.graphic_type && gadget.state.graphic_type &&
gadget.state.option_list.length > 0 && gadget.state.option_list.length > 0 &&
gadget.state.graphic_type !== "") { gadget.state.graphic_type !== "") {
...@@ -1305,6 +1302,9 @@ ...@@ -1305,6 +1302,9 @@
} }
return result_queue; return result_queue;
}) })
.declareMethod('getGraphicType', function getGraphicType() {
return this.state.graphic_type;
})
.declareMethod('getListboxInfo', function getListboxInfo() { .declareMethod('getListboxInfo', function getListboxInfo() {
var domain_list = JSON.parse(this.state.domain_list_json), var domain_list = JSON.parse(this.state.domain_list_json),
......
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>997.48220.58774.24832</string> </value> <value> <string>997.49449.8762.59733</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>1643074611.1</float> <float>1643148086.35</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -9,6 +9,23 @@ ...@@ -9,6 +9,23 @@
declareGadgetClassCanHandleListboxClipboardAction, RSVP) { declareGadgetClassCanHandleListboxClipboardAction, RSVP) {
"use strict"; "use strict";
function getDefaultGraphicType(option_list) {
var i,
default_option_list = [
"translated_simulation_state_title",
"translated_validation_state_title"
];
if (!option_list.length) {
return;
}
for (i = 0; i < option_list.length; i += 1) {
if (default_option_list.indexOf(option_list[i][0]) !== -1) {
return option_list[i][0];
}
}
return option_list[0][0];
}
function updateSearchQueryFromSelection(extended_search, checked_uid_list, function updateSearchQueryFromSelection(extended_search, checked_uid_list,
key, to_include) { key, to_include) {
var i, var i,
...@@ -114,12 +131,19 @@ ...@@ -114,12 +131,19 @@
}) })
.onStateChange(function onStateChange() { .onStateChange(function onStateChange() {
var form_gadget = this; var erp5_form,
graphic_type,
form_gadget = this;
// render the erp5 form // render the erp5 form
return form_gadget.getDeclaredGadget("erp5_form") return new RSVP.Queue(RSVP.all([
.push(function (erp5_form) { form_gadget.getDeclaredGadget("erp5_form"),
form_gadget.getUrlParameter("graphic_type")
]))
.push(function (result_list) {
var form_options = form_gadget.state.erp5_form; var form_options = form_gadget.state.erp5_form;
graphic_type = result_list[1];
erp5_form = result_list[0];
form_options.erp5_document = form_gadget.state.erp5_document; form_options.erp5_document = form_gadget.state.erp5_document;
form_options.form_definition = form_gadget.state.form_definition; form_options.form_definition = form_gadget.state.form_definition;
...@@ -135,21 +159,37 @@ ...@@ -135,21 +159,37 @@
if (form_gadget.state.extended_search) { if (form_gadget.state.extended_search) {
form_options.form_definition.extended_search = form_gadget.state.extended_search; form_options.form_definition.extended_search = form_gadget.state.extended_search;
} }
form_options.enable_graphic = false;
if (graphic_type || (
!form_gadget.state.extended_search && !graphic_type)) {
form_options.enable_graphic = true; form_options.enable_graphic = true;
}
return erp5_form.render(form_options); return erp5_form.render(form_options);
}) })
// render the search field // render the search field
.push(function () { .push(function (result) {
return form_gadget.getDeclaredGadget("erp5_searchfield"); return RSVP.all([
form_gadget.getDeclaredGadget("erp5_searchfield"),
erp5_form.getGraphicType()
])
}) })
.push(function (search_gadget) { .push(function (result_list) {
var search_options = {}; var search_gadget = result_list[0],
search_options = {};
// XXX not generic, fix later // XXX not generic, fix later
if (form_gadget.state.extended_search) { if (form_gadget.state.extended_search) {
search_options.extended_search = form_gadget.state.extended_search; search_options.extended_search = form_gadget.state.extended_search;
} }
search_options.enable_graphic = false;
if (graphic_type || (
!form_gadget.state.extended_search && !graphic_type)) {
search_options.enable_graphic = true; search_options.enable_graphic = true;
}
search_options.graphic_type = result_list[1];
return search_gadget.render(search_options); return search_gadget.render(search_options);
}) })
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>997.48212.37929.9830</string> </value> <value> <string>997.49226.31411.58880</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1643074253.32</float> <float>1643150091.84</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -32,7 +32,8 @@ ...@@ -32,7 +32,8 @@
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var state_dict = { var state_dict = {
extended_search: options.extended_search || "", extended_search: options.extended_search || "",
enable_graphic: options.enable_graphic || false enable_graphic: options.enable_graphic || false,
graphic_type: options.graphic_type
}; };
return this.changeState(state_dict); return this.changeState(state_dict);
}) })
...@@ -58,10 +59,15 @@ ...@@ -58,10 +59,15 @@
continue_full_text_query_search = true; continue_full_text_query_search = true;
if (gadget.state.extended_search) { if (gadget.state.extended_search) {
console.log(modification_dict);
if (modification_dict.enable_graphic && if (modification_dict.enable_graphic &&
button_graphic && button_graphic.classList.contains( modification_dict.graphic_type &&
graphic_css_class)) { button_graphic) {
button_graphic.classList.add(graphic_css_class);
select_button_graphic.classList.remove(graphic_css_class);
} else {
button_graphic.classList.remove(graphic_css_class); button_graphic.classList.remove(graphic_css_class);
select_button_graphic.classList.add(graphic_css_class);
} }
// Parse the raw query // Parse the raw query
...@@ -124,9 +130,13 @@ ...@@ -124,9 +130,13 @@
button_graphic && !button_graphic.classList.contains( button_graphic && !button_graphic.classList.contains(
graphic_css_class)) { graphic_css_class)) {
button_graphic.classList.add(graphic_css_class); button_graphic.classList.add(graphic_css_class);
} else if (modification_dict.enable_graphic && select_button_graphic) { select_button_graphic.classList.remove(graphic_css_class);
} else if (select_button_graphic &&
modification_dict.enable_graphic &&
!modification_dict.extended_search ){
select_button_graphic.classList.remove(graphic_css_class); select_button_graphic.classList.remove(graphic_css_class);
} }
console.log(modification_dict);
button_container.innerHTML = ''; button_container.innerHTML = '';
len = query_text_list.length; len = query_text_list.length;
for (i = 0; i < len; i += 1) { for (i = 0; i < len; i += 1) {
...@@ -250,8 +260,14 @@ ...@@ -250,8 +260,14 @@
// Open the filter panel if one 'search' button is clicked // Open the filter panel if one 'search' button is clicked
evt.preventDefault(); evt.preventDefault();
return this.triggerSubmit({focus_on: parseInt(evt.target.value, 10)}); return this.triggerSubmit({focus_on: parseInt(evt.target.value, 10)});
} else if (evt.target.classList.contains("graphic-button") || } else if (evt.target.classList.contains("graphic-button")) {
evt.target.classList.contains("change-graphic-button")) { return gadget.redirect({
command: "store_and_change",
options: {
graphic_type: gadget.state.graphic_type
}
});
} else if (evt.target.classList.contains("change-graphic-button")) {
return gadget.triggerListboxGraphicSelection(); return gadget.triggerListboxGraphicSelection();
} }
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>997.48219.25108.64102</string> </value> <value> <string>997.49459.47071.9267</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1643074808.7</float> <float>1643150086.6</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -151,6 +151,11 @@ ...@@ -151,6 +151,11 @@
}) })
); );
return gadget.getUrlParameter('extended_search')
.push(function (extended_search) {
if (extended_search) {
jio_query_list.push(Query.parseStringToObject(extended_search));
}
if (domain_id) { if (domain_id) {
domain_list = options.layout.x.domain_list || []; domain_list = options.layout.x.domain_list || [];
for (i = 0; i < domain_list.length; i += 1) { for (i = 0; i < domain_list.length; i += 1) {
...@@ -181,41 +186,35 @@ ...@@ -181,41 +186,35 @@
data.query_list = query_list; data.query_list = query_list;
} else if (group_by instanceof Array && group_by.length > 1) { } else if (group_by instanceof Array && group_by.length > 1) {
data.query = { data.query = {
"query": Query.objectToSearchText(new ComplexQuery({ query: Query.objectToSearchText(new ComplexQuery({
operator: "AND", operator: "AND",
query_list: jio_query_list, query_list: jio_query_list,
type: "complex" type : "complex"
})), })),
"list_method_template": options.list_method_template, list_method_template: options.list_method_template,
"list_method": options.list_method, list_method: options.list_method,
"relative_url": options.relative_url, relative_url: options.relative_url,
"group_by": group_by, group_by: group_by,
"select_list": select_list.concat(group_by) select_list: select_list.concat(group_by)
}; };
} else { } else {
data.extended_search_mapping[options.title] = { data.extended_search_mapping[options.title] = {
"key": group_by, key: group_by,
"value": options.group_by value: options.group_by
}; };
data.query = { data.query = {
"query": Query.objectToSearchText(new ComplexQuery({ query: Query.objectToSearchText(new ComplexQuery({
operator: "AND", operator: "AND",
query_list: jio_query_list, query_list: jio_query_list,
type: "complex" type: "complex"
})), })),
"list_method_template": options.list_method_template, list_method_template: options.list_method_template,
"list_method": options.list_method, list_method: options.list_method,
"relative_url": options.relative_url, relative_url: options.relative_url,
"group_by": group_by, group_by: group_by,
"select_list": select_list select_list: select_list
}; };
} }
return gadget.getUrlParameter('extended_search')
.push(function (extended_search) {
if (extended_search) {
jio_query_list.push(Query.parseStringToObject(extended_search));
}
return gadget.changeState(data); return gadget.changeState(data);
}); });
}) })
......
...@@ -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.31802.54309.25309</string> </value> <value> <string>997.48057.37984.27733</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>1642089304.69</float> <float>1643148004.23</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