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