diff --git a/appinfo/app.php b/appinfo/app.php index 1f73ccfc..674f286d 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -49,6 +49,7 @@ if (isset($request->server['REQUEST_URI'])) { if (preg_match('%index.php/apps/files(/.*)?%', $url)) { \OCP\Util::addScript('richdocuments', 'viewer/viewer'); + \OCP\Util::addStyle('richdocuments', 'viewer/odfviewer'); } } diff --git a/controller/documentcontroller.php b/controller/documentcontroller.php index c92d8469..e42656bb 100644 --- a/controller/documentcontroller.php +++ b/controller/documentcontroller.php @@ -255,11 +255,15 @@ class DocumentController extends Controller { */ public function create(){ $mimetype = $this->request->post['mimetype']; + $filename = $this->request->post['filename']; + $dir = $this->request->post['dir']; $view = new View('/' . $this->uid . '/files'); - $dir = $this->settings->getUserValue($this->uid, $this->appName, 'save_path', '/'); - if (!$view->is_dir($dir)){ - $dir = '/'; + if (!$dir){ + $dir = $this->settings->getUserValue($this->uid, $this->appName, 'save_path', '/'); + if (!$view->is_dir($dir)){ + $dir = '/'; + } } $basename = $this->l10n->t('New Document.odt'); @@ -276,7 +280,11 @@ class DocumentController extends Controller { break; } - $path = Helper::getNewFileName($view, $dir . '/' . $basename); + if (!$filename){ + $path = Helper::getNewFileName($view, $dir . '/' . $basename); + } else { + $path = $dir . '/' . $filename; + } $content = ''; if (class_exists('\OC\Files\Type\TemplateManager')){ @@ -321,7 +329,8 @@ class DocumentController extends Controller { 'status' => 'success', 'fileid' => $info['fileid'], 'urlsrc' => $this->getWopiSrcUrl($discovery_parsed, $mimetype, 'edit'), - 'lolang' => $this->settings->getUserValue($this->uid, 'core', 'lang', 'en') + 'lolang' => $this->settings->getUserValue($this->uid, 'core', 'lang', 'en'), + 'data' => \OCA\Files\Helper::formatFileInfo($info) ); } else { $response = array( diff --git a/css/viewer/odfviewer.css b/css/viewer/odfviewer.css index ed5f570d..4bc302df 100644 --- a/css/viewer/odfviewer.css +++ b/css/viewer/odfviewer.css @@ -8,3 +8,15 @@ -moz-box-shadow: 0px 4px 10px #000; -webkit-box-shadow: 0px 4px 10px #000; } + +.icon-filetype-document{ + background-image: url('../../../../core/img/filetypes/x-office-document.svg') +} + +.icon-filetype-spreadsheet{ + background-image: url('../../../../core/img/filetypes/x-office-spreadsheet.svg'); +} + +.icon-filetype-presentation{ + background-image: url('../../../../core/img/filetypes/x-office-presentation.svg'); +} \ No newline at end of file diff --git a/js/viewer/viewer.js b/js/viewer/viewer.js index 0c782d64..b8e6f2c0 100644 --- a/js/viewer/viewer.js +++ b/js/viewer/viewer.js @@ -113,3 +113,63 @@ $(document).ready(function() { $('#odf_close').live('click', odfViewer.onClose); }); + +(function(OCA){ + OCA.FilesLOMenu = { + attach: function(newFileMenu) { + var self = this; + + newFileMenu.addMenuEntry({ + id: 'add-odt', + displayName: 'Document', + templateName: 'New Document.odt', + iconClass: 'icon-filetype-document', + fileType: 'x-office-document', + actionHandler: function(filename) { + self._createDocument('application/vnd.oasis.opendocument.text', filename); + } + }); + + newFileMenu.addMenuEntry({ + id: 'add-ods', + displayName: 'Spreadsheet', + templateName: 'New Spreadsheet.ods', + iconClass: 'icon-filetype-spreadsheet', + fileType: 'x-office-spreadsheet', + actionHandler: function(filename) { + self._createDocument('application/vnd.oasis.opendocument.spreadsheet', filename); + } + }); + + newFileMenu.addMenuEntry({ + id: 'add-odp', + displayName: 'Presentation', + templateName: 'New Presentation.odp', + iconClass: 'icon-filetype-presentation', + fileType: 'x-office-presentation', + actionHandler: function(filename) { + self._createDocument('application/vnd.oasis.opendocument.presentation', filename); + } + }); + }, + + _createDocument: function(mimetype, filename) { + OCA.Files.Files.isFileNameValid(filename); + filename = FileList.getUniqueName(filename); + + $.post( + OC.generateUrl('apps/richdocuments/ajax/documents/create'), + { mimetype : mimetype, filename: filename, dir: $('#dir').val() }, + function(response){ + if (response && response.status === 'success'){ + FileList.add(response.data, {animate: true, scrollTo: true}); + } else { + OC.dialogs.alert(response.data.message, t('core', 'Could not create file')); + } + } + ); + } + }; +})(OCA); + +OC.Plugins.register('OCA.Files.NewFileMenu', OCA.FilesLOMenu);