From 2856b67018fde05af7bcd7c17e7af1de62785990 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 12 Nov 2014 21:55:48 +0100 Subject: [PATCH] Added client-side warning about too large files --- gruntfile.js | 1 + public_html/index.html | 2 ++ public_html/js/Presenters/PostUploadPresenter.js | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/gruntfile.js b/gruntfile.js index 3f8d4fec..7332d553 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -135,6 +135,7 @@ module.exports = function(grunt) { serviceName: config.basic.serviceName, templates: readTemplates(grunt), timestamp: grunt.template.today('isoDateTime'), + maxPostSize: config.database.maxPostSize, tagCategories: config.tags.categories, } }, diff --git a/public_html/index.html b/public_html/index.html index aac5a32a..17bc7fd2 100644 --- a/public_html/index.html +++ b/public_html/index.html @@ -4,12 +4,14 @@ diff --git a/public_html/js/Presenters/PostUploadPresenter.js b/public_html/js/Presenters/PostUploadPresenter.js index bfbe8b92..04ec70e5 100644 --- a/public_html/js/Presenters/PostUploadPresenter.js +++ b/public_html/js/Presenters/PostUploadPresenter.js @@ -25,10 +25,12 @@ App.Presenters.PostUploadPresenter = function( var interactionEnabled = true; var currentUploadId = null; var currentUploadXhr = null; + var maxPostSize = 0; function init(params, loaded) { topNavigationPresenter.select('upload'); topNavigationPresenter.changeTitle('Upload'); + maxPostSize = parseInt(jQuery('head').attr('data-max-post-size')); promise.wait(util.promiseTemplate('post-upload')) .then(function(template) { @@ -117,6 +119,12 @@ App.Presenters.PostUploadPresenter = function( if (files.length > 0) { var posts = []; for (var i = 0; i < files.length; i ++) { + if (files[i].size > maxPostSize) { + window.alert('File "' + files[i].name + '" is too big - ignoring.' + + String.fromCharCode(10) + + '(max allowed file size = ' + maxPostSize + ' bytes)'); + continue; + } var post = addPostFromFile(files[i]); posts.push(post); }