diff options
author | Pranav Kant <pranavk@collabora.co.uk> | 2016-10-13 09:58:54 +0300 |
---|---|---|
committer | Pranav Kant <pranavk@collabora.co.uk> | 2016-10-13 12:11:49 +0300 |
commit | 145854400e3e82c6a04d68e58e9661de7e3cace2 (patch) | |
tree | 8bd682b909aa683fee063c33fca539b7f5bc943c /js | |
parent | f2e6c36060a2fdf2689c38cbda55c8ae99692cf0 (diff) |
New 'Use OOXML by default' option in admin settings
Diffstat (limited to 'js')
-rw-r--r-- | js/admin.js | 12 | ||||
-rw-r--r-- | js/documents.js | 28 | ||||
-rw-r--r-- | js/viewer/viewer.js | 148 |
3 files changed, 123 insertions, 65 deletions
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); |