pad_impexp: Simplify creation of import failure message

This commit is contained in:
Richard Hansen 2021-02-07 20:51:26 -05:00 committed by John McLear
parent 890e16f6fc
commit d869d96a2b

View file

@ -74,24 +74,19 @@ const padimpexp = (() => {
}; };
const importErrorMessage = (status) => { const importErrorMessage = (status) => {
let msg = ''; const known = [
'convertFailed',
if (status === 'convertFailed') { 'uploadFailed',
msg = html10n.get('pad.impexp.convertFailed'); 'padHasData',
} else if (status === 'uploadFailed') { 'maxFileSize',
msg = html10n.get('pad.impexp.uploadFailed'); 'permission',
} else if (status === 'padHasData') { ];
msg = html10n.get('pad.impexp.padHasData'); const msg = html10n.get(`pad.impexp.${known.indexOf(status) !== -1 ? status : 'copypaste'}`);
} else if (status === 'maxFileSize') {
msg = html10n.get('pad.impexp.maxFileSize');
} else if (status === 'permission') {
msg = html10n.get('pad.impexp.permission');
}
const showError = (fade) => { const showError = (fade) => {
$('#importmessagefail').html( $('#importmessagefail').html(
`<strong style="color: red">${html10n.get('pad.impexp.importfailed')}:</strong> ` + `<strong style="color: red">${html10n.get('pad.impexp.importfailed')}:</strong> ` +
`${msg || html10n.get('pad.impexp.copypaste', '')}`)[(fade ? 'fadeIn' : 'show')](); `${msg}`)[(fade ? 'fadeIn' : 'show')]();
}; };
if ($('#importexport .importmessage').is(':visible')) { if ($('#importexport .importmessage').is(':visible')) {