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

webrjsui: copy paste on form_view

parent 5dbdd4b5
/*global window, RSVP */
/*global window, RSVP, Array, isNaN, SimpleQuery, ComplexQuery, Query */
/*jslint indent: 2, maxerr: 3, nomen: true, unparam: true */
(function (window, RSVP) {
(function (window, RSVP, Array, isNaN, SimpleQuery, ComplexQuery, Query) {
"use strict";
window.calculatePageTitle = function (gadget, erp5_document) {
......@@ -15,4 +15,114 @@
});
};
}(window, RSVP));
///////////////////////////////
// Handle listbox action 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 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],
unchecked_uid_list = argument_list[2],
gadget = this,
extended_search = '',
view,
i;
if (action_name === 'copy_document_list') {
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 (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"
});
});
}
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 = createSearchQuery(
checked_uid_list,
'catalog.uid'
);
}
if (view === undefined) {
// Action was not found.
// Reload
return gadget.redirect({
command: 'reload'
});
}
if (action_name === 'paste_document_list') {
return gadget.getSetting('clipboard')
.push(function (uid_list) {
uid_list = uid_list || [];
if (uid_list.length === 0) {
// Nothing to paste, go away
uid_list = ['XXX'];
}
return gadget.redirect({
command: 'display_dialog_with_history',
options: {
"jio_key": gadget.state.jio_key,
"view": view,
"extended_search": createSearchQuery(
uid_list,
'catalog.uid'
)
}
}, true);
});
}
return gadget.redirect({
command: 'display_dialog_with_history',
options: {
"jio_key": gadget.state.jio_key,
"view": view,
"extended_search": extended_search
}
}, true);
}
window.triggerListboxClipboardAction = triggerListboxClipboardAction;
}(window, RSVP, Array, isNaN, SimpleQuery, ComplexQuery, Query));
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.44086.53634.17646</string> </value>
<value> <string>974.44319.22564.50107</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1553855476.61</float>
<float>1553869431.11</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -20,7 +20,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>
......
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>972.29743.559.65006</string> </value>
<value> <string>973.40657.63647.56780</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1546423008.44</float>
<float>1553869772.06</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>970.13790.51027.29644</string> </value>
<value> <string>973.40657.63647.56780</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1537194482.5</float>
<float>1553869925.08</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -5,6 +5,9 @@
rJS(window)
.declareAcquiredMethod("setSetting", "setSetting")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("submitContent", "submitContent")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("redirect", "redirect")
......@@ -177,6 +180,36 @@
}
}); // page form handles failures well enough
}, false, true);
}, false, true)
// 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;
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;
})
.allowPublicAcquisition("triggerListboxClipboardAction", triggerListboxClipboardAction);
}(window, rJS, RSVP, calculatePageTitle));
\ 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.44332.43937.58060</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1547195554.05</float>
<float>1553870231.56</float>
<string>UTC</string>
</tuple>
</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