diff --git a/appinfo/app.php b/appinfo/app.php index b057f763..d7845a3a 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -51,5 +51,13 @@ $eventDispatcher->addListener( } ); +if (class_exists('\OC\Files\Type\TemplateManager')) { + $manager = \OC_Helper::getFileTemplateManager(); + + $manager->registerTemplate('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'apps/richdocuments/assets/docxtemplate.docx'); + $manager->registerTemplate('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'apps/richdocuments/assets/xlsxtemplate.xlsx'); + $manager->registerTemplate('application/vnd.openxmlformats-officedocument.presentationml.presentation', 'apps/richdocuments/assets/pptxtemplate.pptx'); +} + //Listen to delete file signal \OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA\Richdocuments\Storage", "onDelete"); diff --git a/appinfo/routes.php b/appinfo/routes.php index 3b5d539c..37d996ab 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -41,5 +41,6 @@ $application->registerRoutes($this, [ //settings ['name' => 'settings#setSettings', 'url' => 'ajax/admin.php', 'verb' => 'POST'], ['name' => 'settings#getSupportedMimes', 'url' => 'ajax/mimes.php', 'verb' => 'GET'], + ['name' => 'settings#getSettings', 'url' => 'ajax/settings.php', 'verb' => 'GET'], ] ]); diff --git a/assets/docxtemplate.docx b/assets/docxtemplate.docx new file mode 100644 index 00000000..900c5276 Binary files /dev/null and b/assets/docxtemplate.docx differ diff --git a/assets/odttemplate.odt b/assets/odttemplate.odt index fdab6778..34c424eb 100644 Binary files a/assets/odttemplate.odt and b/assets/odttemplate.odt differ diff --git a/assets/pptxtemplate.pptx b/assets/pptxtemplate.pptx new file mode 100644 index 00000000..49c772e9 Binary files /dev/null and b/assets/pptxtemplate.pptx differ diff --git a/assets/xlsxtemplate.xlsx b/assets/xlsxtemplate.xlsx new file mode 100644 index 00000000..7dbe3992 Binary files /dev/null and b/assets/xlsxtemplate.xlsx differ diff --git a/controller/documentcontroller.php b/controller/documentcontroller.php index f4303475..20045d28 100644 --- a/controller/documentcontroller.php +++ b/controller/documentcontroller.php @@ -270,7 +270,8 @@ class DocumentController extends Controller { 'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize), 'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'), 'wopi_url' => $webSocket, - 'edit_groups' => $this->appConfig->getAppValue('edit_groups') + 'edit_groups' => $this->appConfig->getAppValue('edit_groups'), + 'doc_format' => $this->appConfig->getAppValue('doc_format') ]); $policy = new ContentSecurityPolicy(); @@ -308,6 +309,15 @@ class DocumentController extends Controller { case 'application/vnd.oasis.opendocument.presentation': $basename = $this->l10n->t('New Presentation.odp'); break; + case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': + $basename = $this->l10n->t('New Document.docx'); + break; + case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': + $basename = $this->l10n->t('New Spreadsheet.xlsx'); + break; + case 'application/vnd.openxmlformats-officedocument.presentationml.presentation': + $basename = $this->l10n->t('New Presentation.pptx'); + break; default: // to be safe $mimetype = 'application/vnd.oasis.opendocument.text'; diff --git a/controller/settingscontroller.php b/controller/settingscontroller.php index 8bf3289b..945b021b 100644 --- a/controller/settingscontroller.php +++ b/controller/settingscontroller.php @@ -43,6 +43,16 @@ class SettingsController extends Controller{ ); } + /** + * @NoAdminRequired + */ + public function getSettings() { + return array( + 'doc_format' => $this->appConfig->getAppValue('doc_format'), + 'wopi_url' => $this->appConfig->getAppValue('wopi_url') + ); + } + /** * @NoCSRFRequired */ @@ -63,13 +73,14 @@ class SettingsController extends Controller{ 'admin', [ 'wopi_url' => $this->appConfig->getAppValue('wopi_url'), - 'edit_groups' => $this->appConfig->getAppValue('edit_groups') + 'edit_groups' => $this->appConfig->getAppValue('edit_groups'), + 'doc_format' => $this->appConfig->getAppValue('doc_format') ], 'blank' ); } - public function setSettings($wopi_url, $edit_groups){ + public function setSettings($wopi_url, $edit_groups, $doc_format){ if (!is_null($wopi_url)){ $this->appConfig->setAppValue('wopi_url', $wopi_url); } @@ -78,6 +89,10 @@ class SettingsController extends Controller{ $this->appConfig->setAppValue('edit_groups', $edit_groups); } + if (!is_null($doc_format)){ + $this->appConfig->setAppValue('doc_format', $doc_format); + } + $richMemCache = \OC::$server->getMemCacheFactory()->create('richdocuments'); $richMemCache->clear('discovery.xml'); diff --git a/js/admin.js b/js/admin.js index 7a27eda0..223b1173 100644 --- a/js/admin.js +++ b/js/admin.js @@ -26,6 +26,13 @@ var documentsSettings = { ); }, + saveDocFormat: function(format) { + $.post( + OC.filePath('richdocuments', 'ajax', 'admin.php'), + { 'doc_format': format } + ); + }, + afterSave : function(response){ $('#wopi_apply').attr('disabled', false); OC.msg.finishedAction('#documents-admin-msg', response); @@ -45,6 +52,11 @@ var documentsSettings = { $('#wopi_apply').on('click', documentsSettings.save); documentsSettings.initEditGroups(); + $(document).on('change', '.doc-format-ooxml', function() { + var ooxml = this.checked; + documentsSettings.saveDocFormat(ooxml ? 'ooxml' : 'odf'); + }); + $(document).on('change', '#edit_group_select', function() { var element = $(this).parent().find('input.edit-groups-enable'); var groups = $(this).val(); diff --git a/js/documents.js b/js/documents.js index 7179389c..809c2b0b 100644 --- a/js/documents.js +++ b/js/documents.js @@ -712,6 +712,21 @@ var documentsMain = { documentsMain.create('application/vnd.oasis.opendocument.presentation'); }, + onCreateDOCX: function(event){ + event.preventDefault(); + documentsMain.create('application/vnd.openxmlformats-officedocument.wordprocessingml.document'); + }, + + onCreateXLSX: function(event){ + event.preventDefault(); + documentsMain.create('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + }, + + onCreatePPTX: function(event){ + event.preventDefault(); + documentsMain.create('application/vnd.openxmlformats-officedocument.presentationml.presentation'); + }, + create: function(mimetype){ var docElem = $('.documentslist .template').clone(); docElem.removeClass('template'); @@ -970,7 +985,7 @@ FileList.generatePreviewUrl = function(urlSpec) { urlSpec.y = Math.ceil(urlSpec.y); urlSpec.forceIcon = 0; return OC.generateUrl('/core/preview.png?') + $.param(urlSpec); -} +}; FileList.isFileNameValid = function (name) { var trimmedName = name.trim(); @@ -980,14 +995,14 @@ FileList.isFileNameValid = function (name) { throw t('files', 'File name cannot be empty.'); } return true; -} +}; FileList.setViewerMode = function(){ }; FileList.findFile = function(fileName){ fullPath = escapeHTML(FileList.getCurrentDirectory + '/' + fileName); - return !!$('.documentslist .document:not(.template,.progress) a[original-title="' + fullPath + '"]').length -} + return !!$('.documentslist .document:not(.template,.progress) a[original-title="' + fullPath + '"]').length; +}; $(document).ready(function() { @@ -1030,10 +1045,13 @@ $(document).ready(function() { $('.add-document').on('click', '.add-odt', documentsMain.onCreateODT); $('.add-document').on('click', '.add-ods', documentsMain.onCreateODS); $('.add-document').on('click', '.add-odp', documentsMain.onCreateODP); + $('.add-document').on('click', '.add-docx', documentsMain.onCreateDOCX); + $('.add-document').on('click', '.add-xlsx', documentsMain.onCreateXLSX); + $('.add-document').on('click', '.add-pptx', documentsMain.onCreatePPTX); OC.Upload._isReceivedSharedFile = function () { return false; - } + }; var file_upload_start = $('#file_upload_start'); if (typeof supportAjaxUploadWithProgress !== 'undefined' && supportAjaxUploadWithProgress()) { diff --git a/js/viewer/viewer.js b/js/viewer/viewer.js index 27318ca7..9ec81bd6 100644 --- a/js/viewer/viewer.js +++ b/js/viewer/viewer.js @@ -96,6 +96,88 @@ var odfViewer = { onClose: function() { FileList.setViewerMode(false); $('#loleafletframe').remove(); + }, + + registerFilesMenu: function(response) { + var ooxml = response.doc_format === 'ooxml'; + + var docExt, spreadsheetExt, presentationExt; + var docMime, spreadsheetMime, presentationMime; + if (ooxml) { + docExt = 'docx'; + spreadsheetExt = 'xlsx'; + presentationExt = 'pptx'; + docMime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; + spreadsheetMime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + presentationMime = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; + } else { + docExt = 'odt'; + spreadsheetExt = 'ods'; + presentationExt = 'odp'; + docMime = 'application/vnd.oasis.opendocument.text'; + spreadsheetMime = 'application/vnd.oasis.opendocument.spreadsheet'; + presentationMime = 'application/vnd.oasis.opendocument.presentation'; + } + + (function(OCA){ + OCA.FilesLOMenu = { + attach: function(newFileMenu) { + var self = this; + + newFileMenu.addMenuEntry({ + id: 'add-' + docExt, + displayName: t('richdocuments', 'Document'), + templateName: 'New Document.' + docExt, + iconClass: 'icon-filetype-document', + fileType: 'x-office-document', + actionHandler: function(filename) { + self._createDocument(docMime, filename); + } + }); + + newFileMenu.addMenuEntry({ + id: 'add-' + spreadsheetExt, + displayName: t('richdocuments', 'Spreadsheet'), + templateName: 'New Spreadsheet.' + spreadsheetExt, + iconClass: 'icon-filetype-spreadsheet', + fileType: 'x-office-spreadsheet', + actionHandler: function(filename) { + self._createDocument(spreadsheetMime, filename); + } + }); + + newFileMenu.addMenuEntry({ + id: 'add-' + presentationExt, + displayName: t('richdocuments', 'Presentation'), + templateName: 'New Presentation.' + presentationExt, + iconClass: 'icon-filetype-presentation', + fileType: 'x-office-presentation', + actionHandler: function(filename) { + self._createDocument(presentationMime, 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); } }; @@ -109,67 +191,13 @@ $(document).ready(function() { {}, odfViewer.register ); + + $.get( + OC.filePath('richdocuments', 'ajax', 'settings.php'), + {}, + odfViewer.registerFilesMenu + ); } $('#odf_close').live('click', odfViewer.onClose); }); - -(function(OCA){ - OCA.FilesLOMenu = { - attach: function(newFileMenu) { - var self = this; - - newFileMenu.addMenuEntry({ - id: 'add-odt', - displayName: t('richdocuments', '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: t('richdocuments', '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: t('richdocuments', '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); diff --git a/templates/admin.php b/templates/admin.php index 7a82d418..412c47d6 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -11,6 +11,8 @@ script('richdocuments', 'admin');
-
+
+ data-appid="richdocuments" /> + diff --git a/templates/documents.php b/templates/documents.php index 75594590..898e2219 100644 --- a/templates/documents.php +++ b/templates/documents.php @@ -9,13 +9,13 @@ script('files', 'jquery.fileupload');