From 9d32f5cbae593617fe8817dfbfded8756e2b4dd1 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 18 Nov 2015 13:03:37 +0100 Subject: [PATCH] Add Terminate button on document editing page (T845) --- plugins/kolab_files/kolab_files.js | 37 +++++++++++++++++-- .../kolab_files/lib/kolab_files_engine.php | 2 + plugins/kolab_files/localization/en_US.inc | 3 ++ .../skins/larry/templates/docedit.html | 1 + 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/plugins/kolab_files/kolab_files.js b/plugins/kolab_files/kolab_files.js index 6e7ca0a9..2ed926fa 100644 --- a/plugins/kolab_files/kolab_files.js +++ b/plugins/kolab_files/kolab_files.js @@ -1006,7 +1006,8 @@ function kolab_files_selected() function kolab_files_frame_load(frame) { - var win = frame.contentWindow; + var win = frame.contentWindow, + info = rcmail.env.file_data; try { rcmail.file_editor = win.file_editor && win.file_editor.editable ? win.file_editor : null; @@ -1018,10 +1019,9 @@ function kolab_files_frame_load(frame) rcmail.files_edit(); rcmail.enable_command('files-edit', rcmail.file_editor - || (rcmail.env.file_data.viewer && rcmail.env.file_data.viewer.manticore)); + || (info && info.viewer && info.viewer.manticore)); rcmail.enable_command('files-print', (rcmail.file_editor && rcmail.file_editor.printable) - || (rcmail.env.file_data && /^image\//i.test(rcmail.env.file_data.type))); - + || (info && /^image\//i.test(info.type))); // detect Print button and check if it can be accessed try { if ($('#fileframe').contents().find('#print').length) @@ -1122,7 +1122,10 @@ function kolab_files_progress_str(param) // Initialize document toolbar functionality function manticore_init() { + var info = rcmail.env.file_data; + rcmail.enable_command('document-save', 'document-export', true); + rcmail.enable_command('files-close', info && info.session && info.session.is_owner); }; rcube_webmail.prototype.document_save = function() @@ -1280,6 +1283,13 @@ rcube_webmail.prototype.files_edit = function(session) } }; +// close editing session +rcube_webmail.prototype.files_close = function() +{ + // @todo: check document "unsaved changes" state and display a warning + file_api.document_delete(this.env.file_data.session.id); +}; + rcube_webmail.prototype.files_save = function() { if (!this.file_editor) @@ -2906,6 +2916,25 @@ function kolab_files_ui() } }; + // document session delete request + this.document_delete = function(id) + { + this.req = this.set_busy(true, 'kolab_files.sessionterminating'); + this.request('document_delete', {id: id}, 'document_delete_response'); + }; + + // document session delete response handler + this.document_delete_response = function(response) + { + if (!this.response(response)) + return; + + if (rcmail.task == 'files' && rcmail.env.action == 'edit') + window.close(); + + // @todo: force sessions info update + }; + // handle auth errors on folder list this.folder_list_auth_errors = function(result) { diff --git a/plugins/kolab_files/lib/kolab_files_engine.php b/plugins/kolab_files/lib/kolab_files_engine.php index 5607ee63..7954b1cb 100644 --- a/plugins/kolab_files/lib/kolab_files_engine.php +++ b/plugins/kolab_files/lib/kolab_files_engine.php @@ -918,6 +918,8 @@ class kolab_files_engine */ protected function action_edit() { + $this->plugin->add_label('sessionterminating'); + $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 b8eb0ac7..a95b6586 100644 --- a/plugins/kolab_files/localization/en_US.inc +++ b/plugins/kolab_files/localization/en_US.inc @@ -101,6 +101,9 @@ $labels['joinsession'] = 'Request an invitation from $user'; $labels['editfilero'] = 'This file is read-only. Do you want to create and edit a copy of the file?'; $labels['editfilerotitle'] = 'Read-only file'; $labels['select'] = 'Select'; +$labels['terminatesession'] = 'Terminate the session'; +$labels['terminate'] = 'Terminate'; +$labels['sessionterminating'] = 'Terminating the session...'; $labels['storepasswords'] = 'remember password'; $labels['storepasswordsdesc'] = 'Stored passwords will be encrypted. Enable this if you do not want to be asked for the password on every login or you want this storage to be available via WebDAV.'; diff --git a/plugins/kolab_files/skins/larry/templates/docedit.html b/plugins/kolab_files/skins/larry/templates/docedit.html index 468ebd0c..4839d22a 100644 --- a/plugins/kolab_files/skins/larry/templates/docedit.html +++ b/plugins/kolab_files/skins/larry/templates/docedit.html @@ -18,6 +18,7 @@ +