From f5ebff0cdd9ef99d536ef4a9f7c45706152153fa Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 27 Sep 2015 14:42:53 +0000 Subject: Replace copy-pasted pomf.js errors with constants Introduces client-side UPLOAD_ERR_MAX_SIZE and UPLOAD_ERR_FAILED constants. This reduces code duplication, which means less code smell. --- js/pomf.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/js/pomf.js b/js/pomf.js index 2cea939..bdd3174 100644 --- a/js/pomf.js +++ b/js/pomf.js @@ -106,10 +106,12 @@ $(function() { var totalName = $('.file-name', totalRow); + var UPLOAD_ERR_MAX_SIZE = 'onii-chan y-your upload is t-too big…'; + var UPLOAD_ERR_FAILED = 'Something went wrong; try again later.'; + if (files.size > MAX_SIZE) { uploadFiles.addClass('error'); - - totalName.html('onii-chan y-your upload is t-too big…'); + totalName.html(UPLOAD_ERR_MAX_SIZE); return; } @@ -143,7 +145,7 @@ $(function() { var res = JSON.parse(res); if (!res.success) { uploadFiles.addClass('error'); - totalName.text('Something went wrong; try again later.'); + totalName.text(UPLOAD_ERR_FAILED); break; } eachRow(res.files, function(row, file, files) { @@ -160,11 +162,11 @@ $(function() { break; case 413: uploadFiles.addClass('error completed'); - totalName.html('onii-chan, y-your upload is t-too big…'); + totalName.html(UPLOAD_ERR_MAX_SIZE); break; default: uploadFiles.addClass('error completed'); - totalName.text('Something went wrong; try again later.'); + totalName.text(UPLOAD_ERR_FAILED); } }); up.upload(); -- cgit v1.2.3