Commit 3b4cfe1eab82305a4332059ed798c0e34b197198

Authored by Zambom
1 parent a748a716

Adjusting file bugs in file link resource

amadeus/static/js/crop.js
@@ -3,7 +3,6 @@ $(function () { @@ -3,7 +3,6 @@ $(function () {
3 $("#id_image").change(function () { 3 $("#id_image").change(function () {
4 var max_size = 2*1024*1024; 4 var max_size = 2*1024*1024;
5 var submit_btn = $("#user-form").find("input[type='submit']"); 5 var submit_btn = $("#user-form").find("input[type='submit']");
6 - var regex = new RegExp("(.*?)\.(jpg|jpeg|png)$");  
7 var errors = 0; 6 var errors = 0;
8 7
9 $(".client-file-errors").hide(); 8 $(".client-file-errors").hide();
amadeus/static/js/resources.js
@@ -132,10 +132,43 @@ function Init() { @@ -132,10 +132,43 @@ function Init() {
132 // file selection 132 // file selection
133 function FileSelectHandler(e) { 133 function FileSelectHandler(e) {
134 var files = e.target.files || e.dataTransfer.files, 134 var files = e.target.files || e.dataTransfer.files,
135 - parent = $(e.target.offsetParent); 135 + parent = $(e.target.offsetParent),
  136 + max_size = parseInt($(e.target).data("max_size")) * 1024 * 1024,
  137 + submit_btn = $(e.target).closest("form").find("input[type='submit']"),
  138 + mimeTypes = ['image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png',
  139 + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  140 + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  141 + 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  142 + 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  143 + 'application/vnd.ms-excel','text/html','application/msword','application/vnd.oasis.opendocument.presentation',
  144 + 'application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.text',
  145 + 'application/pdf', 'application/vnd.ms-powerpoint'];
  146 +
  147 + $(".client-file-errors").hide();
  148 + $(".size").hide();
  149 + $(".format").hide();
  150 + $(submit_btn).prop('disable', false);
  151 + $(submit_btn).prop('disabled', false);
136 152
137 // process all File objects 153 // process all File objects
138 for (var i = 0, f; f = files[i]; i++) { 154 for (var i = 0, f; f = files[i]; i++) {
  155 +
  156 + if (f.size > max_size) {
  157 + $(submit_btn).prop('disable', true);
  158 + $(submit_btn).prop('disabled', true);
  159 +
  160 + $(".client-file-errors").show();
  161 + $(".size").show();
  162 + }
  163 +
  164 + if (!mimeTypes.includes(f.type)) {
  165 + $(submit_btn).prop('disable', true);
  166 + $(submit_btn).prop('disabled', true);
  167 +
  168 + $(".client-file-errors").show();
  169 + $(".format").show();
  170 + }
  171 +
139 parent.find('.filedrag').html(f.name); 172 parent.find('.filedrag').html(f.name);
140 } 173 }
141 } 174 }
142 \ No newline at end of file 175 \ No newline at end of file
file_link/models.py
@@ -15,7 +15,8 @@ def validate_file_extension(value): @@ -15,7 +15,8 @@ def validate_file_extension(value):
15 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 15 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
16 'application/vnd.ms-excel','text/html','application/msword','application/vnd.oasis.opendocument.presentation', 16 'application/vnd.ms-excel','text/html','application/msword','application/vnd.oasis.opendocument.presentation',
17 'application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.text', 17 'application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.text',
18 - 'application/pdf' 18 + 'application/pdf',
  19 + 'application/vnd.ms-powerpoint'
19 ] 20 ]
20 21
21 if hasattr(value.file, 'content_type'): 22 if hasattr(value.file, 'content_type'):
file_link/templates/file_links/_form.html
@@ -27,7 +27,7 @@ @@ -27,7 +27,7 @@
27 </div> 27 </div>
28 28
29 <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> 29 <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput">
30 - {% render_field form.file_content class='file-selector' %} 30 + {% render_field form.file_content class='file-selector' data-max_size="10" %}
31 31
32 <div class="input-group common-file-input"> 32 <div class="input-group common-file-input">
33 <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}"> 33 <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}">
@@ -52,18 +52,29 @@ @@ -52,18 +52,29 @@
52 52
53 <span id="helpBlock" class="help-block">{{ form.file_content.help_text }}</span> 53 <span id="helpBlock" class="help-block">{{ form.file_content.help_text }}</span>
54 54
55 - {% if form.file_content.errors %}  
56 - <div class="alert alert-danger alert-dismissible" role="alert">  
57 - <button type="button" class="close" data-dismiss="alert" aria-label="Close">  
58 - <span aria-hidden="true">&times;</span>  
59 - </button>  
60 - <ul>  
61 - {% for error in form.file_content.errors %}  
62 - <li>{{ error }}</li>  
63 - {% endfor %}  
64 - </ul>  
65 - </div>  
66 - {% endif %} 55 + </div>
  56 +
  57 + {% if form.file_content.errors %}
  58 + <div class="alert alert-danger alert-dismissible" role="alert">
  59 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  60 + <span aria-hidden="true">&times;</span>
  61 + </button>
  62 + <ul>
  63 + {% for error in form.file_content.errors %}
  64 + <li>{{ error }}</li>
  65 + {% endfor %}
  66 + </ul>
  67 + </div>
  68 + {% endif %}
  69 +
  70 + <div class="col-lg-12 col-md-12 col-sm-12 alert alert-danger alert-dismissible client-file-errors" style="display:none" role="alert">
  71 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  72 + <span aria-hidden="true">&times;</span>
  73 + </button>
  74 + <ul>
  75 + <li class="size" style="display:none">{% trans "The file is too large. It should have less than 10MB." %}</li>
  76 + <li class="format" style="display:none">{% trans 'File not supported.' %}</li>
  77 + </ul>
67 </div> 78 </div>
68 79
69 <legend>{% trans 'Common resources settings' %}</legend> 80 <legend>{% trans 'Common resources settings' %}</legend>