Commit 97fb5989 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Handle redirection to a specific view

parent fbac275e
...@@ -361,13 +361,18 @@ and handling data send&receive. ...@@ -361,13 +361,18 @@ and handling data send&receive.
var gadget = this, var gadget = this,
jio_key = param_list[0], jio_key = param_list[0],
target_url = param_list[1], target_url = param_list[1],
content_dict = param_list[2]; content_dict = param_list[2],
result = {
jio_key: undefined,
view: undefined
};
return gadget.notifySubmitting() return gadget.notifySubmitting()
.push(function () { .push(function () {
return gadget.jio_putAttachment(jio_key, target_url, content_dict); return gadget.jio_putAttachment(jio_key, target_url, content_dict);
}) })
.push(function (attachment) { .push(function (attachment) {
var response;
if (attachment.target.response.type === "application/json") { if (attachment.target.response.type === "application/json") {
// successful form save returns simple redirect and an answer as JSON // successful form save returns simple redirect and an answer as JSON
...@@ -379,7 +384,7 @@ and handling data send&receive. ...@@ -379,7 +384,7 @@ and handling data send&receive.
]); ]);
}) })
.push(function (result_list) { .push(function (result_list) {
var response = JSON.parse(result_list[0].target.result); response = JSON.parse(result_list[0].target.result);
return gadget.notifySubmitted({ return gadget.notifySubmitted({
"message": response.portal_status_message || result_list[1], "message": response.portal_status_message || result_list[1],
...@@ -389,11 +394,15 @@ and handling data send&receive. ...@@ -389,11 +394,15 @@ and handling data send&receive.
.push(function () { .push(function () {
// here we figure out where to go after form submit - indicated // here we figure out where to go after form submit - indicated
// by X-Location HTTP header placed by Base_redirect script // by X-Location HTTP header placed by Base_redirect script
var redirect_jio_key = new URI( var uri = new URI(
attachment.target.getResponseHeader("X-Location") attachment.target.getResponseHeader("X-Location")
).segment(2); ),
redirect_jio_key = uri.segment(2);
return redirect_jio_key; result.jio_key = redirect_jio_key;
if (response._links.hasOwnProperty('location')) {
result.view = response._links.location.href;
}
return result;
}); });
} }
...@@ -449,7 +458,7 @@ and handling data send&receive. ...@@ -449,7 +458,7 @@ and handling data send&receive.
// Make sure to return nothing (previous render can return // Make sure to return nothing (previous render can return
// something) so the successfull handler does not receive // something) so the successfull handler does not receive
// anything which it could consider as redirect jio key. // anything which it could consider as redirect jio key.
return; return result;
}); });
}); });
} }
...@@ -468,7 +477,8 @@ and handling data send&receive. ...@@ -468,7 +477,8 @@ and handling data send&receive.
}); });
}) })
.push(function () { .push(function () {
return jio_key; result.jio_key = jio_key;
return result;
}); });
} }
...@@ -488,7 +498,8 @@ and handling data send&receive. ...@@ -488,7 +498,8 @@ and handling data send&receive.
// in the old UI but it will be a change of behaviour // in the old UI but it will be a change of behaviour
// Nicolas required this feature to be allowed // Nicolas required this feature to be allowed
.push(function () { .push(function () {
return jio_key; result.jio_key = jio_key;
return result;
}); });
}) })
...@@ -511,7 +522,8 @@ and handling data send&receive. ...@@ -511,7 +522,8 @@ and handling data send&receive.
}); });
}) })
.push(function () { .push(function () {
return; // error was handled // error was handled
return result;
}); });
} }
...@@ -572,11 +584,15 @@ and handling data send&receive. ...@@ -572,11 +584,15 @@ and handling data send&receive.
erp5_document._now = Date.now(); erp5_document._now = Date.now();
return gadget.changeState({erp5_document: JSON.stringify(erp5_document), return gadget.changeState({erp5_document: JSON.stringify(erp5_document),
is_refresh: true}); is_refresh: true});
})
.push(function () {
return result;
}); });
} }
}) })
.push(function () { .push(function () {
return; // error was handled // error was handled
return result;
}); });
} }
...@@ -593,7 +609,8 @@ and handling data send&receive. ...@@ -593,7 +609,8 @@ and handling data send&receive.
}); });
}) })
.push(function () { .push(function () {
return; // error was handled // error was handled
return result;
}); });
}); });
}) })
...@@ -611,10 +628,10 @@ and handling data send&receive. ...@@ -611,10 +628,10 @@ and handling data send&receive.
attachment.target.getResponseHeader("Content-Disposition") || "" attachment.target.getResponseHeader("Content-Disposition") || ""
), ),
a_tag = document.createElement("a"); a_tag = document.createElement("a");
if (filename_utf8_quoted) { if (filename_utf8_quoted) {
filename = filename_utf8_quoted; filename = filename_utf8_quoted;
filename[1] = decodeURI(filename[1]); filename[1] = decodeURI(filename[1]);
} }
/*jslint regexp: false */ /*jslint regexp: false */
if (attachment.target.responseType !== "blob") { if (attachment.target.responseType !== "blob") {
......
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>978.43862.35468.53555</string> </value> <value> <string>979.200.9391.33553</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>1569398056.45</float> <float>1570693140.76</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -71,42 +71,49 @@ ...@@ -71,42 +71,49 @@
data data
); );
}) })
.push(function (jio_key) { // success redirect handler .push(function (result) { // success redirect handler
var splitted_jio_key_list, var splitted_jio_key_list,
splitted_current_jio_key_list, splitted_current_jio_key_list,
command, command,
i; i;
if (is_updating || !jio_key) { if (is_updating || !result.jio_key) {
return; return;
} }
if (gadget.state.redirect_to_parent) { if (gadget.state.redirect_to_parent) {
return gadget.redirect({command: 'history_previous'}); return gadget.redirect({command: 'history_previous'});
} }
if (gadget.state.jio_key === jio_key) { console.log('COSUCOUS', result);
Please register or sign in to reply
if ((gadget.state.jio_key === result.jio_key) &&
(!result.view)) {
// don't update navigation history when not really redirecting // don't update navigation history when not really redirecting
return gadget.redirect({command: 'cancel_dialog_with_history'}); return gadget.redirect({command: 'cancel_dialog_with_history'});
} } else if (gadget.state.jio_key === result.jio_key) {
// Check if the redirection goes to a same parent's subdocument. command = 'display_with_history_and_cancel';
// In this case, do not add current document to the history } else {
// example: when cloning, do not keep the original document in history // Check if the redirection goes to a same parent's subdocument.
splitted_jio_key_list = jio_key.split('/'); // In this case, do not add current document to the history
splitted_current_jio_key_list = gadget.state.jio_key.split('/'); // example: when cloning, do not keep the original document in history
command = 'display_with_history'; splitted_jio_key_list = result.jio_key.split('/');
if (splitted_jio_key_list.length === splitted_current_jio_key_list.length) { splitted_current_jio_key_list = gadget.state.jio_key.split('/');
for (i = 0; i < splitted_jio_key_list.length - 1; i += 1) { command = 'display_with_history';
if (splitted_jio_key_list[i] !== splitted_current_jio_key_list[i]) { if (splitted_jio_key_list.length === splitted_current_jio_key_list.length) {
command = 'push_history'; for (i = 0; i < splitted_jio_key_list.length - 1; i += 1) {
if (splitted_jio_key_list[i] !== splitted_current_jio_key_list[i]) {
command = 'push_history';
}
} }
} else {
command = 'push_history';
} }
} else {
command = 'push_history';
} }
console.log('lets redirect', command, result.jio_key, result.view);
// forced document change thus we update history // forced document change thus we update history
return gadget.redirect({ return gadget.redirect({
command: command, command: command,
options: { options: {
"jio_key": jio_key "jio_key": result.jio_key,
"view": result.view
// do not mingle with editable because it isn't necessary // do not mingle with editable because it isn't necessary
} }
}); });
...@@ -255,7 +262,7 @@ ...@@ -255,7 +262,7 @@
]); ]);
}) })
.push(function (translated_title_list) { .push(function (translated_title_list) {
var action_confirm = form_gadget.element.querySelector('input.dialogconfirm') var action_confirm = form_gadget.element.querySelector('input.dialogconfirm');
if (form_gadget.state.action_title) { if (form_gadget.state.action_title) {
action_confirm.value = form_gadget.state.action_title; action_confirm.value = form_gadget.state.action_title;
} else { } else {
......
...@@ -142,114 +142,122 @@ ...@@ -142,114 +142,122 @@
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<list> <key> <string>_log</string> </key>
<dictionary> <value>
<item> <list>
<key> <string>action</string> </key> <dictionary>
<value> <string>publish_alive</string> </value> <item>
</item> <key> <string>action</string> </key>
<item> <value> <string>publish_alive</string> </value>
<key> <string>actor</string> </key> </item>
<value> <string>superkato</string> </value> <item>
</item> <key> <string>actor</string> </key>
<item> <value> <string>superkato</string> </value>
<key> <string>comment</string> </key> </item>
<value> <string></string> </value> <item>
</item> <key> <string>comment</string> </key>
<item> <value> <string></string> </value>
<key> <string>error_message</string> </key> </item>
<value> <string></string> </value> <item>
</item> <key> <string>error_message</string> </key>
<item> <value> <string></string> </value>
<key> <string>time</string> </key> </item>
<value> <item>
<object> <key> <string>time</string> </key>
<klass> <value>
<global name="DateTime" module="DateTime.DateTime"/> <object>
</klass> <klass>
<tuple> <global name="DateTime" module="DateTime.DateTime"/>
<none/> </klass>
</tuple> <tuple>
<state> <none/>
<tuple> </tuple>
<float>1523969253.3</float> <state>
<string>UTC</string> <tuple>
</tuple> <float>1523969253.3</float>
</state> <string>UTC</string>
</object> </tuple>
</value> </state>
</item> </object>
<item> </value>
<key> <string>validation_state</string> </key> </item>
<value> <string>published_alive</string> </value> <item>
</item> <key> <string>validation_state</string> </key>
</dictionary> <value> <string>published_alive</string> </value>
</list> </item>
</tuple> </dictionary>
</list>
</value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<list> <key> <string>_log</string> </key>
<dictionary> <value>
<item> <list>
<key> <string>action</string> </key> <dictionary>
<value> <string>edit</string> </value> <item>
</item> <key> <string>action</string> </key>
<item> <value> <string>edit</string> </value>
<key> <string>actor</string> </key> </item>
<value> <string>valentin</string> </value> <item>
</item> <key> <string>actor</string> </key>
<item> <value> <string>zope</string> </value>
<key> <string>comment</string> </key> </item>
<value> <item>
<none/> <key> <string>comment</string> </key>
</value> <value>
</item> <none/>
<item> </value>
<key> <string>error_message</string> </key> </item>
<value> <string></string> </value> <item>
</item> <key> <string>error_message</string> </key>
<item> <value> <string></string> </value>
<key> <string>serial</string> </key> </item>
<value> <string>978.13676.64074.1365</string> </value> <item>
</item> <key> <string>serial</string> </key>
<item> <value> <string>979.21958.43628.13243</string> </value>
<key> <string>state</string> </key> </item>
<value> <string>current</string> </value> <item>
</item> <key> <string>state</string> </key>
<item> <value> <string>current</string> </value>
<key> <string>time</string> </key> </item>
<value> <item>
<object> <key> <string>time</string> </key>
<klass> <value>
<global name="DateTime" module="DateTime.DateTime"/> <object>
</klass> <klass>
<tuple> <global name="DateTime" module="DateTime.DateTime"/>
<none/> </klass>
</tuple> <tuple>
<state> <none/>
<tuple> </tuple>
<float>1567589301.19</float> <state>
<string>UTC</string> <tuple>
</tuple> <float>1571996930.73</float>
</state> <string>UTC</string>
</object> </tuple>
</value> </state>
</item> </object>
</dictionary> </value>
</list> </item>
</tuple> </dictionary>
</list>
</value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
...@@ -31,23 +31,23 @@ ...@@ -31,23 +31,23 @@
data data
); );
}) })
.push(function (jio_key) { // success redirect handler .push(function (result) { // success redirect handler
var splitted_jio_key_list, var splitted_jio_key_list,
splitted_current_jio_key_list, splitted_current_jio_key_list,
command, command,
i; i;
if (!jio_key) { if (!result.jio_key) {
return; return;
} }
if (gadget.state.jio_key === jio_key) { if (gadget.state.jio_key === result.jio_key) {
// don't update navigation history when not really redirecting // don't update navigation history when not really redirecting
return gadget.redirect({command: 'cancel_dialog_with_history'}); return gadget.redirect({command: 'cancel_dialog_with_history'});
} }
// Check if the redirection goes to a same parent's subdocument. // Check if the redirection goes to a same parent's subdocument.
// In this case, do not add current document to the history // In this case, do not add current document to the history
// example: when cloning, do not keep the original document in history // example: when cloning, do not keep the original document in history
splitted_jio_key_list = jio_key.split('/'); splitted_jio_key_list = result.jio_key.split('/');
splitted_current_jio_key_list = gadget.state.jio_key.split('/'); splitted_current_jio_key_list = gadget.state.jio_key.split('/');
command = 'display_with_history'; command = 'display_with_history';
if (splitted_jio_key_list.length === splitted_current_jio_key_list.length) { if (splitted_jio_key_list.length === splitted_current_jio_key_list.length) {
...@@ -64,7 +64,8 @@ ...@@ -64,7 +64,8 @@
return gadget.redirect({ return gadget.redirect({
command: command, command: command,
options: { options: {
"jio_key": jio_key "jio_key": result.jio_key,
"view": result.view
// do not mingle with editable because it isn't necessary // do not mingle with editable because it isn't necessary
} }
}); });
......
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>978.35224.37222.15547</string> </value> <value> <string>979.197.9357.62617</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>1568880648.91</float> <float>1570623795.93</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -163,7 +163,7 @@ ...@@ -163,7 +163,7 @@
}) })
.push(function (content_dict) { .push(function (content_dict) {
if (content_dict === null) { if (content_dict === null) {
return; return {};
} }
return gadget.submitContent( return gadget.submitContent(
gadget.state.jio_key, gadget.state.jio_key,
...@@ -171,8 +171,8 @@ ...@@ -171,8 +171,8 @@
content_dict content_dict
); );
}) })
.push(function (jio_key) { .push(function (result) {
if (jio_key) { if (result.jio_key) {
// success redirect callback receives jio_key // success redirect callback receives jio_key
return gadget.redirect({command: 'reload'}); return gadget.redirect({command: 'reload'});
} }
......
...@@ -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.48372.34584.55722</string> </value> <value> <string>979.2796.18260.40345</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>1554113074.68</float> <float>1570779670.8</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