diff --git a/plugins/kolab_files/kolab_files.js b/plugins/kolab_files/kolab_files.js
index 59f767fe..46df8799 100644
--- a/plugins/kolab_files/kolab_files.js
+++ b/plugins/kolab_files/kolab_files.js
@@ -113,13 +113,17 @@ window.rcmail && window.files_api && rcmail.addEventListener('init', function()
if (rcmail.env.action == 'edit' && rcmail.env.file_data.viewer && rcmail.env.file_data.viewer.manticore)
manticore = new manticore_api({
+ // UI elements
iframe: $('#fileframe').get(0),
export_menu: rcmail.gui_objects.exportmenu ? $('ul', rcmail.gui_objects.exportmenu).get(0) : null,
title_input: $('#document-title').get(0),
members_list: $('#members').get(0),
photo_url: '?_task=addressbook&_action=photo&_email=%email',
photo_default_url: rcmail.env.photo_placeholder,
+ // events
ready: function(data) { manticore_init(); },
+ documentChanged: function(data) { rcmail.enable_command('document-save', true); },
+ // notifications/alerts
set_busy: function(state, message) { return rcmail.set_busy(state, message ? 'kolab_files.' + message : ''); },
hide_message: function(id) { return rcmail.hide_message(id); },
display_message: function(label, type) { return rcmail.display_message('kolab_files.' + label, type); },
@@ -1124,15 +1128,17 @@ function manticore_init()
{
var info = rcmail.env.file_data;
- rcmail.enable_command('document-save', 'document-export', true);
+ rcmail.enable_command('document-export', true);
if (info && info.session && info.session.is_owner)
- rcmail.enable_command('files-close', 'document-editors', true);
+ rcmail.enable_command('document-close', 'document-editors', true);
};
rcube_webmail.prototype.document_save = function()
{
- manticore.save();
+ manticore.save(function(data) {
+ rcmail.enable_command('document-save', false);
+ });
};
rcube_webmail.prototype.document_export = function(type)
@@ -1151,10 +1157,13 @@ rcube_webmail.prototype.document_editors = function()
};
// close editing session
-rcube_webmail.prototype.files_close = function()
+rcube_webmail.prototype.document_close = function()
{
- // @todo: check document "unsaved changes" state and display a warning
- file_api.document_delete(this.env.file_data.session.id);
+ // check document "unsaved changes" state and display a warning
+ if (this.commands['document-save'] && !confirm(this.gettext('kolab_files.unsavedchanges')))
+ return;
+
+ file_api.document_delete(this.env.file_data.session.id);
};
// document editors management dialog
diff --git a/plugins/kolab_files/lib/kolab_files_engine.php b/plugins/kolab_files/lib/kolab_files_engine.php
index efa70769..fda250ce 100644
--- a/plugins/kolab_files/lib/kolab_files_engine.php
+++ b/plugins/kolab_files/lib/kolab_files_engine.php
@@ -950,7 +950,7 @@ class kolab_files_engine
*/
protected function action_edit()
{
- $this->plugin->add_label('sessionterminating');
+ $this->plugin->add_label('sessionterminating', 'unsavedchanges');
$this->file_opener(intval($_GET['_viewer']));
}
diff --git a/plugins/kolab_files/localization/en_US.inc b/plugins/kolab_files/localization/en_US.inc
index a2812d2b..88ba16c6 100644
--- a/plugins/kolab_files/localization/en_US.inc
+++ b/plugins/kolab_files/localization/en_US.inc
@@ -105,6 +105,7 @@ $labels['select'] = 'Select';
$labels['terminatesession'] = 'Terminate the session';
$labels['terminate'] = 'Terminate';
$labels['sessionterminating'] = 'Terminating the session...';
+$labels['unsavedchanges'] = 'There are unsaved changes in the document that will be lost. Do you want to terminate the session anyway?';
$labels['manageeditors'] = 'Invite to document';
$labels['participant'] = 'Participant';
$labels['status'] = 'Status';
diff --git a/plugins/kolab_files/skins/larry/templates/docedit.html b/plugins/kolab_files/skins/larry/templates/docedit.html
index cbcd3ef9..90629786 100644
--- a/plugins/kolab_files/skins/larry/templates/docedit.html
+++ b/plugins/kolab_files/skins/larry/templates/docedit.html
@@ -18,7 +18,7 @@
-
+