From 9882a3a923a6a8cd51f65dfa37e2042b600af11d Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 25 Apr 2017 18:42:21 +0200 Subject: [PATCH] Add support for the file applicaiton in the drive --- customize.dist/translations/messages.fr.js | 1 + customize.dist/translations/messages.js | 1 + www/common/common-hash.js | 2 +- www/common/toolbar.js | 2 +- .../file/assets/image.png-encrypted | Bin www/{examples => }/file/index.html | 0 www/{examples => }/file/inner.html | 0 www/{examples => }/file/main.js | 40 +++++++++++++++++- 8 files changed, 43 insertions(+), 3 deletions(-) rename www/{examples => }/file/assets/image.png-encrypted (100%) rename www/{examples => }/file/index.html (100%) rename www/{examples => }/file/inner.html (100%) rename www/{examples => }/file/main.js (55%) diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index 97aec74ab..429e2f928 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -11,6 +11,7 @@ define(function () { out.type.slide = 'Présentation'; out.type.drive = 'Drive'; out.type.whiteboard = "Tableau Blanc"; + out.type.file = "Fichier"; out.button_newpad = 'Nouveau document texte'; out.button_newcode = 'Nouvelle page de code'; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index e27a074b5..678d3c4fb 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -11,6 +11,7 @@ define(function () { out.type.slide = 'Presentation'; out.type.drive = 'Drive'; out.type.whiteboard = 'Whiteboard'; + out.type.file = 'File'; out.button_newpad = 'New Rich Text pad'; out.button_newcode = 'New Code pad'; diff --git a/www/common/common-hash.js b/www/common/common-hash.js index 12f23c0a7..23f5f6a24 100644 --- a/www/common/common-hash.js +++ b/www/common/common-hash.js @@ -252,7 +252,7 @@ Version 2 if (parsed.version === 0) { return parsed.channel; - } else if (parsed.version !== 1) { + } else if (parsed.version !== 1 && parsed.version !== 2) { console.error("parsed href had no version"); console.error(parsed); return; diff --git a/www/common/toolbar.js b/www/common/toolbar.js index 9302441f0..4162e3dbf 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -791,7 +791,7 @@ define([ if (!connected) { return; } checkLag(getLag, lagElement); }, 3000); - } + } else { connected = true; } var failed = function () { connected = false; diff --git a/www/examples/file/assets/image.png-encrypted b/www/file/assets/image.png-encrypted similarity index 100% rename from www/examples/file/assets/image.png-encrypted rename to www/file/assets/image.png-encrypted diff --git a/www/examples/file/index.html b/www/file/index.html similarity index 100% rename from www/examples/file/index.html rename to www/file/index.html diff --git a/www/examples/file/inner.html b/www/file/inner.html similarity index 100% rename from www/examples/file/inner.html rename to www/file/inner.html diff --git a/www/examples/file/main.js b/www/file/main.js similarity index 55% rename from www/examples/file/main.js rename to www/file/main.js index 298d88904..b628edee9 100644 --- a/www/examples/file/main.js +++ b/www/file/main.js @@ -31,6 +31,37 @@ define([ // Test hash: // #/2/K6xWU-LT9BJHCQcDCT-DcQ/TBo77200c0e-FdldQFcnQx4Y/image-png + var parsed = Cryptpad.parsePadUrl(window.location.href); + var defaultName = Cryptpad.getDefaultName(parsed); + + var getTitle = function () { + var pad = Cryptpad.getRelativeHref(window.location.href); + var fo = Cryptpad.getStore().getProxy().fo; + var data = fo.getFileData(pad); + return data ? data.title : undefined; + }; + + var updateTitle = function (newTitle) { + Cryptpad.renamePad(newTitle, function (err, data) { + if (err) { + console.log("Couldn't set pad title"); + console.error(err); + return; + } + document.title = newTitle; + $bar.find('.' + Toolbar.constants.title).find('span.title').text(data); + $bar.find('.' + Toolbar.constants.title).find('input').val(data); + }); + }; + + var suggestName = function () { + return document.title || getTitle() || ''; + }; + + var renameCb = function (err, title) { + document.title = title; + }; + var $mt = $iframe.find('#encryptedFile'); $mt.attr('src', '/blob/' + hexFileName.slice(0,2) + '/' + hexFileName); $mt.attr('data-crypto-key', cryptKey); @@ -41,9 +72,16 @@ define([ var configTb = { displayed: ['useradmin', 'newpad'], ifrw: ifrw, - common: Cryptpad + common: Cryptpad, + title: { + onRename: renameCb, + defaultName: defaultName, + suggestName: suggestName + } }; Toolbar.create($bar, null, null, null, null, configTb); + + updateTitle(Cryptpad.initialName || getTitle() || defaultName); }); };