Open readonly shares with viewer. Ref #62
This commit is contained in:
parent
d406168c59
commit
19a1b51a0e
@ -26,7 +26,17 @@ class SessionController extends Controller{
|
||||
$uid = self::preDispatch();
|
||||
$fileId = intval(@$args['file_id']);
|
||||
$file = new File($fileId);
|
||||
|
||||
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){
|
||||
|
@ -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;
|
||||
}
|
||||
@ -221,6 +226,16 @@ var documentsMain = {
|
||||
);
|
||||
},
|
||||
|
||||
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();
|
||||
var docElem = $('.documentslist .template').clone();
|
||||
|
@ -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) {
|
||||
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');
|
||||
}
|
||||
|
||||
OC.addStyle('documents', 'viewer/odfviewer');
|
||||
|
||||
var webodfSource = (oc_debug === true) ? 'webodf-debug' : 'webodf';
|
||||
|
||||
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 = {
|
||||
'<div id="odf-toolbar">' +
|
||||
'<button id="odf_close">' + t('documents', 'Close') +
|
||||
'</button></div>';
|
||||
$('#controls').append(odfToolbarHtml);
|
||||
|
||||
if (odfViewer.isDocuments){
|
||||
$(attachToolbarTo).prepend(odfToolbarHtml);
|
||||
$('#odf-toolbar').css({position:'fixed'});
|
||||
} else {
|
||||
$(attachToolbarTo).append(odfToolbarHtml);
|
||||
}
|
||||
});
|
||||
|
||||
// fade out file list and show pdf canvas
|
||||
$('table').fadeOut('slow').promise().done(function() {
|
||||
$('table, #documents-content').fadeOut('slow').promise().done(function() {
|
||||
var canvashtml = '<div id="odf-canvas"></div>';
|
||||
$('table').after(canvashtml);
|
||||
$(attachTo).after(canvashtml);
|
||||
// in case we are on the public sharing page we shall display the odf into the preview tag
|
||||
$('#preview').html(canvashtml);
|
||||
|
||||
@ -85,7 +98,7 @@ var odfViewer = {
|
||||
$('#odf-toolbar').remove();
|
||||
$('#odf-canvas').remove();
|
||||
$('#controls div').not('.hidden').fadeIn('slow');
|
||||
$('table').fadeIn('slow');
|
||||
$('table, #documents-content').fadeIn('slow');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
21
lib/file.php
21
lib/file.php
@ -130,6 +130,27 @@ class File {
|
||||
$this->passwordProtected = $value;
|
||||
}
|
||||
|
||||
public function getPermissions(){
|
||||
if (count($this->sharing)){
|
||||
if ($this->isPublicShare()){
|
||||
$permissions = \OCP\PERMISSION_READ | \OCP\PERMISSION_UPDATE;
|
||||
} else {
|
||||
$permissions = $this->sharing[0]['permissions'];
|
||||
}
|
||||
} else {
|
||||
list($owner, $path) = $this->getOwnerViewAndPath();
|
||||
$permissions = 0;
|
||||
if (\OC\Files\Filesystem::isReadable($path)){
|
||||
$permissions |= \OCP\PERMISSION_READ;
|
||||
}
|
||||
if (\OC\Files\Filesystem::isUpdatable($path)){
|
||||
$permissions |= \OCP\PERMISSION_UPDATE;
|
||||
}
|
||||
|
||||
}
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string owner of the current file item
|
||||
|
Loading…
x
Reference in New Issue
Block a user