Commit 91e9e59d authored by Romain Courteaud's avatar Romain Courteaud 🐙

WIP [erp5_web_renderjs_ui] Copy/Paste

[erp5_web_renderjs_ui] Copy all visible doc if nothing is selected

copy/paste jslint

webrjsui: copy paste on form_view

[erp5_web_renderjs_ui] Factorise code

Only use what is visible / checked

[erp5_web_renderjs_ui] Use same code than form_view

[erp5_web_renderjs_ui] Factorise code

[erp5_web_renderjs_ui] Factorise more

[erp5_web_renderjs_ui] Drop useless code

[erp5_web_renderjs_ui] Listbox: always activate the Edit button

This allows to copy documents shown by the listbox.

translate copy/paste message

fixup

[erp5_web_renderjs_ui_test] Mass workflow transition only change documents shown on the previous listbox

erp5_global: remove unused variable
parent 2531cf89
/*global window, RSVP */
/*jslint indent: 2, maxerr: 3, nomen: true, unparam: true */
(function (window, RSVP) {
/*global window, RSVP, SimpleQuery, ComplexQuery, Query,
ensureArray */
/*jslint indent: 2, maxerr: 3, nomen: true, unparam: true, continue: true */
(function (window, RSVP, SimpleQuery, ComplexQuery, Query,
ensureArray) {
"use strict";
window.calculatePageTitle = function (gadget, erp5_document) {
......@@ -15,4 +17,158 @@
});
};
}(window, RSVP));
///////////////////////////////
// Handle listbox action list
///////////////////////////////
function getListboxClipboardActionList() {
var action_list = ensureArray(this.state.erp5_document._links.action_object_list_action || []),
i,
result_list = [],
icon;
result_list.push({
title: 'Copy',
icon: 'copy',
action: 'copy_document_list'
});
for (i = 0; i < action_list.length; i += 1) {
if (action_list[i].name === 'delete_document_list') {
icon = 'trash-o';
} else if (action_list[i].name === 'paste_document_list') {
icon = 'paste';
} else {
continue;
}
result_list.push({
title: action_list[i].title,
icon: icon,
action: action_list[i].name
});
}
return result_list;
}
function createSearchQuery(checked_uid_list, key) {
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: "=",
value: checked_uid_list[i]
}));
}
search_query = new ComplexQuery({
operator: "OR",
query_list: query_list,
type: "complex"
});
return Query.objectToSearchText(search_query);
}
function notifyTranslatedMessage(gadget, options) {
return gadget.getTranslationClipboardAction(options.message)
.push(function (translated_message) {
options.message = translated_message;
return gadget.notifySubmittedClipboardAction(options);
});
}
function triggerListboxClipboardAction(argument_list) {
var gadget = this,
action_list = ensureArray(gadget.state.erp5_document._links.action_object_list_action || []),
action_name = argument_list[0],
checked_uid_list = argument_list[1],
unchecked_uid_list = argument_list[2],
view,
i,
queue;
if (checked_uid_list.length === 0) {
// If nothing is checked, use all unchecked values (same as xhtml style)
checked_uid_list = unchecked_uid_list;
}
if (action_name !== 'copy_document_list') {
// Copy action is only done on javascript side
for (i = 0; i < action_list.length; i += 1) {
if (action_name === action_list[i].name) {
view = action_list[i].href;
}
}
if (view === undefined) {
// Action was not found.
return notifyTranslatedMessage(gadget, {
"message": "Action not handled"
});
}
}
if (action_name === 'paste_document_list') {
// Get the list of document uid from the internal clipboard
queue = gadget.getSettingClipboardAction('clipboard')
.push(function (uid_list) {
checked_uid_list = uid_list || [];
});
} else {
queue = new RSVP.Queue();
}
return queue
.push(function () {
if (checked_uid_list.length === 0) {
// Do not trigger action if the listbox was empty
// Dialog listbox use catalog method, which may be different from the current select method
// and so, it is mandatory to propagate a list of uid, otherwise, the dialog may display
// an unexpected huge list of unrelated documents
return notifyTranslatedMessage(gadget, {
"message": "Nothing selected"
});
}
if (action_name === 'copy_document_list') {
return gadget.setSettingClipboardAction('clipboard', checked_uid_list)
.push(function () {
return notifyTranslatedMessage(gadget, {
"message": "Copied",
"status": "success"
});
});
}
return gadget.redirectClipboardAction({
command: 'display_dialog_with_history',
options: {
"jio_key": gadget.state.jio_key,
"view": view,
"extended_search": createSearchQuery(
checked_uid_list,
'catalog.uid'
)
}
}, true);
});
}
function declareGadgetClassCanHandleListboxClipboardAction(gadget_klass) {
gadget_klass
.declareAcquiredMethod("getTranslationClipboardAction", "translate")
.declareAcquiredMethod("setSettingClipboardAction", "setSetting")
.declareAcquiredMethod("getSettingClipboardAction", "getSetting")
.declareAcquiredMethod("redirectClipboardAction", "redirect")
.declareAcquiredMethod("notifySubmittedClipboardAction",
"notifySubmitted")
// Handle listbox custom button
.allowPublicAcquisition("getListboxClipboardActionList",
getListboxClipboardActionList)
.allowPublicAcquisition("triggerListboxClipboardAction",
triggerListboxClipboardAction);
}
window.triggerListboxClipboardAction = triggerListboxClipboardAction;
window.declareGadgetClassCanHandleListboxClipboardAction =
declareGadgetClassCanHandleListboxClipboardAction;
}(window, RSVP, SimpleQuery, ComplexQuery, Query, ensureArray));
\ No newline at end of file
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.44086.53634.17646</string> </value>
<value> <string>974.49982.38828.49698</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1553855476.61</float>
<float>1554209210.63</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -696,7 +696,7 @@
button_element.setAttribute('data-select-action', select_option_list[k].action);
button_element.setAttribute('name', 'SelectAction');
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.setAttribute('class', 'ui-icon-' + select_option_list[k].icon + ' ui-btn-icon-left');
button_element.textContent = select_option_list[k].title;
div_element.appendChild(button_element);
}
......@@ -707,7 +707,7 @@
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.setAttribute('class', 'ui-icon-times ui-btn-icon-left');
button_element.textContent = translation_list[4];
div_element.appendChild(button_element);
......@@ -720,7 +720,7 @@
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.setAttribute('class', 'ui-icon-' + select_option_list[k].icon + ' ui-btn-icon-left');
button_element.textContent = select_option_list[k].title;
div_element.appendChild(button_element);
}
......@@ -731,7 +731,7 @@
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.setAttribute('class', 'ui-icon-times ui-btn-icon-left');
button_element.textContent = translation_list[4];
div_element.appendChild(button_element);
......@@ -762,11 +762,10 @@
// 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-list-ul ui-btn-icon-left ' + gadget.state.hide_class);
button_element.setAttribute('class', 'ui-icon-list-ul ui-btn-icon-left ');
button_element.textContent = translation_list[5];
div_element.appendChild(button_element);
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.49753.38890.51660</string> </value>
<value> <string>974.48625.48692.50363</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1554195993.54</float>
<float>1554127815.84</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -5,6 +5,9 @@
data-i18n=Include
data-i18n=Exclude
data-i18n=Delete
data-i18n=Action not handled
data-i18n=Nothing selected
data-i18n=Copied
-->
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
......@@ -20,7 +23,6 @@
<script src="jiodev.js" type="text/javascript"></script>
<script src="gadget_global.js" type="text/javascript"></script>
<script src="gadget_erp5_global.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<script src="gadget_erp5_pt_form_list.js" type="text/javascript"></script>
</head>
......@@ -41,4 +43,4 @@
</form>
</body>
</html>
</html>
\ No newline at end of file
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>972.29743.559.65006</string> </value>
<value> <string>974.48720.1486.39116</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1546423008.44</float>
<float>1554191230.42</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, calculatePageTitle, SimpleQuery, ComplexQuery,
Query, QueryFactory, ensureArray */
Query, QueryFactory, ensureArray, triggerListboxClipboardAction,
declareGadgetClassCanHandleListboxClipboardAction*/
/*jslint nomen: true, indent: 2, maxerr: 3, continue: true */
(function (window, rJS, RSVP, calculatePageTitle, SimpleQuery, ComplexQuery,
Query, QueryFactory, ensureArray) {
Query, QueryFactory, ensureArray, triggerListboxClipboardAction,
declareGadgetClassCanHandleListboxClipboardAction) {
"use strict";
function updateSearchQueryFromSelection(extended_search, checked_uid_list,
......@@ -62,48 +64,6 @@
return Query.objectToSearchText(search_query);
}
function triggerListboxClipboardAction(argument_list) {
var action_list = ensureArray(this.state.erp5_document._links.action_object_list_action || []),
action_name = argument_list[0],
checked_uid_list = argument_list[1],
gadget = this,
extended_search = gadget.state.extended_search,
view,
i;
for (i = 0; i < action_list.length; i += 1) {
if (action_name === action_list[i].name) {
view = action_list[i].href;
}
}
if (checked_uid_list.length !== 0) {
// If nothing is checked, use original query
extended_search = updateSearchQueryFromSelection(
extended_search,
checked_uid_list,
'catalog.uid',
true
);
}
if (view === undefined) {
// Action was not found.
// Reload
return gadget.redirect({
command: 'reload'
});
}
return gadget.redirect({
command: 'display_dialog_with_history',
options: {
"jio_key": gadget.state.jio_key,
"view": view,
"extended_search": extended_search
}
}, true);
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
......@@ -320,6 +280,9 @@
if (action_list[i].name === 'delete_document_list') {
continue;
}
if (action_list[i].name === 'paste_document_list') {
continue;
}
if (action_list[i].name === 'mass_workflow_jio') {
icon = 'random';
} else {
......@@ -365,35 +328,16 @@
}, true);
}
if (action !== 'delete_document_list') {
if ((action !== 'delete_document_list') &&
(action !== 'paste_document_list')) {
return triggerListboxClipboardAction.apply(this, [argument_list]);
}
throw new Error('Unsupported triggerListboxSelectAction action: ' + action);
})
// Handle listbox custom button
.allowPublicAcquisition("getListboxClipboardActionList", function getListboxClipboardActionList() {
var action_list = ensureArray(this.state.erp5_document._links.action_object_list_action || []),
i,
result_list = [],
icon;
for (i = 0; i < action_list.length; i += 1) {
if (action_list[i].name === 'delete_document_list') {
icon = 'trash-o';
} else {
continue;
}
result_list.push({
title: action_list[i].title,
icon: icon,
action: action_list[i].name
});
}
return result_list;
})
});
.allowPublicAcquisition("triggerListboxClipboardAction", triggerListboxClipboardAction);
declareGadgetClassCanHandleListboxClipboardAction(rJS(window));
}(window, rJS, RSVP, calculatePageTitle, SimpleQuery, ComplexQuery, Query,
QueryFactory, ensureArray));
\ No newline at end of file
QueryFactory, ensureArray, triggerListboxClipboardAction,
declareGadgetClassCanHandleListboxClipboardAction));
\ No newline at end of file
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>973.131.13855.5137</string> </value>
<value> <string>974.48375.47521.35942</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1547545219.53</float>
<float>1554113017.67</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<head>
<!--
data-i18n=Action not handled
data-i18n=Nothing selected
data-i18n=Copied
-->
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>ERP5 PT Form View</title>
......@@ -36,4 +41,4 @@
</div>
</form>
</body>
</html>
</html>
\ No newline at end of file
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>970.13790.51027.29644</string> </value>
<value> <string>974.48721.18403.49049</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1537194482.5</float>
<float>1554191271.73</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, calculatePageTitle */
/*global window, rJS, RSVP, calculatePageTitle,
declareGadgetClassCanHandleListboxClipboardAction */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, calculatePageTitle) {
(function (window, rJS, RSVP, calculatePageTitle,
declareGadgetClassCanHandleListboxClipboardAction) {
"use strict";
rJS(window)
.declareAcquiredMethod("submitContent", "submitContent")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("redirect", "redirect")
......@@ -179,4 +180,7 @@
}, false, true);
}(window, rJS, RSVP, calculatePageTitle));
\ No newline at end of file
declareGadgetClassCanHandleListboxClipboardAction(rJS(window));
}(window, rJS, RSVP, calculatePageTitle,
declareGadgetClassCanHandleListboxClipboardAction));
\ No newline at end of file
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>972.58906.44395.12356</string> </value>
<value> <string>974.48372.34584.55722</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1547195554.05</float>
<float>1554113074.68</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<head>
<!--
data-i18n=Action not handled
data-i18n=Nothing selected
data-i18n=Copied
-->
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>ERP5 PT Form View</title>
......@@ -30,4 +35,4 @@
</div>
</body>
</html>
</html>
\ No newline at end of file
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>970.13790.51027.29644</string> </value>
<value> <string>974.48721.10433.57924</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1537194595.83</float>
<float>1554191359.24</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, calculatePageTitle, isEmpty */
/*global window, rJS, RSVP, calculatePageTitle, isEmpty,
declareGadgetClassCanHandleListboxClipboardAction */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, calculatePageTitle, isEmpty) {
(function (window, rJS, RSVP, calculatePageTitle, isEmpty,
declareGadgetClassCanHandleListboxClipboardAction) {
"use strict";
/** Return true if `field` resembles non-empty and non-editable field. */
......@@ -161,4 +163,7 @@
});
});
}(window, rJS, RSVP, calculatePageTitle, isEmpty));
\ No newline at end of file
declareGadgetClassCanHandleListboxClipboardAction(rJS(window));
}(window, rJS, RSVP, calculatePageTitle, isEmpty,
declareGadgetClassCanHandleListboxClipboardAction));
\ No newline at end of file
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>972.58906.44395.12356</string> </value>
<value> <string>974.48369.21631.14967</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1547195629.34</float>
<float>1554112407.89</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -92,7 +92,7 @@
<td>//textarea[@name="field_workflow_form_your_comment"]</td>
<td>Crème brulée</td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_listbox_loaded" />
<tal:block tal:define="pagination_configuration python: {'header': '(4)', 'footer': '4 Records'}">
<tal:block tal:define="pagination_configuration python: {'header': '(3)', 'footer': '3 Records'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_pagination_text" />
</tal:block>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/submit_dialog" />
......@@ -168,7 +168,7 @@
<tr><td>waitForElementPresent</td>
<td>//textarea[@name="field_workflow_form_your_comment"]</td><td></td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_listbox_loaded" />
<tal:block tal:define="pagination_configuration python: {'header': '(4)', 'footer': '4 Records'}">
<tal:block tal:define="pagination_configuration python: {'header': '(2)', 'footer': '2 Records'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_pagination_text" />
</tal:block>
......@@ -189,7 +189,7 @@
<td>//textarea[@name="field_workflow_form_your_comment"]</td>
<td>Foobar comment</td></tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_listbox_loaded" />
<tal:block tal:define="pagination_configuration python: {'header': '(2)', 'footer': '2 Records'}">
<tal:block tal:define="pagination_configuration python: {'header': '(1)', 'footer': '1 Records'}">
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/check_listbox_pagination_text" />
</tal:block>
......
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