Commit 46f6c2a839b49d7fea575f73f394f1c8ec86f6e0

Authored by Zambom
1 parent 1d178d46

Resolving bugs in mural post creation

amadeus/static/js/mural.js
@@ -91,7 +91,12 @@ function seeComplete(btn, post) { @@ -91,7 +91,12 @@ function seeComplete(btn, post) {
91 function setPostFormSubmit(post = "") { 91 function setPostFormSubmit(post = "") {
92 var frm = $('#post-form'); 92 var frm = $('#post-form');
93 93
94 - frm.submit(function () { 94 + frm.submit(function (e) {
  95 + var btn = frm.parent().parent().parent().find("button[form='post-form']")
  96 +
  97 + btn.prop('disable', true);
  98 + btn.prop('disabled', true);
  99 +
95 var formData = new FormData($(this)[0]); 100 var formData = new FormData($(this)[0]);
96 101
97 $.ajax({ 102 $.ajax({
chat/models.py
@@ -11,9 +11,9 @@ from datetime import timezone @@ -11,9 +11,9 @@ from datetime import timezone
11 from subjects.models import Subject 11 from subjects.models import Subject
12 from users.models import User 12 from users.models import User
13 13
  14 +valid_formats = ['image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png','image/gif']
  15 +
14 def validate_img_extension(value): 16 def validate_img_extension(value):
15 - valid_formats = ['image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png','image/gif']  
16 -  
17 if hasattr(value.file, 'content_type'): 17 if hasattr(value.file, 'content_type'):
18 if not value.file.content_type in valid_formats: 18 if not value.file.content_type in valid_formats:
19 raise ValidationError(_('Select a valid file. The file must posses one of this extensions: .jpg, .png, .gif')) 19 raise ValidationError(_('Select a valid file. The file must posses one of this extensions: .jpg, .png, .gif'))
mural/models.py
@@ -10,9 +10,9 @@ from subjects.models import Subject @@ -10,9 +10,9 @@ from subjects.models import Subject
10 from topics.models import KnowsChild, Resource 10 from topics.models import KnowsChild, Resource
11 from users.models import User 11 from users.models import User
12 12
13 -def validate_img_extension(value):  
14 - valid_formats = ['image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png'] 13 +valid_formats = ['image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png','image/gif']
15 14
  15 +def validate_img_extension(value):
16 if hasattr(value.file, 'content_type'): 16 if hasattr(value.file, 'content_type'):
17 if not value.file.content_type in valid_formats: 17 if not value.file.content_type in valid_formats:
18 raise ValidationError(_('File not supported.')) 18 raise ValidationError(_('File not supported.'))
mural/templates/mural/_form.html
@@ -80,24 +80,35 @@ @@ -80,24 +80,35 @@
80 80
81 <span id="helpBlock" class="help-block">{{ form.image.help_text }}</span> 81 <span id="helpBlock" class="help-block">{{ form.image.help_text }}</span>
82 82
83 - {% if form.image.errors %}  
84 - <div class="alert alert-danger alert-dismissible" role="alert">  
85 - <button type="button" class="close" data-dismiss="alert" aria-label="Close">  
86 - <span aria-hidden="true">&times;</span>  
87 - </button>  
88 - <ul>  
89 - {% for error in form.image.errors %}  
90 - <li>{{ error }}</li>  
91 - {% endfor %}  
92 - </ul>  
93 - </div>  
94 - {% endif %} 83 + </div>
  84 +
  85 + {% if form.image.errors %}
  86 + <div class="alert alert-danger alert-dismissible" role="alert">
  87 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  88 + <span aria-hidden="true">&times;</span>
  89 + </button>
  90 + <ul>
  91 + {% for error in form.image.errors %}
  92 + <li>{{ error }}</li>
  93 + {% endfor %}
  94 + </ul>
  95 + </div>
  96 + {% endif %}
  97 +
  98 + <div class="alert alert-danger alert-dismissible client-file-errors" style="display:none" role="alert">
  99 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  100 + <span aria-hidden="true">&times;</span>
  101 + </button>
  102 + <ul>
  103 + <li class="size" style="display:none">{% trans "The image is too large. It should have less than 5MB." %}</li>
  104 + <li class="format" style="display:none">{% trans 'File not supported.' %}</li>
  105 + </ul>
95 </div> 106 </div>
96 </form> 107 </form>
97 </div> 108 </div>
98 <div class="modal-footer"> 109 <div class="modal-footer">
99 <div class="col-md-12"> 110 <div class="col-md-12">
100 - <button type="submit" id="button" form="post-form" class="btn btn-success btn-raised post-button pull-left">{% trans "Post" context "button"%}</button> 111 + <button type="submit" id="button" form="post-form" class="btn btn-success btn-raised post-button pull-left">{% trans "Post" context "button" %}</button>
101 <button type="button" class="btn btn-raised btn-default pull-right" data-dismiss="modal">{% trans "Cancel" %}</button> 112 <button type="button" class="btn btn-raised btn-default pull-right" data-dismiss="modal">{% trans "Cancel" %}</button>
102 </div> 113 </div>
103 </div> 114 </div>
@@ -147,10 +158,33 @@ @@ -147,10 +158,33 @@
147 // file selection 158 // file selection
148 function FileSelectHandler(e) { 159 function FileSelectHandler(e) {
149 var files = e.target.files || e.dataTransfer.files, 160 var files = e.target.files || e.dataTransfer.files,
150 - parent = $(e.target.offsetParent); 161 + parent = $(e.target.offsetParent),
  162 + max_size = 5*1024*1024;
  163 +
  164 + $(".client-file-errors").hide();
  165 + $(".size").hide();
  166 + $(".format").hide();
  167 + $("#button").prop('disable', false);
  168 + $("#button").prop('disabled', false);
151 169
152 // process all File objects 170 // process all File objects
153 for (var i = 0, f; f = files[i]; i++) { 171 for (var i = 0, f; f = files[i]; i++) {
  172 + if (f.size > max_size) {
  173 + $("#button").prop('disable', true);
  174 + $("#button").prop('disabled', true);
  175 +
  176 + $(".client-file-errors").show();
  177 + $(".size").show();
  178 + }
  179 +
  180 + if (!f.type.match(/^image\//)) {
  181 + $("#button").prop('disable', true);
  182 + $("#button").prop('disabled', true);
  183 +
  184 + $(".client-file-errors").show();
  185 + $(".format").show();
  186 + }
  187 +
154 parent.find('.filedrag').html(f.name); 188 parent.find('.filedrag').html(f.name);
155 } 189 }
156 } 190 }