Skip to content

Commit f0d9224

Browse files
authored
Warn the user the changes are not saved when clicking the Cancel button #62 (#76)
* Warn the user the changes are not saved when clicking the Cancel button #62 * Add translations
1 parent 20d2ff8 commit f0d9224

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

application-onlyoffice-connector-ui/src/main/resources/XWikiOnlyOfficeCode/Translations.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ xoo.inFrameContent.editConvertibleVersion.title=This document type ({0}) cannot
6161
xoo.inFrameContent.editConvertibleVersion.value=Edit version
6262
xoo.inFrameContent.loading=Loading OnlyOffice...
6363
xoo.inFrameContent.onPage=on page
64+
xoo.editor.cancel.confirm=You have unsaved changes. Are you sure you want to continue?
6465
xoo.validation.attachmentExists=An attachment with that name ({0}) already exists. Please choose another name.
6566
xoo.validation.attachmentMissing=Document or attachment not found!
6667
xoo.validation.documentMissing=Document parameter required!

application-onlyoffice-connector-ui/src/main/resources/XWikiOnlyOfficeCode/XooEdit.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@
145145
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
146146
<title>${currentAction}$escapetool.xml($request.filename)</title>
147147
#template('stylesheets.vm')
148+
#template('javascript.vm')
149+
148150
<link rel="stylesheet" type="text/css" href="$doc.getURL('ssx')">
149151
## Old IE
150152
<link rel="shortcut icon" href="$xwiki.getSkinFile('icons/xwiki/favicon.ico')" />
@@ -155,13 +157,7 @@
155157
## For smart phones and tablets
156158
<link rel="apple-touch-icon" href="$xwiki.getSkinFile('icons/xwiki/favicon144.png')" />
157159

158-
<script type="text/javascript" src="$services.webjars.url('requirejs', 'require.min.js')"></script>
159160
<script type="text/javascript" language="javascript">
160-
require.config({
161-
paths: {
162-
'jquery': "$services.webjars.url('jquery', 'jquery.min.js')"
163-
}
164-
});
165161
require.onError = function(err) {
166162
var div = document.getElementById('iframeEditor');
167163
if (!div) {

application-onlyoffice-connector-webjar/src/main/webjar/xwiki-onlyoffice.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
1818
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
1919
*/
20-
define(['jquery'], function ($) {
20+
define('xwiki-onlyoffice-wrapper', {
21+
prefix: 'xoo.editor.',
22+
keys: [
23+
'cancel.confirm'
24+
]
25+
});
26+
define(['jquery', 'xwiki-l10n!xwiki-onlyoffice-wrapper'], function ($, l10n) {
2127
var TEXT_EXTENSIONS = [
2228
"djvu", "doc", "docx", "epub", "fb2", "htm", "html", "mht", "odt",
2329
"pdf", "rtf", "txt", "xps"
@@ -206,9 +212,15 @@ define(['jquery'], function ($) {
206212
ready = true;
207213
console.log("Document editor ready2");
208214
$('#button-cancel').on('click', function () {
215+
if (window.docEditor && window.docEditor.xwikiEdited && !confirm(l10n.get('cancel.confirm'))) {
216+
return;
217+
}
209218
window.location.href = ctx.config.DOCU_VIEW_URL;
210219
});
211220
$('#button-sac').on('click', save(function () {
221+
if (window.docEditor) {
222+
window.docEditor.xwikiEdited = false;
223+
}
212224
console.log("saved");
213225
}, false));
214226
$('#button-sav').on('click', save(function () {
@@ -265,7 +277,12 @@ define(['jquery'], function ($) {
265277
onRequestEditRights: function () { docEditor.applyEditRights(true); },
266278
// The event.data will be true when the current user is editing the document and false when the current user's
267279
// changes are sent to the document editing service.
268-
onDocumentStateChange: function (evt) { $('#button-sav').prop('disabled', evt.data); },
280+
onDocumentStateChange: function (evt) {
281+
$('#button-sav').prop('disabled', evt.data);
282+
if (window.docEditor) {
283+
window.docEditor.xwikiEdited = true;
284+
}
285+
},
269286
onError: onError
270287
}
271288
};

0 commit comments

Comments
 (0)