Commit cfa27657 authored by Gabriel Monnerat's avatar Gabriel Monnerat

HACK erp5_web_renderjs_ui: Add command to keep history when displaying an erp5 action

erp5_web_renderjs_ui: Refactor code to support more than option as page

Sometimes we can display "preview" or "html_view"

erp5_web_renderjs_ui: Small changes on router to follow latest erp5 master
parent eabc24ef
......@@ -26,6 +26,8 @@
COMMAND_KEEP_HISTORY_AND_DISPLAY_DIALOG_STATE = "display_dialog_with_history",
// Display the cancellable url (or the current doc default) + the history
COMMAND_KEEP_HISTORY_AND_CANCEL_DIALOG_STATE = "cancel_dialog_with_history",
// Display an action on the jio document + the history
COMMAND_KEEP_HISTORY_AND_DISPLAY_ERP5_ACTION = "display_erp5_action_with_history",
// Store the jio key for the person document of the user
COMMAND_LOGIN = "login",
// Display a raw string URL
......@@ -65,6 +67,7 @@
VALID_URL_COMMAND_DICT[COMMAND_KEEP_HISTORY_CANCEL_AND_DISPLAY_STATE] = null;
VALID_URL_COMMAND_DICT[COMMAND_KEEP_HISTORY_AND_DISPLAY_DIALOG_STATE] = null;
VALID_URL_COMMAND_DICT[COMMAND_KEEP_HISTORY_AND_CANCEL_DIALOG_STATE] = null;
VALID_URL_COMMAND_DICT[COMMAND_KEEP_HISTORY_AND_DISPLAY_ERP5_ACTION] = null;
VALID_URL_COMMAND_DICT[COMMAND_DISPLAY_STORED_STATE] = null;
VALID_URL_COMMAND_DICT[COMMAND_CHANGE_STATE] = null;
VALID_URL_COMMAND_DICT[COMMAND_DISPLAY_ERP5_ACTION] = null;
......@@ -388,35 +391,56 @@
);
}
function execDisplayERP5ActionCommand(gadget, options) {
return gadget.jio_getAttachment(options.jio_key, 'links')
function execDisplayERP5ActionCommand(gadget, previous_options, next_options, keep_history) {
return gadget.jio_getAttachment(next_options.jio_key, 'links')
.push(function (document_view) {
var action, action_data, action_url, i, j, new_options;
var action,
queue,
action_data,
action_url,
i,
j,
k,
new_options,
options_page;
if (next_options.page.constructor === String) {
if (next_options.page.indexOf(",") !== -1) {
options_page = next_options.page.split(",");
} else {
options_page = [next_options.page];
}
}
for (i = 0; i < Object.keys(document_view._links).length; i = i + 1) {
action = Object.keys(document_view._links)[i];
// XXX This is a hack for Capago
if (action !== "view") {
continue;
}
if (document_view._links.hasOwnProperty(action)) {
if (document_view._links[action].constructor !== Array) {
document_view._links[action] = [document_view._links[action]];
}
for (j = 0; j < document_view._links[action].length; j = j + 1) {
action_data = document_view._links[action][j];
if (action_data.name === options.page) {
new_options = {
jio_key: options.jio_key,
view: action_data.href
};
copyStickyParameterDict(options, new_options);
action_url = getDisplayUrlFor(
options.jio_key,
new_options
);
return synchronousChangeState(action_url);
for (k = 0; k < options_page.length; k = k + 1) {
if (action_data.name && action_data.name.indexOf(options_page[k]) !== -1) {
new_options = {
jio_key: next_options.jio_key,
view: action_data.href
};
queue = RSVP.Queue();
copyStickyParameterDict(next_options, new_options);
if (keep_history) {
return execPushHistoryCommand(gadget, previous_options, new_options);
}
return execDisplayCommand(gadget, new_options);
}
}
}
}
}
throw new Error('Action not found: ' + options.name);
throw new Error('Action not found: ' + next_options.name);
});
}
......@@ -433,8 +457,11 @@
}
display_url = getDisplayUrlFor(jio_key, options);
if (storage_key) {
// Only keep state for the default view
// otherwise, user will never be able to reset it with the filter panel
// Do not store state for module subdocument, to not pollute the IDB size
if ((storage_key && (storage_key.indexOf('/') === -1)) &&
((options.view === undefined) || (options.view === 'view'))) {
queue = gadget.props.jio_state_gadget.put(storage_key, dropStickyParameterEntry(options));
} else {
queue = new RSVP.Queue();
......@@ -641,13 +668,15 @@
var parent_link = erp5_document._links.parent,
uri,
options = {};
copyStickyParameterDict(previous_options, options);
if (parent_link !== undefined) {
uri = new URI(parent_link.href);
copyStickyParameterDict(previous_options, options);
options.jio_key = uri.segment(2);
// When redirecting to parent, always try to restore the state
return execDisplayStoredStateCommand(gadget, options);
}
// If no parent, return to the home page
return gadget.redirect({command: 'display', options: options});
}, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
......@@ -887,6 +916,9 @@
if (command_options.path === COMMAND_KEEP_HISTORY_AND_CANCEL_DIALOG_STATE) {
return execKeepHistoryAndCancelDialogCommand(gadget, previous_options);
}
if (command_options.path === COMMAND_KEEP_HISTORY_AND_DISPLAY_ERP5_ACTION) {
return execDisplayERP5ActionCommand(gadget, previous_options, next_options, true);
}
if (command_options.path === COMMAND_DISPLAY_STORED_STATE) {
return execDisplayStoredStateCommand(gadget, next_options, drop_options);
}
......@@ -897,7 +929,7 @@
return execChangeCommand(previous_options, next_options, drop_options);
}
if (command_options.path === COMMAND_DISPLAY_ERP5_ACTION) {
return execDisplayERP5ActionCommand(gadget, next_options);
return execDisplayERP5ActionCommand(gadget, previous_options, next_options);
}
if (command_options.path === COMMAND_STORE_AND_CHANGE_STATE) {
return execStoreAndChangeCommand(gadget, previous_options, next_options, drop_options);
......@@ -1186,4 +1218,4 @@
false
);
});
}(window, rJS, RSVP, loopEventListener, document, jIO, URI, URL, Blob));
\ No newline at end of file
}(window, rJS, RSVP, loopEventListener, document, jIO, URI, URL, Blob));
......@@ -222,7 +222,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>ERP5TypeTestCase</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>979.51895.64958.60108</string> </value>
<value> <string>985.49865.7906.35925</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1573725627.05</float>
<float>1596764862.76</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