drop.chapril.org-firefoxsend/app/ui/expiryOptions.js

74 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2018-10-25 04:07:10 +02:00
const html = require('choo/html');
const raw = require('choo/html/raw');
const { secondsToL10nId } = require('../utils');
const selectbox = require('./selectbox');
module.exports = function(state, emit) {
const el = html`
2019-02-11 22:48:06 +01:00
<div class="px-1">
2019-01-24 21:31:20 +01:00
${raw(
state.translate('archiveExpiryInfo', {
2019-01-24 21:31:20 +01:00
downloadCount:
'<span class="lg:inline-block md:block sm:inline-block block"></span><select id="dlCount"></select>',
timespan: '<select id="timespan"></select>'
})
)}
2018-11-16 21:39:36 +01:00
</div>
`;
2018-10-25 04:07:10 +02:00
if (el.__encoded) {
// we're rendering on the server
return el;
}
const counts = state.DEFAULTS.DOWNLOAD_COUNTS.filter(
2018-10-25 04:07:10 +02:00
i => state.capabilities.account || i <= state.user.maxDownloads
);
const dlCountSelect = el.querySelector('#dlCount');
el.replaceChild(
selectbox(
2019-02-12 20:50:06 +01:00
state.archive.dlimit,
2018-10-25 04:07:10 +02:00
counts,
num => state.translate('downloadCount', { num }),
value => {
2021-05-19 06:43:08 +02:00
const selected = parseInt(value);
state.archive.dlimit = selected;
emit('render');
if (selected > parseInt(state.user.maxDownloads || '0')) {
console.log('Chosen max download count is larger than the allowed limit', selected)
2018-10-25 04:07:10 +02:00
}
},
'expire-after-dl-count-select'
2018-10-25 04:07:10 +02:00
),
dlCountSelect
);
const expires = state.DEFAULTS.EXPIRE_TIMES_SECONDS.filter(
2018-10-25 04:07:10 +02:00
i => state.capabilities.account || i <= state.user.maxExpireSeconds
);
const timeSelect = el.querySelector('#timespan');
el.replaceChild(
selectbox(
2019-02-12 20:50:06 +01:00
state.archive.timeLimit,
2018-10-25 04:07:10 +02:00
expires,
num => {
const l10n = secondsToL10nId(num);
return state.translate(l10n.id, l10n);
},
value => {
2021-05-19 06:43:08 +02:00
const selected = parseInt(value);
state.archive.timeLimit = selected;
emit('render');
if (selected > parseInt(state.user.maxExpireSeconds || '0')) {
console.log('Chosen download expiration is larger than the allowed limit', selected)
2018-10-25 04:07:10 +02:00
}
},
'expire-after-time-select'
2018-10-25 04:07:10 +02:00
),
timeSelect
);
return el;
};