Commit ebe4a9b1 authored by Romain Courteaud's avatar Romain Courteaud 🐙

[erp5_web_renderjs_ui] Factorise code

Only use what is visible / checked
parent 67b6d207
...@@ -99,76 +99,64 @@ ...@@ -99,76 +99,64 @@
} }
function triggerListboxClipboardAction(argument_list) { function triggerListboxClipboardAction(argument_list) {
var action_list = ensureArray(this.state.erp5_document._links.action_object_list_action || []), var gadget = this,
action_list = ensureArray(gadget.state.erp5_document._links.action_object_list_action || []),
action_name = argument_list[0], action_name = 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,
extended_search = '',
view, view,
i; i,
queue;
if (action_name === 'copy_document_list') {
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)
checked_uid_list = unchecked_uid_list; checked_uid_list = unchecked_uid_list;
} }
if (checked_uid_list.length === 0) {
// XXX Queries do not correctly handle empty uid list
return gadget.redirect({
command: 'reload'
});
}
return gadget.setSetting('clipboard', checked_uid_list)
.push(function () {
return gadget.notifySubmitted({
"message": "Copied.",
"status": "success"
});
});
}
if (action_name !== 'copy_document_list') {
// Copy action is only done on javascript side
for (i = 0; i < action_list.length; i += 1) { for (i = 0; i < action_list.length; i += 1) {
if (action_name === action_list[i].name) { if (action_name === action_list[i].name) {
view = action_list[i].href; view = action_list[i].href;
} }
} }
if (checked_uid_list.length !== 0) {
// If nothing is checked, use original query
extended_search = createSearchQuery(
checked_uid_list,
'catalog.uid'
);
}
if (view === undefined) { if (view === undefined) {
// Action was not found. // Action was not found.
// Reload return gadget.notifySubmitted({
return gadget.redirect({ "message": "Action not handled."
command: 'reload'
}); });
} }
}
if (action_name === 'paste_document_list') { if (action_name === 'paste_document_list') {
return gadget.getSetting('clipboard') // Get the list of document uid from the internal clipboard
queue = gadget.getSetting('clipboard')
.push(function (uid_list) { .push(function (uid_list) {
uid_list = uid_list || []; checked_uid_list = uid_list || [];
if (uid_list.length === 0) { });
// Nothing to paste, go away } else {
uid_list = ['XXX']; queue = new RSVP.Queue();
} }
return gadget.redirect({
command: 'display_dialog_with_history', return queue
options: { .push(function () {
"jio_key": gadget.state.jio_key, if (checked_uid_list.length === 0) {
"view": view, // Do not trigger action if the listbox was empty
"extended_search": createSearchQuery( // Dialog listbox use catalog method, which may be different from the current select method
uid_list, // and so, it is mandatory to propagate a list of uid, otherwise, the dialog may display
'catalog.uid' // an unexpected huge list of unrelated documents
) return gadget.notifySubmitted({
"message": "Nothing selected."
});
} }
}, true);
if (action_name === 'copy_document_list') {
return gadget.setSetting('clipboard', checked_uid_list)
.push(function () {
return gadget.notifySubmitted({
"message": "Copied.",
"status": "success"
});
}); });
} }
...@@ -177,9 +165,13 @@ ...@@ -177,9 +165,13 @@
options: { options: {
"jio_key": gadget.state.jio_key, "jio_key": gadget.state.jio_key,
"view": view, "view": view,
"extended_search": extended_search "extended_search": createSearchQuery(
checked_uid_list,
'catalog.uid'
)
} }
}, true); }, true);
});
} }
window.triggerListboxClipboardAction = triggerListboxClipboardAction; window.triggerListboxClipboardAction = triggerListboxClipboardAction;
......
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>974.44319.22564.50107</string> </value> <value> <string>974.48315.28627.55534</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1553869431.11</float> <float>1554109242.58</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