Commit d9bc8ef689beebb7d0f5034514f561b9b312a185
1 parent
c2ff223a
Exists in
master
and in
2 other branches
Resolvendo bug 1 e 2 em webpage
Showing
3 changed files
with
52 additions
and
17 deletions
Show diff stats
webpage/forms.py
... | ... | @@ -102,7 +102,7 @@ class FormModalMessage(forms.Form): |
102 | 102 | MAX_UPLOAD_SIZE = 5*1024*1024 |
103 | 103 | |
104 | 104 | comment = forms.CharField(widget=forms.Textarea,label=_("Message")) |
105 | - image = forms.FileField(widget=ResubmitFileWidget(attrs={'accept':'image/*'})) | |
105 | + image = forms.FileField(widget=ResubmitFileWidget(attrs={'accept':'image/*'}),required=False) | |
106 | 106 | |
107 | 107 | def clean_comment(self): |
108 | 108 | comment = self.cleaned_data.get('comment', '') | ... | ... |
webpage/templates/webpages/relatorios.html
... | ... | @@ -84,6 +84,7 @@ |
84 | 84 | } |
85 | 85 | searcher(col, tabela_atual,true); |
86 | 86 | } |
87 | + scroll("#title-table"); | |
87 | 88 | } |
88 | 89 | chart.setSelection([]) |
89 | 90 | } |
... | ... | @@ -153,16 +154,18 @@ |
153 | 154 | {% endblock %} |
154 | 155 | |
155 | 156 | {% block content %} |
156 | - {% if messages %} | |
157 | - {% for message in messages %} | |
158 | - <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert"> | |
159 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
160 | - <span aria-hidden="true">×</span> | |
161 | - </button> | |
162 | - <p>{{ message }}</p> | |
163 | - </div> | |
164 | - {% endfor %} | |
165 | - {% endif %} | |
157 | + <div id="message-top"> | |
158 | + {% if messages %} | |
159 | + {% for message in messages %} | |
160 | + <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert"> | |
161 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
162 | + <span aria-hidden="true">×</span> | |
163 | + </button> | |
164 | + <p>{{ message }}</p> | |
165 | + </div> | |
166 | + {% endfor %} | |
167 | + {% endif %} | |
168 | + </div> | |
166 | 169 | <div class="panel panel-info topic-panel"> |
167 | 170 | <div class="panel-heading"> |
168 | 171 | <div class="row"> |
... | ... | @@ -392,17 +395,41 @@ |
392 | 395 | $("body").removeClass("modal-open"); |
393 | 396 | $( "#modal-message" ).empty(); |
394 | 397 | $(".modal-backdrop.fade.in").remove(); |
398 | + $("#message-top").empty(); | |
399 | + $("#message-top").append('\ | |
400 | + <div class="alert alert-success alert-dismissible" role="alert">\ | |
401 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close">\ | |
402 | + <span aria-hidden="true">×</span>\ | |
403 | + </button>\ | |
404 | + <p>' + data["message"] + '</p>\ | |
405 | + </div>\ | |
406 | + '); | |
407 | + $("html, body").animate({ scrollTop: 0 }, "slow"); | |
408 | + $('#google-chart-checkbox')[0].reset(); | |
395 | 409 | } else { |
396 | 410 | $( "#modal-message" ).empty(); |
397 | 411 | $(".modal-backdrop.fade.in").remove(); |
398 | 412 | $( "#modal-message" ).append( data ); |
399 | 413 | $("#send-message-modal").modal("show"); |
414 | + $("html, body").animate({ scrollTop: 0 }, "slow"); | |
400 | 415 | } |
401 | 416 | }, |
402 | 417 | error: function(data){ |
403 | - console.log("erro"); | |
418 | + $("#message-top").empty(); | |
419 | + $("#message-top").append('\ | |
420 | + <div class="alert alert-danger alert-dismissible" role="alert">\ | |
421 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close">\ | |
422 | + <span aria-hidden="true">×</span>\ | |
423 | + </button>\ | |
424 | + <p>' + data.responseText + '</p>\ | |
425 | + </div>\ | |
426 | + '); | |
427 | + $("html, body").animate({ scrollTop: 0 }, "slow"); | |
404 | 428 | } |
405 | 429 | }); |
406 | 430 | } |
431 | + function scroll(to){ | |
432 | + $("html, body").animate({ scrollTop: $(to).offset().top }, "slow"); | |
433 | + } | |
407 | 434 | </script> |
408 | 435 | {% endblock %} | ... | ... |
webpage/views.py
... | ... | @@ -513,6 +513,8 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): |
513 | 513 | |
514 | 514 | |
515 | 515 | |
516 | +from django.http import HttpResponse #used to send HTTP 404 error to ajax | |
517 | + | |
516 | 518 | class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): |
517 | 519 | log_component = 'resources' |
518 | 520 | log_action = 'send' |
... | ... | @@ -541,11 +543,17 @@ class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): |
541 | 543 | users = (self.request.POST.get('users[]','')).split(",") |
542 | 544 | user = self.request.user |
543 | 545 | subject = self.webpage.topic.subject |
544 | - for u in users: | |
545 | - to_user = User.objects.get(email=u) | |
546 | - talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) | |
547 | - created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image) | |
548 | - return JsonResponse({"message":"ok"}) | |
546 | + | |
547 | + if (users[0] is not ''): | |
548 | + for u in users: | |
549 | + to_user = User.objects.get(email=u) | |
550 | + talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user) | |
551 | + created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image) | |
552 | + success = str(_('The message was successfull sent!')) | |
553 | + return JsonResponse({"message":success}) | |
554 | + erro = HttpResponse(str(_("No user selected!"))) | |
555 | + erro.status_code = 404 | |
556 | + return erro | |
549 | 557 | |
550 | 558 | def get_context_data(self, **kwargs): |
551 | 559 | context = super(SendMessage,self).get_context_data() | ... | ... |