2018-09-25 00:08:39 +02:00
|
|
|
/* globals DEFAULTS */
|
2018-07-31 20:09:18 +02:00
|
|
|
const html = require('choo/html');
|
|
|
|
const raw = require('choo/html/raw');
|
|
|
|
const selectbox = require('../selectbox');
|
2018-08-08 20:07:09 +02:00
|
|
|
const timeLimitText = require('../timeLimitText');
|
2018-09-07 19:53:40 +02:00
|
|
|
const okDialog = require('../okDialog');
|
2018-07-31 20:09:18 +02:00
|
|
|
|
2018-08-08 00:40:17 +02:00
|
|
|
module.exports = function(state, emit) {
|
2018-07-31 20:09:18 +02:00
|
|
|
const el = html`<div> ${raw(
|
|
|
|
state.translate('frontPageExpireInfo', {
|
|
|
|
downloadCount: '<select id=dlCount></select>',
|
2018-08-08 20:07:09 +02:00
|
|
|
timespan: '<select id=timespan></select>'
|
2018-07-31 20:09:18 +02:00
|
|
|
})
|
|
|
|
)}
|
|
|
|
</div>`;
|
2018-08-08 00:40:17 +02:00
|
|
|
if (el.__encoded) {
|
|
|
|
// we're rendering on the server
|
|
|
|
return el;
|
|
|
|
}
|
2018-07-31 20:09:18 +02:00
|
|
|
|
2018-09-25 00:08:39 +02:00
|
|
|
const counts = DEFAULTS.DOWNLOAD_COUNTS.filter(
|
2018-09-17 21:05:03 +02:00
|
|
|
i => state.capabilities.account || i <= state.user.maxDownloads
|
|
|
|
);
|
|
|
|
|
2018-07-31 20:09:18 +02:00
|
|
|
const dlCountSelect = el.querySelector('#dlCount');
|
|
|
|
el.replaceChild(
|
|
|
|
selectbox(
|
|
|
|
state.downloadCount || 1,
|
2018-09-17 21:05:03 +02:00
|
|
|
counts,
|
2018-07-31 20:09:18 +02:00
|
|
|
num => state.translate('downloadCount', { num }),
|
|
|
|
value => {
|
2018-08-08 00:40:17 +02:00
|
|
|
const max = state.user.maxDownloads;
|
|
|
|
if (value > max) {
|
2018-09-07 19:53:40 +02:00
|
|
|
state.modal = okDialog('todo: this setting requires an account');
|
2018-08-08 00:40:17 +02:00
|
|
|
value = max;
|
|
|
|
}
|
2018-07-31 20:09:18 +02:00
|
|
|
state.downloadCount = value;
|
2018-08-08 00:40:17 +02:00
|
|
|
emit('render');
|
2018-07-31 20:09:18 +02:00
|
|
|
}
|
|
|
|
),
|
|
|
|
dlCountSelect
|
|
|
|
);
|
|
|
|
|
2018-09-25 00:08:39 +02:00
|
|
|
const expires = DEFAULTS.EXPIRE_TIMES_SECONDS.filter(
|
2018-09-17 21:05:03 +02:00
|
|
|
i => state.capabilities.account || i <= state.user.maxExpireSeconds
|
|
|
|
);
|
|
|
|
|
2018-07-31 20:09:18 +02:00
|
|
|
const timeSelect = el.querySelector('#timespan');
|
|
|
|
el.replaceChild(
|
2018-08-08 20:07:09 +02:00
|
|
|
selectbox(
|
|
|
|
state.timeLimit || 86400,
|
2018-09-17 21:05:03 +02:00
|
|
|
expires,
|
2018-08-08 20:07:09 +02:00
|
|
|
num => timeLimitText(state.translate, num),
|
|
|
|
value => {
|
2018-08-08 00:40:17 +02:00
|
|
|
const max = state.user.maxExpireSeconds;
|
|
|
|
if (value > max) {
|
2018-09-07 19:53:40 +02:00
|
|
|
state.modal = okDialog('todo: this setting requires an account');
|
2018-08-08 00:40:17 +02:00
|
|
|
value = max;
|
|
|
|
}
|
2018-08-08 20:07:09 +02:00
|
|
|
state.timeLimit = value;
|
2018-08-08 00:40:17 +02:00
|
|
|
emit('render');
|
2018-08-08 20:07:09 +02:00
|
|
|
}
|
|
|
|
),
|
2018-07-31 20:09:18 +02:00
|
|
|
timeSelect
|
|
|
|
);
|
|
|
|
|
|
|
|
return el;
|
|
|
|
};
|