2017-08-24 21:54:02 +00:00
|
|
|
const html = require('choo/html');
|
|
|
|
const assets = require('../../common/assets');
|
|
|
|
const fileList = require('./fileList');
|
|
|
|
const { fadeOut } = require('../utils');
|
|
|
|
|
|
|
|
module.exports = function(state, emit) {
|
|
|
|
const div = html`
|
|
|
|
<div id="page-one" class="fadeIn">
|
|
|
|
<div class="title">${state.translate('uploadPageHeader')}</div>
|
|
|
|
<div class="description">
|
|
|
|
<div>${state.translate('uploadPageExplainer')}</div>
|
|
|
|
<a href="https://testpilot.firefox.com/experiments/send" class="link">${state.translate(
|
|
|
|
'uploadPageLearnMore'
|
|
|
|
)}</a>
|
|
|
|
</div>
|
2017-09-12 00:09:29 +00:00
|
|
|
<div class="${state.config
|
|
|
|
.uploadWindowStyle}" ondragover=${dragover} ondragleave=${dragleave}>
|
2017-08-24 21:54:02 +00:00
|
|
|
<div id="upload-img"><img src="${assets.get(
|
|
|
|
'upload.svg'
|
|
|
|
)}" title="${state.translate('uploadSvgAlt')}"/></div>
|
|
|
|
<div id="upload-text">${state.translate('uploadPageDropMessage')}</div>
|
|
|
|
<span id="file-size-msg"><em>${state.translate(
|
|
|
|
'uploadPageSizeMessage'
|
|
|
|
)}</em></span>
|
|
|
|
<form method="post" action="upload" enctype="multipart/form-data">
|
2017-09-12 00:09:29 +00:00
|
|
|
<label for="file-upload" id="browse" class="${state.config
|
2017-09-13 19:01:55 +00:00
|
|
|
.uploadButtonStyle}" title="${state.translate(
|
2017-09-12 00:09:29 +00:00
|
|
|
'uploadPageBrowseButton1'
|
2017-09-13 19:01:55 +00:00
|
|
|
)}">${state.translate('uploadPageBrowseButton1')}</label>
|
2017-08-24 21:54:02 +00:00
|
|
|
<input id="file-upload" type="file" name="fileUploaded" onchange=${upload} />
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
${fileList(state, emit)}
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
|
|
|
function dragover(event) {
|
2017-08-29 18:36:40 +00:00
|
|
|
const div = document.querySelector('.upload-window');
|
|
|
|
div.classList.add('ondrag');
|
2017-08-24 21:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function dragleave(event) {
|
2017-08-29 18:36:40 +00:00
|
|
|
const div = document.querySelector('.upload-window');
|
|
|
|
div.classList.remove('ondrag');
|
2017-08-24 21:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function upload(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
const target = event.target;
|
|
|
|
const file = target.files[0];
|
2017-08-29 18:20:34 +00:00
|
|
|
if (file.size === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-24 21:54:02 +00:00
|
|
|
await fadeOut('page-one');
|
|
|
|
emit('upload', { file, type: 'click' });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.layout) {
|
|
|
|
return state.layout(state, div);
|
|
|
|
}
|
|
|
|
return div;
|
|
|
|
};
|