Commit 1ff370903b808c188355489b81478bba6c819f1b

Authored by Zambom
1 parent 46f6c2a8

Resolving bugs in mural post comment creation

amadeus/static/js/mural.js
... ... @@ -255,6 +255,11 @@ function setCommentFormSubmit(post, comment = "") {
255 255 var frm = $('#comment-form');
256 256  
257 257 frm.submit(function () {
  258 + var btn = frm.parent().parent().parent().find("button[form='comment-form']")
  259 +
  260 + btn.prop('disable', true);
  261 + btn.prop('disabled', true);
  262 +
258 263 var formData = new FormData($(this)[0]);
259 264  
260 265 $.ajax({
... ...
mural/templates/mural/_form_comment.html
... ... @@ -45,19 +45,29 @@
45 45 </div>
46 46  
47 47 <span id="helpBlock" class="help-block">{{ form.image.help_text }}</span>
  48 + </div>
48 49  
49   - {% if form.image.errors %}
50   - <div class="alert alert-danger alert-dismissible" role="alert">
51   - <button type="button" class="close" data-dismiss="alert" aria-label="Close">
52   - <span aria-hidden="true">&times;</span>
53   - </button>
54   - <ul>
55   - {% for error in form.image.errors %}
56   - <li>{{ error }}</li>
57   - {% endfor %}
58   - </ul>
59   - </div>
60   - {% endif %}
  50 + {% if form.image.errors %}
  51 + <div class="alert alert-danger alert-dismissible" role="alert">
  52 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  53 + <span aria-hidden="true">&times;</span>
  54 + </button>
  55 + <ul>
  56 + {% for error in form.image.errors %}
  57 + <li>{{ error }}</li>
  58 + {% endfor %}
  59 + </ul>
  60 + </div>
  61 + {% endif %}
  62 +
  63 + <div class="alert alert-danger alert-dismissible client-file-errors" style="display:none" role="alert">
  64 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  65 + <span aria-hidden="true">&times;</span>
  66 + </button>
  67 + <ul>
  68 + <li class="size" style="display:none">{% trans "The image is too large. It should have less than 5MB." %}</li>
  69 + <li class="format" style="display:none">{% trans 'File not supported.' %}</li>
  70 + </ul>
61 71 </div>
62 72 </form>
63 73 </div>
... ... @@ -225,10 +235,33 @@
225 235 // file selection
226 236 function FileSelectHandler(e) {
227 237 var files = e.target.files || e.dataTransfer.files,
228   - parent = $(e.target.offsetParent);
  238 + parent = $(e.target.offsetParent),
  239 + max_size = 5*1024*1024;
  240 +
  241 + $(".client-file-errors").hide();
  242 + $(".size").hide();
  243 + $(".format").hide();
  244 + $("#button").prop('disable', false);
  245 + $("#button").prop('disabled', false);
229 246  
230 247 // process all File objects
231 248 for (var i = 0, f; f = files[i]; i++) {
  249 + if (f.size > max_size) {
  250 + $("#button").prop('disable', true);
  251 + $("#button").prop('disabled', true);
  252 +
  253 + $(".client-file-errors").show();
  254 + $(".size").show();
  255 + }
  256 +
  257 + if (!f.type.match(/^image\//)) {
  258 + $("#button").prop('disable', true);
  259 + $("#button").prop('disabled', true);
  260 +
  261 + $(".client-file-errors").show();
  262 + $(".format").show();
  263 + }
  264 +
232 265 parent.find('.filedrag').html(f.name);
233 266 }
234 267 }
... ...