diff --git a/www/common/fileObject.js b/www/common/fileObject.js index e822b9bd8..85f278827 100644 --- a/www/common/fileObject.js +++ b/www/common/fileObject.js @@ -81,6 +81,16 @@ define([ return typeof(element) === "string"; }; + var isReadOnlyFile = exp.isReadOnlyFile = function (element) { + if (!isFile(element)) { return false; } + var parsed = Cryptpad.parsePadUrl(element); + if (!parsed) { return false; } + var hash = parsed.hash; + var pHash = Cryptpad.parseHash(hash); + if (pHash && !pHash.mode) { return; } + return pHash && pHash.mode === 'view'; + }; + var isFolder = exp.isFolder = function (element) { return typeof(element) !== "string"; }; diff --git a/www/drive/main.js b/www/drive/main.js index 373ee39c1..03c76a427 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -375,6 +375,13 @@ define([ if ($element.is('.file-element')) { // No folder in files hide.push($menu.find('a.newfolder')); + if ($element.is('.readonly')) { + // Keep only open readonly + hide.push($menu.find('a.open')); + } else if ($element.is('.noreadonly')) { + // Keep only open readonly + hide.push($menu.find('a.open_ro')); + } } else { if (hasFolder) { // More than 1 folder selected: cannot create a new subfolder @@ -858,7 +865,10 @@ define([ var element = filesOp.findElement(files, newPath); var $icon = !isFolder ? getFileIcon(element) : undefined; - var liClass = 'file-item file-element element'; + var ro = filesOp.isReadOnlyFile(element); + // ro undefined mens it's an old hash which doesn't support read-only + var roClass = typeof(ro) === 'undefined' ? ' noreadonly' : ro ? ' readonly' : ''; + var liClass = 'file-item file-element element' + roClass; if (isFolder) { liClass = 'folder-item folder-element element'; $icon = filesOp.isFolderEmpty(root[key]) ? $folderEmptyIcon.clone() : $folderIcon.clone(); @@ -1337,8 +1347,12 @@ define([ } var idx = files[rootName].indexOf(href); var $icon = getFileIcon(href); + var ro = filesOp.isReadOnlyFile(href); + console.log(ro); + // ro undefined mens it's an old hash which doesn't support read-only + var roClass = typeof(ro) === 'undefined' ? ' noreadonly' : ro ? ' readonly' : ''; var $element = $('