Commit af2c1676 authored by Romain Courteaud's avatar Romain Courteaud

XXX [erp5_web_renderjs_ui] Listbox: new buttons, more fun

Remove delete from the action page

Move delete button on the listbox itself

Check selected lines when deleting

Do not touch the query if no line is selected
parent 20fb75d6
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
data-i18n=No records data-i18n=No records
data-i18n=Records data-i18n=Records
data-i18n=Select data-i18n=Select
data-i18n=Clipboard
data-i18n=Configure data-i18n=Configure
data-i18n=Sort data-i18n=Sort
data-i18n=sample of data-i18n=sample of
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>971.37684.40708.23176</string> </value> <value> <string>972.44335.31558.29354</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>1545124793.17</float> <float>1546420711.37</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -278,7 +278,9 @@ ...@@ -278,7 +278,9 @@
"row_list": row_list, "row_list": row_list,
"show_anchor": gadget.state.show_anchor, "show_anchor": gadget.state.show_anchor,
"column_list": column_list, "column_list": column_list,
"show_line_selector": gadget.state.show_line_selector "show_line_selector": gadget.state.show_line_selector,
"show_select_action": gadget.state.show_select_action,
"show_clipboard_action": gadget.state.show_clipboard_action
}); });
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
...@@ -331,8 +333,12 @@ ...@@ -331,8 +333,12 @@
.declareAcquiredMethod("getTranslationList", "getTranslationList") .declareAcquiredMethod("getTranslationList", "getTranslationList")
.declareAcquiredMethod("getListboxSelectActionList", .declareAcquiredMethod("getListboxSelectActionList",
"getListboxSelectActionList") "getListboxSelectActionList")
.declareAcquiredMethod("getListboxClipboardActionList",
"getListboxClipboardActionList")
.declareAcquiredMethod("triggerListboxSelectAction", .declareAcquiredMethod("triggerListboxSelectAction",
"triggerListboxSelectAction") "triggerListboxSelectAction")
.declareAcquiredMethod("triggerListboxClipboardAction",
"triggerListboxClipboardAction")
////////////////////////////////////////////// //////////////////////////////////////////////
// initialize the gadget content // initialize the gadget content
...@@ -481,7 +487,9 @@ ...@@ -481,7 +487,9 @@
// No error message // No error message
has_error: false, has_error: false,
show_line_selector: false show_line_selector: false,
show_select_action: false,
show_clipboard_action: false
}); });
}); });
return queue; return queue;
...@@ -497,6 +505,7 @@ ...@@ -497,6 +505,7 @@
j, j,
result_queue = new RSVP.Queue(), result_queue = new RSVP.Queue(),
button_selector_list = ['button[name="Sort"]', 'button[name="Hide"]', button_selector_list = ['button[name="Sort"]', 'button[name="Hide"]',
'button[name="Clipboard"]',
'button[name="Configure"]', 'button[name="Configure"]',
'button[name="SelectRows"]'], 'button[name="SelectRows"]'],
button; button;
...@@ -614,7 +623,7 @@ ...@@ -614,7 +623,7 @@
} }
} }
if (gadget.state.show_line_selector) { if (gadget.state.show_select_action) {
select_list = gadget.getListboxSelectActionList() select_list = gadget.getListboxSelectActionList()
.push(undefined, function (error) { .push(undefined, function (error) {
if (error instanceof rJS.AcquisitionError) { if (error instanceof rJS.AcquisitionError) {
...@@ -627,12 +636,25 @@ ...@@ -627,12 +636,25 @@
}); });
} }
if (gadget.state.show_clipboard_action) {
select_list = gadget.getListboxClipboardActionList()
.push(undefined, function (error) {
if (error instanceof rJS.AcquisitionError) {
// Do not break if parent gadget does not implement it
// XXX this could be a new rJS function when doing
// declareAcquiredMethod
return [];
}
throw error;
});
}
return RSVP.all([ return RSVP.all([
gadget.getUrlForList(url_for_option_list), gadget.getUrlForList(url_for_option_list),
is_sortable_list, is_sortable_list,
gadget.getTranslationList(['Jump', gadget.getTranslationList(['Jump',
'Select', 'Configure', 'Sort', 'Select', 'Configure', 'Sort',
'Cancel']), 'Cancel', 'Clipboard']),
select_list select_list
]); ]);
}) })
...@@ -665,7 +687,7 @@ ...@@ -665,7 +687,7 @@
h1_element.appendChild(span_element); h1_element.appendChild(span_element);
div_element.appendChild(h1_element); div_element.appendChild(h1_element);
if (gadget.state.show_line_selector) { if (gadget.state.show_select_action) {
for (k = 0; k < select_option_list.length; k += 1) { for (k = 0; k < select_option_list.length; k += 1) {
// Add include button // Add include button
// <button data-rel="hide" data-i18n="Include" name="IncludeRows" type="button" class="ui-icon-eye ui-btn-icon-left {{hide_class}}"></button> // <button data-rel="hide" data-i18n="Include" name="IncludeRows" type="button" class="ui-icon-eye ui-btn-icon-left {{hide_class}}"></button>
...@@ -689,6 +711,30 @@ ...@@ -689,6 +711,30 @@
button_element.textContent = translation_list[4]; button_element.textContent = translation_list[4];
div_element.appendChild(button_element); div_element.appendChild(button_element);
} else if (gadget.state.show_clipboard_action) {
for (k = 0; k < select_option_list.length; k += 1) {
// Add include button
// <button data-rel="hide" data-i18n="Include" name="IncludeRows" type="button" class="ui-icon-eye ui-btn-icon-left {{hide_class}}"></button>
button_element = document.createElement('button');
button_element.setAttribute('data-rel', 'clipboard');
button_element.setAttribute('data-clipboard-action', select_option_list[k].action);
button_element.setAttribute('name', 'ClipboardAction');
button_element.type = 'button';
button_element.setAttribute('class', 'ui-icon-' + select_option_list[k].icon + ' ui-btn-icon-left ' + gadget.state.hide_class);
button_element.textContent = select_option_list[k].title;
div_element.appendChild(button_element);
}
// Add cancel button
// <button data-rel="cancel" data-i18n="Cancel" name="ExcludeRows" type="button" class="ui-icon-times ui-btn-icon-left {{hide_class}}"></button>
button_element = document.createElement('button');
button_element.setAttribute('data-rel', 'hide');
button_element.setAttribute('name', 'CancelSelect');
button_element.type = 'button';
button_element.setAttribute('class', 'ui-icon-times ui-btn-icon-left ' + gadget.state.hide_class);
button_element.textContent = translation_list[4];
div_element.appendChild(button_element);
} else { } else {
// Add Configure button // Add Configure button
...@@ -713,6 +759,17 @@ ...@@ -713,6 +759,17 @@
button_element.textContent = translation_list[3]; button_element.textContent = translation_list[3];
div_element.appendChild(button_element); div_element.appendChild(button_element);
// Add Do button
// <button {{disabled}} data-rel="hide" data-i18n="Select" name="Hide" type="button" class="ui-icon-check-square-o ui-btn-icon-left {{hide_class}}"></button>
button_element = document.createElement('button');
button_element.disabled = gadget.state.disabled;
button_element.setAttribute('data-rel', 'clipboard');
button_element.setAttribute('name', 'Clipboard');
button_element.type = 'button';
button_element.setAttribute('class', 'ui-icon-ellipsis-v ui-btn-icon-left ' + gadget.state.hide_class);
button_element.textContent = translation_list[5];
div_element.appendChild(button_element);
// Add Select button // Add Select button
// <button {{disabled}} data-rel="hide" data-i18n="Select" name="Hide" type="button" class="ui-icon-check-square-o ui-btn-icon-left {{hide_class}}"></button> // <button {{disabled}} data-rel="hide" data-i18n="Select" name="Hide" type="button" class="ui-icon-check-square-o ui-btn-icon-left {{hide_class}}"></button>
button_element = document.createElement('button'); button_element = document.createElement('button');
...@@ -1217,6 +1274,7 @@ ...@@ -1217,6 +1274,7 @@
var gadget = this, var gadget = this,
sort_button = gadget.element.querySelector('button[name="Sort"]'), sort_button = gadget.element.querySelector('button[name="Sort"]'),
hide_button = gadget.element.querySelector('button[name="Hide"]'), hide_button = gadget.element.querySelector('button[name="Hide"]'),
clipboard_button = gadget.element.querySelector('button[name="Clipboard"]'),
configure_button = gadget.element.querySelector('button[name="Configure"]'), configure_button = gadget.element.querySelector('button[name="Configure"]'),
cancel_select_button = gadget.element.querySelector('button[name="CancelSelect"]'), cancel_select_button = gadget.element.querySelector('button[name="CancelSelect"]'),
url, url,
...@@ -1247,19 +1305,30 @@ ...@@ -1247,19 +1305,30 @@
if (evt.target === hide_button) { if (evt.target === hide_button) {
evt.preventDefault(); evt.preventDefault();
return gadget.changeState({ return gadget.changeState({
show_line_selector: true show_line_selector: true,
show_select_action: true
});
}
if (evt.target === clipboard_button) {
evt.preventDefault();
return gadget.changeState({
show_line_selector: true,
show_clipboard_action: true
}); });
} }
if (evt.target === cancel_select_button) { if (evt.target === cancel_select_button) {
evt.preventDefault(); evt.preventDefault();
return gadget.changeState({ return gadget.changeState({
show_line_selector: false show_line_selector: false,
show_select_action: false,
show_clipboard_action: false
}); });
} }
if ((evt.target.type === 'button') && if ((evt.target.type === 'button') &&
(evt.target.name === 'SelectAction')) { ((evt.target.name === 'SelectAction') || (evt.target.name === 'ClipboardAction'))) {
evt.preventDefault(); evt.preventDefault();
checked_uid_list = []; checked_uid_list = [];
...@@ -1275,7 +1344,10 @@ ...@@ -1275,7 +1344,10 @@
unchecked_uid_list.push(all_hide_element_list[i].getAttribute("data-uid")); unchecked_uid_list.push(all_hide_element_list[i].getAttribute("data-uid"));
} }
} }
return gadget.triggerListboxSelectAction(evt.target.getAttribute('data-select-action'), checked_uid_list, unchecked_uid_list); if (evt.target.name === 'SelectAction') {
return gadget.triggerListboxSelectAction(evt.target.getAttribute('data-select-action'), checked_uid_list, unchecked_uid_list);
}
return gadget.triggerListboxClipboardAction(evt.target.getAttribute('data-clipboard-action'), checked_uid_list, unchecked_uid_list);
} }
}, false, false) }, false, false)
......
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>972.27092.48077.63488</string> </value> <value> <string>972.46980.44591.46967</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -254,7 +254,7 @@ ...@@ -254,7 +254,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1545386943.7</float> <float>1546508438.91</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -79,16 +79,14 @@ ...@@ -79,16 +79,14 @@
action_list = ensureArray(jio_attachment._links.action_object_jio_action) action_list = ensureArray(jio_attachment._links.action_object_jio_action)
.concat(ensureArray(jio_attachment._links.action_object_jio_button)) .concat(ensureArray(jio_attachment._links.action_object_jio_button))
.concat(ensureArray(jio_attachment._links.action_object_jio_fast_input)), .concat(ensureArray(jio_attachment._links.action_object_jio_fast_input)),
clone_list = ensureArray(jio_attachment._links.action_object_clone_action), clone_list = ensureArray(jio_attachment._links.action_object_clone_action);
delete_list = ensureArray(jio_attachment._links.action_object_delete_action);
erp5_document = jio_attachment; erp5_document = jio_attachment;
return RSVP.all([ return RSVP.all([
renderLinkList(gadget, "Workflows", "random", transition_list), renderLinkList(gadget, "Workflows", "random", transition_list),
renderLinkList(gadget, "Actions", "gear", action_list), renderLinkList(gadget, "Actions", "gear", action_list),
renderLinkList(gadget, "Clone", "clone", clone_list), renderLinkList(gadget, "Clone", "clone", clone_list)
renderLinkList(gadget, "Delete", "trash-o", delete_list)
]); ]);
}) })
.push(function (translated_html_link_list) { .push(function (translated_html_link_list) {
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>970.5224.10569.36898</string> </value> <value> <string>972.47025.43931.43690</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>1536227065.3</float> <float>1546427153.93</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<!-- <!--
data-i18n=Include data-i18n=Include
data-i18n=Exclude data-i18n=Exclude
data-i18n=Delete
--> -->
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>972.25327.46098.50073</string> </value> <value> <string>972.29743.559.65006</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>1545389700.46</float> <float>1546423008.44</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, RSVP, calculatePageTitle, SimpleQuery, ComplexQuery, /*global window, rJS, RSVP, calculatePageTitle, SimpleQuery, ComplexQuery,
Query, QueryFactory */ Query, QueryFactory, ensureArray */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, calculatePageTitle, SimpleQuery, ComplexQuery, (function (window, rJS, RSVP, calculatePageTitle, SimpleQuery, ComplexQuery,
Query, QueryFactory) { Query, QueryFactory, ensureArray) {
"use strict"; "use strict";
function updateSearchQueryFromSelection(extended_search, checked_uid_list,
key, to_include) {
var i,
search_query,
query_list = [];
for (i = 0; i < checked_uid_list.length; i += 1) {
query_list.push(new SimpleQuery({
key: key,
type: "simple",
operator: to_include ? "=" : "!=",
value: checked_uid_list[i]
}));
}
if (extended_search) {
search_query = QueryFactory.create(extended_search);
}
if (to_include) {
// Lines must match the existing query and be one of the selected
// line. Which means that is user change the query, one of the
// selected line could disappear.
if (search_query) {
search_query = new ComplexQuery({
operator: "AND",
query_list: [
new ComplexQuery({
operator: "OR",
query_list: query_list,
type: "complex"
}),
search_query
],
type: "complex"
});
} else {
search_query = new ComplexQuery({
operator: "OR",
query_list: query_list,
type: "complex"
});
}
} else {
// Lines must match the existing query and must not be one of the
// selected line.
if (search_query) {
query_list.push(search_query);
}
search_query = new ComplexQuery({
operator: "AND",
query_list: query_list,
type: "complex"
});
}
return Query.objectToSearchText(search_query);
}
rJS(window) rJS(window)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Acquired methods // Acquired methods
...@@ -207,10 +264,7 @@ ...@@ -207,10 +264,7 @@
var action = argument_list[0], var action = argument_list[0],
checked_uid_list = argument_list[1], checked_uid_list = argument_list[1],
unchecked_uid_list = argument_list[2], unchecked_uid_list = argument_list[2],
gadget = this, gadget = this;
i,
search_query,
query_list = [];
if ((action === 'include') || (action === 'exclude')) { if ((action === 'include') || (action === 'exclude')) {
if (checked_uid_list.length === 0) { if (checked_uid_list.length === 0) {
// If nothing is checked, use all unchecked values (same as xhtml style) // If nothing is checked, use all unchecked values (same as xhtml style)
...@@ -223,65 +277,61 @@ ...@@ -223,65 +277,61 @@
}); });
} }
for (i = 0; i < checked_uid_list.length; i += 1) {
query_list.push(new SimpleQuery({
key: "catalog.uid",
type: "simple",
operator: (action === 'include') ? "=" : "!=",
value: checked_uid_list[i]
}));
}
if (gadget.state.extended_search) {
search_query = QueryFactory.create(gadget.state.extended_search);
}
if (action === 'include') {
// Lines must match the existing query and be one of the selected
// line. Which means that is user change the query, one of the
// selected line could disappear.
if (search_query) {
search_query = new ComplexQuery({
operator: "AND",
query_list: [
new ComplexQuery({
operator: "OR",
query_list: query_list,
type: "complex"
}),
search_query
],
type: "complex"
});
} else {
search_query = new ComplexQuery({
operator: "OR",
query_list: query_list,
type: "complex"
});
}
} else {
// Lines must match the existing query and must not be one of the
// selected line.
if (search_query) {
query_list.push(search_query);
}
search_query = new ComplexQuery({
operator: "AND",
query_list: query_list,
type: "complex"
});
}
return gadget.redirect({ return gadget.redirect({
command: 'store_and_change', command: 'store_and_change',
options: { options: {
"extended_search": Query.objectToSearchText(search_query) "extended_search": updateSearchQueryFromSelection(
gadget.state.extended_search,
checked_uid_list,
'catalog.uid',
(action === 'include')
)
} }
}); });
} }
throw new Error('Unsupported triggerListboxSelectAction action: ' + action); throw new Error('Unsupported triggerListboxSelectAction action: ' + action);
})
// Handle listbox custom button
.allowPublicAcquisition("getListboxClipboardActionList", function getListboxClipboardActionList() {
var delete_list = ensureArray(this.state.erp5_document._links.action_object_delete_action);
if (!delete_list.length) {
return [];
}
return this.getTranslationList(['Delete'])
.push(function (result_list) {
return [{
title: result_list[0],
icon: 'trash-o',
action: 'delete'
}];
});
})
.allowPublicAcquisition("triggerListboxClipboardAction", function triggerListboxClipboardAction(argument_list) {
var delete_list = ensureArray(this.state.erp5_document._links.action_object_delete_action),
checked_uid_list = argument_list[1],
gadget = this,
extended_search = gadget.state.extended_search;
if (checked_uid_list.length !== 0) {
// If nothing is checked, use original query
extended_search = updateSearchQueryFromSelection(
extended_search,
checked_uid_list,
'catalog.uid',
true
);
}
return this.redirect({
command: 'change',
options: {
"view": delete_list[0].href,
"page": undefined,
"extended_search": extended_search
}
});
}); });
}(window, rJS, RSVP, calculatePageTitle, SimpleQuery, ComplexQuery, Query, }(window, rJS, RSVP, calculatePageTitle, SimpleQuery, ComplexQuery, Query,
QueryFactory)); QueryFactory, ensureArray));
\ 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>972.27145.17258.43178</string> </value> <value> <string>972.48364.17669.16281</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>1545233919.1</float> <float>1546507906.6</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