From ad8c16343653f2dab5b33d2824c2a14ee477cd40 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Tue, 1 Oct 2013 19:34:08 +0300 Subject: [PATCH] Default documents dir for upload. Ref #49 --- ajax/documentController.php | 4 +++- ajax/personal.php | 38 +++++++++++++++++++++++++++++++++++++ appinfo/app.php | 3 +-- index.php | 4 ++++ js/personal.js | 15 +++++++++++++++ personal.php | 21 ++++++++++++++++++++ templates/documents.php | 2 +- templates/personal.php | 7 +++++++ 8 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 ajax/personal.php create mode 100644 js/personal.js create mode 100644 personal.php create mode 100644 templates/personal.php diff --git a/ajax/documentController.php b/ajax/documentController.php index 1043a372..0d479c4b 100644 --- a/ajax/documentController.php +++ b/ajax/documentController.php @@ -19,7 +19,9 @@ class DocumentController extends Controller{ $uid = self::preDispatch(); $view = new \OC\Files\View('/' . $uid . '/files'); - $path = Helper::getNewFileName($view, '/New Document.odt'); + + $dir = \OCP\Config::getUserValue(\OCP\User::getUser(), 'documents', 'save_path', '/'); + $path = Helper::getNewFileName($view, $dir . '/New Document.odt'); $view->file_put_contents( $path, diff --git a/ajax/personal.php b/ajax/personal.php new file mode 100644 index 00000000..4d29f8cd --- /dev/null +++ b/ajax/personal.php @@ -0,0 +1,38 @@ + array('message'=>'') + ) + ); + } + } + \OCP\Config::setUserValue(\OCP\User::getUser(), 'documents', 'save_path', $savePath); + \OCP\JSON::success( + array( + 'data' => array('message'=>'') + ) + ); + exit(); +} + +exit(); \ No newline at end of file diff --git a/appinfo/app.php b/appinfo/app.php index 57e842e0..719b3a17 100755 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -21,10 +21,9 @@ * */ -//OCP\Util::addStyle( 'documents', 'style'); - OCP\App::register(array('order' => 70, 'id' => 'documents', 'name' => 'Documents')); OCP\App::registerAdmin('documents', 'settings'); +OCP\App::registerPersonal('documents', 'personal'); OCP\App::addNavigationEntry(array( 'id' => 'documents_index', diff --git a/index.php b/index.php index afd4477b..d85a57e4 100755 --- a/index.php +++ b/index.php @@ -39,8 +39,12 @@ namespace OCA\Documents; $tmpl = new \OCP\Template('documents', 'documents', 'user'); + $maxUploadFilesize = \OCP\Util::maxUploadFilesize("/"); +$savePath = \OCP\Config::getUserValue(\OCP\User::getUser(), 'documents', 'save_path', '/'); + $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); $tmpl->assign('uploadMaxHumanFilesize', \OCP\Util::humanFileSize($maxUploadFilesize)); +$tmpl->assign('savePath', $savePath); $tmpl->printPage(); diff --git a/js/personal.js b/js/personal.js new file mode 100644 index 00000000..00363b00 --- /dev/null +++ b/js/personal.js @@ -0,0 +1,15 @@ +$(document).ready(function(){ + var documentsSettings = { + save : function() { + var data = { + savePath : $('#documents-default-path').val() + }; + OC.msg.startSaving('#documents-personal .msg'); + $.post(OC.filePath('documents', 'ajax', 'personal.php'), data, documentsSettings.afterSave); + }, + afterSave : function(data){ + OC.msg.finishedSaving('#documents-personal .msg', data); + } + }; + $('#documents-default-path').blur(documentsSettings.save); +}); \ No newline at end of file diff --git a/personal.php b/personal.php new file mode 100644 index 00000000..80669767 --- /dev/null +++ b/personal.php @@ -0,0 +1,21 @@ +assign('savePath', $savePath); + +return $tmpl->fetchPage(); diff --git a/templates/documents.php b/templates/documents.php index 32b8f73b..f55a71d2 100755 --- a/templates/documents.php +++ b/templates/documents.php @@ -21,7 +21,7 @@ - + diff --git a/templates/personal.php b/templates/personal.php new file mode 100644 index 00000000..f7225292 --- /dev/null +++ b/templates/personal.php @@ -0,0 +1,7 @@ +
+ t('Documents')); ?> +
+ + +
+
\ No newline at end of file