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;
}); });
}); });
}) })
......
...@@ -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,25 +71,29 @@ ...@@ -71,25 +71,29 @@
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);
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) {
command = 'display_with_history_and_cancel';
} else {
// 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) {
...@@ -101,12 +105,15 @@ ...@@ -101,12 +105,15 @@
} else { } else {
command = 'push_history'; 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,11 +142,13 @@ ...@@ -142,11 +142,13 @@
</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>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -190,16 +192,20 @@ ...@@ -190,16 +192,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </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>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -208,7 +214,7 @@ ...@@ -208,7 +214,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>valentin</string> </value> <value> <string>zope</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -222,7 +228,7 @@ ...@@ -222,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>978.13676.64074.1365</string> </value> <value> <string>979.21958.43628.13243</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -240,7 +246,7 @@ ...@@ -240,7 +246,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1567589301.19</float> <float>1571996930.73</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -249,7 +255,9 @@ ...@@ -249,7 +255,9 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </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