pad_impexp: Simplify creation of import failure message

pull/4779/head
Richard Hansen 2021-02-07 20:51:26 -05:00 committed by John McLear
parent 890e16f6fc
commit d869d96a2b
1 changed files with 9 additions and 14 deletions

View File

@ -74,24 +74,19 @@ const padimpexp = (() => {
};
const importErrorMessage = (status) => {
let msg = '';
if (status === 'convertFailed') {
msg = html10n.get('pad.impexp.convertFailed');
} else if (status === 'uploadFailed') {
msg = html10n.get('pad.impexp.uploadFailed');
} else if (status === 'padHasData') {
msg = html10n.get('pad.impexp.padHasData');
} else if (status === 'maxFileSize') {
msg = html10n.get('pad.impexp.maxFileSize');
} else if (status === 'permission') {
msg = html10n.get('pad.impexp.permission');
}
const known = [
'convertFailed',
'uploadFailed',
'padHasData',
'maxFileSize',
'permission',
];
const msg = html10n.get(`pad.impexp.${known.indexOf(status) !== -1 ? status : 'copypaste'}`);
const showError = (fade) => {
$('#importmessagefail').html(
`<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')) {