Commit d572f60b authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_web_renderjs_ui: show warning when leave page with unsaved data

parent 96f37c2c
......@@ -335,13 +335,15 @@
.allowPublicAcquisition('notifySubmitted', function (argument_list) {
return RSVP.all([
route(this, "header", 'notifySubmitted'),
route(this, "notification", 'notify', argument_list)
route(this, "notification", 'notify', argument_list),
route(this, "router", 'notify', argument_list)
]);
})
.allowPublicAcquisition('notifyChange', function (argument_list) {
return RSVP.all([
route(this, "header", 'notifyChange'),
route(this, "notification", 'notify', argument_list)
route(this, "notification", 'notify', argument_list),
route(this, "router", 'notify', argument_list)
]);
})
......@@ -578,7 +580,8 @@
.push(function () {
var promise_list = [
route(gadget, 'panel', 'close'),
route(gadget, 'editor_panel', 'close')
route(gadget, 'editor_panel', 'close'),
route(gadget, 'router', 'notify', [{modified : false}])
];
if (keep_message !== true) {
promise_list.push(route(gadget, 'notification', 'close'));
......
......@@ -216,7 +216,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>vincent</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>964.8140.54108.1245</string> </value>
<value> <string>964.29808.29957.65314</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1513245928.9</float>
<float>1514543212.43</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -19,7 +19,7 @@
/////////////////////////////////////////////////////////////////
gadget_klass
.declareMethod('notify', function (options) {
if (options) {
if (options && options.message) {
return this.changeState({
visible: true,
message: options.message,
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>961.59536.21138.61354</string> </value>
<value> <string>962.4168.39270.46967</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1504769866.21</float>
<float>1514542276.66</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -15,7 +15,9 @@
.declareAcquiredMethod("notifyChange", "notifyChange")
.declareAcquiredMethod("displayFormulatorValidationError",
"displayFormulatorValidationError")
.allowPublicAcquisition("notifyChange", function () {
return this.notifyChange({modified: true});
})
/////////////////////////////////////////////////////////////////
// Proxy methods to the child gadget
/////////////////////////////////////////////////////////////////
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>961.59393.42745.39918</string> </value>
<value> <string>962.4168.39270.46967</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1504701066.63</float>
<float>1514542029.91</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<head>
<!--
data-i18n=This page contains unsaved changes, do you really want to leave the page ?
-->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Router Gadget</title>
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.45675.44850.53452</string> </value>
<value> <string>964.35847.42197.53026</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1476956546.79</float>
<float>1514969789.88</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -812,6 +812,19 @@
}
}
//execute an url command without saving
if (gadget.props.modified && command[0] === PREFIX_COMMAND) {
if (!window.confirm(gadget.props.warning_message)) {
//back to previous hash
gadget.props.hasUnsaved = true;
return synchronousChangeState(evt.oldURL);
}
}
//don't rerender old page when back to the previous hash
if (gadget.props.hasUnsaved) {
gadget.props.hasUnsaved = false;
return;
}
return gadget.route({
method: command[0],
path: command.substr(1),
......@@ -974,7 +987,8 @@
return RSVP.all([
gadget.getSetting("selected_language"),
gadget.getSetting("default_selected_language"),
gadget.getSetting("language_map")
gadget.getSetting("language_map"),
gadget.translate("This page contains unsaved changes, do you really want to leave the page ?")
]);
})
.push(function (results) {
......@@ -986,6 +1000,7 @@
}
});
}
gadget.props.warning_message = results[3];
return gadget.listenHashChange();
})
.push(undefined, function (error) {
......@@ -995,6 +1010,9 @@
throw error;
});
})
.declareMethod('notify', function (options) {
this.props.modified = (options && options.modified);
})
.declareAcquiredMethod('renderApplication', 'renderApplication')
.declareAcquiredMethod('jio_allDocs', 'jio_allDocs')
......@@ -1002,9 +1020,23 @@
.declareAcquiredMethod('setSetting', 'setSetting')
.declareAcquiredMethod('getSetting', 'getSetting')
.declareAcquiredMethod('renderError', 'reportServiceError')
.declareAcquiredMethod('translate', 'translate')
.declareJob('listenHashChange', function () {
return listenHashChange(this);
})
.declareService(function () {
var gadget = this;
return loopEventListener(
window,
'beforeunload',
false,
function (event) {
if (gadget.props.modified) {
event.returnValue = 'fake';
}
return 'fake';
}
);
});
}(window, rJS, RSVP, loopEventListener, document, jIO, URI, URL, Blob));
\ No newline at end of file
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>964.29820.17700.38587</string> </value>
<value> <string>964.36966.42383.29030</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1514542054.97</float>
<float>1514970793.49</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