From aa0a8f666ada8f1d1edae17b906089cc03ba473d Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Wed, 4 Nov 2015 13:15:22 +0100 Subject: [PATCH] cloudsuite: Implement the saving back. --- appinfo/routes.php | 1 + controller/documentcontroller.php | 31 +++++++++++++++++++++++++++++++ js/documents.js | 21 +++++++++++++++++++-- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index c23bbaaf..79a42065 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -34,6 +34,7 @@ $application->registerRoutes($this, [ ['name' => 'document#download', 'url' => 'ajax/download.php', 'verb' => 'GET'], //documents - for CloudSuite access ['name' => 'document#localLoad', 'url' => 'load/{fileId}', 'verb' => 'POST'], + ['name' => 'document#localSave', 'url' => 'save/{fileId}', 'verb' => 'POST'], //settings ['name' => 'settings#savePersonal', 'url' => 'ajax/personal.php', 'verb' => 'POST'], ['name' => 'settings#setUnstable', 'url' => 'ajax/config/unstable', 'verb' => 'POST'], diff --git a/controller/documentcontroller.php b/controller/documentcontroller.php index e0946fb9..bd375721 100644 --- a/controller/documentcontroller.php +++ b/controller/documentcontroller.php @@ -138,6 +138,37 @@ class DocumentController extends Controller{ ); } + /** + * @NoAdminRequired + * @PublicPage + * Copy the file to a temporary location that is shared between the + * cloudsuite server part and owncloud. + */ + public function localSave($fileId){ + // get really just the basename for the case somebody tries to trick us + $basename = basename($this->request->post['basename']); + + $filename = dirname(__DIR__) . self::CLOUDSUITE_TMP_PATH . $basename; + + $view = \OC\Files\Filesystem::getView(); + $path = $view->getPath($fileId); + + if (!is_file($filename) || !$view->is_file($path)) { + return array( + 'status' => 'error', + 'message' => (string) $this->l10n->t('Unable to copy the document back from CloudSuite.') + ); + } + + $content = file_get_contents($filename); + + $view->file_put_contents($path, $content); + + return array( + 'status' => 'success' + ); + } + /** * @NoAdminRequired * @PublicPage diff --git a/js/documents.js b/js/documents.js index c5e0a8d0..8b9f6b2f 100644 --- a/js/documents.js +++ b/js/documents.js @@ -308,7 +308,7 @@ var documentsMain = { $(documentsMain.toolbar).appendTo('#header'); if (!response || !response.status || response.status==='error'){ - documentsMain.onEditorShutdown(t('documents', 'Failed to load this document. Please check if it can be opened with an external odt editor. This might also mean it has been unshared or deleted recently.')); + documentsMain.onEditorShutdown(t('documents', 'Failed to load this document. Please check if it can be opened with an external editor. This might also mean it has been unshared or deleted recently.')); return; } @@ -484,7 +484,7 @@ var documentsMain = { if (result.message){ documentsMain.IU.notify(result.message); } - documentsMain.onEditorShutdown(t('documents', 'Failed to load this document. Please check if it can be opened with an external odt editor. This might also mean it has been unshared or deleted recently.')); + documentsMain.onEditorShutdown(t('documents', 'Failed to load this document. Please check if it can be opened with an external editor. This might also mean it has been unshared or deleted recently.')); return; } @@ -496,6 +496,23 @@ var documentsMain = { ); }, + saveDocumentBack: function() { + var url = OC.generateUrl('apps/documents/save/{file_id}', {file_id: documentsMain.fileId}); + $.post( + url, + { basename : documentsMain.baseName }, + function(result) { + if (result && result.status === 'error') { + if (result.message){ + documentsMain.IU.notify(result.message); + } + documentsMain.onEditorShutdown(t('documents', 'Failed to save this document. Please check if it can be saved with an external editor. This might also mean it has been unshared or deleted recently.')); + return; + } + } + ); + }, + renameDocument: function(name) { var url = OC.generateUrl('apps/documents/ajax/documents/rename/{file_id}', {file_id: documentsMain.fileId}); $.post(