cloudsuite: Implement the saving back.

pull/1/head
Jan Holesovsky 9 years ago
parent 00befededb
commit aa0a8f666a

@ -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'],

@ -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

@ -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(

Loading…
Cancel
Save