diff --git a/ajax/sessionController.php b/ajax/sessionController.php index ca021d4d..008f1a97 100644 --- a/ajax/sessionController.php +++ b/ajax/sessionController.php @@ -26,7 +26,17 @@ class SessionController extends Controller{ $uid = self::preDispatch(); $fileId = intval(@$args['file_id']); $file = new File($fileId); - self::join($uid, $file); + + if ($file->getPermissions() & \OCP\PERMISSION_UPDATE) { + self::join($uid, $file); + } else { + \OCP\JSON::success(array( + 'permissions' => $file->getPermissions(), + 'id' => $fileId + )); + } + + exit(); } protected static function join($uid, $file){ diff --git a/js/documents.js b/js/documents.js index 60ad9bfa..decb3ff4 100644 --- a/js/documents.js +++ b/js/documents.js @@ -162,10 +162,15 @@ var documentsMain = { initSession: function(response) { "use strict"; - if (!response || !response.es_id || !response.status || response.status==='error'){ + if(response && (response.id && !response.es_id)){ + return documentsMain.view(response.id); + } + + if (!response || !response.status || response.status==='error'){ OC.Notification.show(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.prepareGrid(); documentsMain.show(); + $(window).off('beforeunload'); setTimeout(OC.Notification.hide, 7000); return; } @@ -220,6 +225,16 @@ var documentsMain = { documentsMain.initSession ); }, + + view : function(id){ + OC.addScript('documents', 'viewer/viewer', function() { + documentsMain.prepareGrid(); + $(window).off('beforeunload'); + var path = $('li[data-id='+ id +']>a').attr('href'); + odfViewer.isDocuments = true; + odfViewer.onView(path); + }); + }, onCreate: function(event){ event.preventDefault(); diff --git a/js/viewer/viewer.js b/js/viewer/viewer.js index b6d9a3b3..088bafa1 100644 --- a/js/viewer/viewer.js +++ b/js/viewer/viewer.js @@ -1,4 +1,5 @@ var odfViewer = { + isDocuments : false, supportedMimesRead: [ 'application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.spreadsheet', @@ -44,14 +45,22 @@ var odfViewer = { }, onView: function(filename) { - OC.addStyle('documents', 'viewer/webodf'); - OC.addStyle('documents', 'viewer/odfviewer'); + var webodfSource = (oc_debug === true) ? 'webodf-debug' : 'webodf', + attachTo = odfViewer.isDocuments ? '#documents-content' : 'table', + attachToolbarTo = odfViewer.isDocuments ? '#content-wrapper' : '#controls'; + + if (odfViewer.isDocuments){ + //Documents view + var location = filename; + } else { + //Public page, files app, etc + var location = fileDownloadPath($('#dir').val(), filename); + OC.addStyle('documents', 'viewer/webodf'); + } - var webodfSource = (oc_debug === true) ? 'webodf-debug' : 'webodf'; + OC.addStyle('documents', 'viewer/odfviewer'); OC.addScript('documents', '3rdparty/webodf/' + webodfSource, function() { - var location = fileDownloadPath($('#dir').val(), filename); - // fade out files menu and add odf menu $('#controls div').fadeOut('slow').promise().done(function() { // odf action toolbar @@ -59,14 +68,18 @@ var odfViewer = { '