2017-08-24 21:54:02 +00:00
|
|
|
const html = require('choo/html');
|
2018-02-13 19:32:59 +00:00
|
|
|
const assets = require('../../../common/assets');
|
2018-07-31 18:09:18 +00:00
|
|
|
const title = require('../../templates/title');
|
|
|
|
const setPasswordSection = require('../../templates/setPasswordSection');
|
|
|
|
const uploadBox = require('../../templates/uploadedFileList');
|
|
|
|
const expireInfo = require('../../templates/expireInfo');
|
2017-08-24 21:54:02 +00:00
|
|
|
|
|
|
|
module.exports = function(state, emit) {
|
2018-02-13 19:32:59 +00:00
|
|
|
// the page flickers if both the server and browser set 'effect--fadeIn'
|
|
|
|
const fade = state.layout ? '' : 'effect--fadeIn';
|
2018-08-03 19:24:41 +00:00
|
|
|
|
|
|
|
const hasAnUpload = state.archive && state.archive.numFiles > 0;
|
2018-07-31 18:09:18 +00:00
|
|
|
|
|
|
|
const optionClass = state.uploading ? 'uploadOptions--faded' : '';
|
|
|
|
const btnUploading = state.uploading ? 'btn--stripes' : '';
|
2018-07-31 22:19:18 +00:00
|
|
|
const cancelVisible = state.uploading ? '' : 'noDisplay';
|
2018-08-03 19:24:41 +00:00
|
|
|
const faded = hasAnUpload ? 'uploadArea--faded' : '';
|
|
|
|
const selectFileClass = hasAnUpload > 0 ? 'btn--hidden' : '';
|
|
|
|
const sendFileClass = hasAnUpload > 0 ? '' : 'btn--hidden';
|
2018-07-31 18:09:18 +00:00
|
|
|
|
|
|
|
let btnText = '';
|
|
|
|
|
|
|
|
if (state.encrypting) {
|
|
|
|
btnText = state.translate('encryptingFile');
|
|
|
|
} else if (state.uploading) {
|
|
|
|
btnText = `sending... ${Math.floor(state.transfer.progressRatio * 100)}%`;
|
|
|
|
} else {
|
|
|
|
//default pre-upload text
|
|
|
|
btnText = state.translate('uploadSuccessConfirmHeader');
|
|
|
|
}
|
|
|
|
|
2018-02-16 20:56:53 +00:00
|
|
|
return html`
|
2018-07-31 18:09:18 +00:00
|
|
|
<div id="page-one" class="page ${fade}">
|
|
|
|
${title(state)}
|
|
|
|
|
|
|
|
<label class="uploadArea"
|
2018-08-08 18:07:09 +00:00
|
|
|
|
2017-08-31 16:43:36 +00:00
|
|
|
ondragover=${dragover}
|
|
|
|
ondragleave=${dragleave}>
|
2018-07-31 18:09:18 +00:00
|
|
|
|
2018-08-03 19:24:41 +00:00
|
|
|
${uploadBox(state.archive, state, emit)}
|
2018-07-31 18:09:18 +00:00
|
|
|
|
|
|
|
<div class="uploadedFilesWrapper ${faded}">
|
|
|
|
<img
|
|
|
|
class="uploadArea__icon"
|
|
|
|
src="${assets.get('addfile.svg')}"
|
|
|
|
title="${state.translate('uploadSvgAlt')}"/>
|
|
|
|
<div class="uploadArea__msg">
|
|
|
|
${state.translate('uploadDropDragMessage')}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<span class="uploadArea__clickMsg">
|
|
|
|
${state.translate('uploadDropClickMessage')}
|
|
|
|
</span>
|
2018-02-13 19:32:59 +00:00
|
|
|
</div>
|
2018-07-31 18:09:18 +00:00
|
|
|
|
2017-08-31 16:43:36 +00:00
|
|
|
<input id="file-upload"
|
2018-07-31 18:09:18 +00:00
|
|
|
class="inputFile fileBox"
|
2017-08-31 16:43:36 +00:00
|
|
|
type="file"
|
2018-07-26 05:26:11 +00:00
|
|
|
multiple
|
2017-08-31 16:43:36 +00:00
|
|
|
name="fileUploaded"
|
|
|
|
onfocus=${onfocus}
|
|
|
|
onblur=${onblur}
|
2018-07-31 18:09:18 +00:00
|
|
|
onchange=${addFiles} />
|
2018-08-07 22:40:17 +00:00
|
|
|
|
2018-07-31 18:09:18 +00:00
|
|
|
</label>
|
|
|
|
|
|
|
|
<div class="uploadOptions ${optionClass}">
|
2018-08-07 22:40:17 +00:00
|
|
|
${expireInfo(state, emit)}
|
2018-07-31 18:09:18 +00:00
|
|
|
${setPasswordSection(state)}
|
2017-08-24 21:54:02 +00:00
|
|
|
</div>
|
2018-07-31 18:09:18 +00:00
|
|
|
|
|
|
|
<label for="file-upload"
|
|
|
|
class="btn btn--file ${selectFileClass}"
|
|
|
|
title="${state.translate('uploadPageBrowseButton1')}">
|
|
|
|
${state.translate('uploadPageBrowseButton1')}
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="btn ${btnUploading} ${sendFileClass}"
|
2018-09-18 19:56:42 +00:00
|
|
|
onclick=${state.uploading ? noop : upload}
|
2018-07-31 18:09:18 +00:00
|
|
|
title="${btnText}">
|
|
|
|
${btnText}
|
|
|
|
</button>
|
|
|
|
|
2018-07-31 22:19:18 +00:00
|
|
|
<button class="btn--cancel uploadCancel ${cancelVisible}"
|
|
|
|
onclick=${cancel}>
|
|
|
|
${state.translate('uploadingPageCancel')}
|
|
|
|
</button>
|
|
|
|
|
2017-08-24 21:54:02 +00:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
2018-09-18 19:56:42 +00:00
|
|
|
function noop() {}
|
|
|
|
|
2017-08-24 21:54:02 +00:00
|
|
|
function dragover(event) {
|
2018-02-13 19:32:59 +00:00
|
|
|
const div = document.querySelector('.uploadArea');
|
|
|
|
div.classList.add('uploadArea--dragging');
|
2017-08-24 21:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function dragleave(event) {
|
2018-02-13 19:32:59 +00:00
|
|
|
const div = document.querySelector('.uploadArea');
|
|
|
|
div.classList.remove('uploadArea--dragging');
|
2017-08-24 21:54:02 +00:00
|
|
|
}
|
|
|
|
|
2017-09-12 23:49:50 +00:00
|
|
|
function onfocus(event) {
|
2018-02-13 19:32:59 +00:00
|
|
|
event.target.classList.add('inputFile--focused');
|
2017-09-12 23:49:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onblur(event) {
|
2018-02-13 19:32:59 +00:00
|
|
|
event.target.classList.remove('inputFile--focused');
|
2017-09-12 23:49:50 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 22:19:18 +00:00
|
|
|
function cancel(event) {
|
|
|
|
if (state.uploading) {
|
|
|
|
emit('cancel');
|
|
|
|
const cancelBtn = document.querySelector('.uploadCancel');
|
|
|
|
cancelBtn.innerHTML = state.translate('uploadCancelNotification');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 19:56:42 +00:00
|
|
|
function addFiles(event) {
|
2017-08-24 21:54:02 +00:00
|
|
|
event.preventDefault();
|
2018-08-03 19:24:41 +00:00
|
|
|
const newFiles = Array.from(event.target.files);
|
|
|
|
|
|
|
|
emit('addFiles', { files: newFiles });
|
2018-07-31 18:09:18 +00:00
|
|
|
}
|
2018-07-26 05:26:11 +00:00
|
|
|
|
2018-09-18 19:56:42 +00:00
|
|
|
function upload(event) {
|
2018-07-31 18:09:18 +00:00
|
|
|
event.preventDefault();
|
2018-09-18 19:56:42 +00:00
|
|
|
event.target.disabled = true;
|
|
|
|
if (!state.uploading) {
|
|
|
|
emit('upload', {
|
|
|
|
type: 'click',
|
|
|
|
dlimit: state.downloadCount || 1,
|
|
|
|
password: state.password
|
|
|
|
});
|
|
|
|
}
|
2017-08-24 21:54:02 +00:00
|
|
|
}
|
|
|
|
};
|