From 3b4cfe1eab82305a4332059ed798c0e34b197198 Mon Sep 17 00:00:00 2001 From: Zambom Date: Fri, 1 Sep 2017 00:01:58 -0300 Subject: [PATCH] Adjusting file bugs in file link resource --- amadeus/static/js/crop.js | 1 - amadeus/static/js/resources.js | 35 ++++++++++++++++++++++++++++++++++- file_link/models.py | 3 ++- file_link/templates/file_links/_form.html | 37 ++++++++++++++++++++++++------------- 4 files changed, 60 insertions(+), 16 deletions(-) diff --git a/amadeus/static/js/crop.js b/amadeus/static/js/crop.js index 619a0cd..f8f0386 100644 --- a/amadeus/static/js/crop.js +++ b/amadeus/static/js/crop.js @@ -3,7 +3,6 @@ $(function () { $("#id_image").change(function () { var max_size = 2*1024*1024; var submit_btn = $("#user-form").find("input[type='submit']"); - var regex = new RegExp("(.*?)\.(jpg|jpeg|png)$"); var errors = 0; $(".client-file-errors").hide(); diff --git a/amadeus/static/js/resources.js b/amadeus/static/js/resources.js index ddf6cbc..f32f4ef 100644 --- a/amadeus/static/js/resources.js +++ b/amadeus/static/js/resources.js @@ -132,10 +132,43 @@ function Init() { // file selection function FileSelectHandler(e) { var files = e.target.files || e.dataTransfer.files, - parent = $(e.target.offsetParent); + parent = $(e.target.offsetParent), + max_size = parseInt($(e.target).data("max_size")) * 1024 * 1024, + submit_btn = $(e.target).closest("form").find("input[type='submit']"), + mimeTypes = ['image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', + 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + 'application/vnd.ms-excel','text/html','application/msword','application/vnd.oasis.opendocument.presentation', + 'application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.text', + 'application/pdf', 'application/vnd.ms-powerpoint']; + + $(".client-file-errors").hide(); + $(".size").hide(); + $(".format").hide(); + $(submit_btn).prop('disable', false); + $(submit_btn).prop('disabled', false); // process all File objects for (var i = 0, f; f = files[i]; i++) { + + if (f.size > max_size) { + $(submit_btn).prop('disable', true); + $(submit_btn).prop('disabled', true); + + $(".client-file-errors").show(); + $(".size").show(); + } + + if (!mimeTypes.includes(f.type)) { + $(submit_btn).prop('disable', true); + $(submit_btn).prop('disabled', true); + + $(".client-file-errors").show(); + $(".format").show(); + } + parent.find('.filedrag').html(f.name); } } \ No newline at end of file diff --git a/file_link/models.py b/file_link/models.py index 2604901..5652310 100644 --- a/file_link/models.py +++ b/file_link/models.py @@ -15,7 +15,8 @@ def validate_file_extension(value): 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/vnd.ms-excel','text/html','application/msword','application/vnd.oasis.opendocument.presentation', 'application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.text', - 'application/pdf' + 'application/pdf', + 'application/vnd.ms-powerpoint' ] if hasattr(value.file, 'content_type'): diff --git a/file_link/templates/file_links/_form.html b/file_link/templates/file_links/_form.html index 9917a5b..5fa2ed8 100644 --- a/file_link/templates/file_links/_form.html +++ b/file_link/templates/file_links/_form.html @@ -27,7 +27,7 @@
- {% render_field form.file_content class='file-selector' %} + {% render_field form.file_content class='file-selector' data-max_size="10" %}
@@ -52,18 +52,29 @@ {{ form.file_content.help_text }} - {% if form.file_content.errors %} - - {% endif %} +
+ + {% if form.file_content.errors %} + + {% endif %} + + {% trans 'Common resources settings' %} -- libgit2 0.21.2