2017-08-24 23:54:02 +02:00
|
|
|
const html = require('choo/html');
|
2018-02-11 23:02:40 +01:00
|
|
|
const raw = require('choo/html/raw');
|
2018-02-13 20:32:59 +01:00
|
|
|
const assets = require('../../../common/assets');
|
|
|
|
const notFound = require('../notFound');
|
|
|
|
const deletePopup = require('../../templates/popup');
|
2018-08-03 21:24:41 +02:00
|
|
|
const uploadedFileList = require('../../templates/uploadedFileList');
|
2018-08-08 20:07:09 +02:00
|
|
|
const timeLimitText = require('../../templates/timeLimitText');
|
2018-02-13 20:32:59 +01:00
|
|
|
const { allowedCopy, delay, fadeOut } = require('../../utils');
|
2017-08-24 23:54:02 +02:00
|
|
|
|
|
|
|
module.exports = function(state, emit) {
|
|
|
|
const file = state.storage.getFileById(state.params.id);
|
|
|
|
if (!file) {
|
2018-07-31 20:09:18 +02:00
|
|
|
return notFound(state);
|
2017-08-24 23:54:02 +02:00
|
|
|
}
|
2017-10-25 21:48:01 +02:00
|
|
|
|
2018-07-31 20:09:18 +02:00
|
|
|
const passwordReminderClass = file._hasPassword
|
|
|
|
? ''
|
|
|
|
: 'passwordReminder--hidden';
|
|
|
|
|
2018-02-16 21:56:53 +01:00
|
|
|
return html`
|
2018-07-31 20:09:18 +02:00
|
|
|
<div class="page effect--fadeIn" id="shareWrapper">
|
|
|
|
<a href="/" class="goBackButton">
|
|
|
|
<img src="${assets.get('back-arrow.svg')}"/>
|
|
|
|
</a>
|
|
|
|
${expireInfo(file, state.translate)}
|
|
|
|
|
2018-08-03 21:24:41 +02:00
|
|
|
${uploadedFileList(file, state, emit)}
|
2018-07-31 20:09:18 +02:00
|
|
|
|
2018-02-13 20:32:59 +01:00
|
|
|
<div class="sharePage__copyText">
|
2018-08-03 21:24:41 +02:00
|
|
|
${state.translate('copyUrlLabel')}
|
2018-07-31 20:09:18 +02:00
|
|
|
<div class="sharePage__passwordReminder ${passwordReminderClass}">(don't forget the password too)</div>
|
2018-01-24 19:23:13 +01:00
|
|
|
</div>
|
2018-07-31 20:09:18 +02:00
|
|
|
|
|
|
|
<input
|
|
|
|
id="fileUrl"
|
|
|
|
class="copySection__url"
|
|
|
|
type="url"
|
|
|
|
value="${file.url}"
|
|
|
|
readonly="true"/>
|
|
|
|
|
|
|
|
<button id="copyBtn"
|
|
|
|
class="btn copyBtn"
|
|
|
|
title="${state.translate('copyUrlFormButton')}"
|
|
|
|
onclick=${copyLink}>${state.translate('copyUrlFormButton')}
|
2018-01-09 16:26:27 +01:00
|
|
|
</button>
|
2018-07-31 20:09:18 +02:00
|
|
|
|
2018-02-13 20:32:59 +01:00
|
|
|
<div class="sharePage__deletePopup">
|
|
|
|
${deletePopup(
|
|
|
|
state.translate('deletePopupText'),
|
|
|
|
state.translate('deletePopupYes'),
|
|
|
|
state.translate('deletePopupCancel'),
|
|
|
|
deleteFile
|
|
|
|
)}
|
2018-01-09 16:26:27 +01:00
|
|
|
</div>
|
2018-07-31 20:09:18 +02:00
|
|
|
|
2018-08-01 00:19:18 +02:00
|
|
|
<button
|
|
|
|
class="btn--cancel btn--delete"
|
2018-07-31 20:09:18 +02:00
|
|
|
title="${state.translate('deleteFileButton')}"
|
2018-08-03 21:24:41 +02:00
|
|
|
onclick=${showDeletePopup}>${state.translate('deleteFileButton')}
|
2018-08-01 00:19:18 +02:00
|
|
|
</button>
|
2018-07-31 20:09:18 +02:00
|
|
|
|
2017-08-24 23:54:02 +02:00
|
|
|
</div>
|
2018-07-31 20:09:18 +02:00
|
|
|
|
2017-08-24 23:54:02 +02:00
|
|
|
`;
|
|
|
|
|
2018-08-03 21:24:41 +02:00
|
|
|
function showDeletePopup() {
|
2018-02-13 20:32:59 +01:00
|
|
|
const popup = document.querySelector('.popup');
|
|
|
|
popup.classList.add('popup--show');
|
|
|
|
popup.focus();
|
2017-12-23 04:20:19 +01:00
|
|
|
}
|
|
|
|
|
2017-08-24 23:54:02 +02:00
|
|
|
async function copyLink() {
|
|
|
|
if (allowedCopy()) {
|
|
|
|
emit('copy', { url: file.url, location: 'success-screen' });
|
2018-02-13 20:32:59 +01:00
|
|
|
const input = document.getElementById('fileUrl');
|
2017-08-29 20:25:41 +02:00
|
|
|
input.disabled = true;
|
2018-02-13 20:32:59 +01:00
|
|
|
const copyBtn = document.getElementById('copyBtn');
|
2017-08-24 23:54:02 +02:00
|
|
|
copyBtn.disabled = true;
|
2018-07-31 20:09:18 +02:00
|
|
|
copyBtn.classList.add('copyBtn--copied');
|
2017-08-24 23:54:02 +02:00
|
|
|
copyBtn.replaceChild(
|
2018-07-31 20:09:18 +02:00
|
|
|
html`<label>${state.translate('copiedUrl')}</label>`,
|
2017-08-24 23:54:02 +02:00
|
|
|
copyBtn.firstChild
|
|
|
|
);
|
|
|
|
await delay(2000);
|
2017-08-29 20:25:41 +02:00
|
|
|
input.disabled = false;
|
2018-02-13 20:32:59 +01:00
|
|
|
copyBtn.disabled = false;
|
2018-07-31 20:09:18 +02:00
|
|
|
copyBtn.classList.remove('copyBtn--copied');
|
2017-08-24 23:54:02 +02:00
|
|
|
copyBtn.textContent = state.translate('copyUrlFormButton');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function deleteFile() {
|
|
|
|
emit('delete', { file, location: 'success-screen' });
|
2018-02-13 20:32:59 +01:00
|
|
|
await fadeOut('#shareWrapper');
|
2017-08-24 23:54:02 +02:00
|
|
|
emit('pushState', '/');
|
|
|
|
}
|
|
|
|
};
|
2018-02-16 21:56:53 +01:00
|
|
|
|
2018-07-31 20:09:18 +02:00
|
|
|
function expireInfo(file, translate) {
|
2018-08-08 20:07:09 +02:00
|
|
|
const el = html`<div class="shareTitle">
|
|
|
|
${raw(
|
|
|
|
translate('expireInfo', {
|
|
|
|
downloadCount: translate('downloadCount', { num: file.dlimit }),
|
|
|
|
timespan: timeLimitText(translate, file.timeLimit)
|
|
|
|
})
|
|
|
|
)}
|
|
|
|
</div>`;
|
2018-07-31 20:09:18 +02:00
|
|
|
|
2018-02-16 21:56:53 +01:00
|
|
|
return el;
|
|
|
|
}
|