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,7 +102,7 @@ class FormModalMessage(forms.Form): | ||
102 | MAX_UPLOAD_SIZE = 5*1024*1024 | 102 | MAX_UPLOAD_SIZE = 5*1024*1024 |
103 | 103 | ||
104 | comment = forms.CharField(widget=forms.Textarea,label=_("Message")) | 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 | def clean_comment(self): | 107 | def clean_comment(self): |
108 | comment = self.cleaned_data.get('comment', '') | 108 | comment = self.cleaned_data.get('comment', '') |
webpage/templates/webpages/relatorios.html
@@ -84,6 +84,7 @@ | @@ -84,6 +84,7 @@ | ||
84 | } | 84 | } |
85 | searcher(col, tabela_atual,true); | 85 | searcher(col, tabela_atual,true); |
86 | } | 86 | } |
87 | + scroll("#title-table"); | ||
87 | } | 88 | } |
88 | chart.setSelection([]) | 89 | chart.setSelection([]) |
89 | } | 90 | } |
@@ -153,16 +154,18 @@ | @@ -153,16 +154,18 @@ | ||
153 | {% endblock %} | 154 | {% endblock %} |
154 | 155 | ||
155 | {% block content %} | 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 | <div class="panel panel-info topic-panel"> | 169 | <div class="panel panel-info topic-panel"> |
167 | <div class="panel-heading"> | 170 | <div class="panel-heading"> |
168 | <div class="row"> | 171 | <div class="row"> |
@@ -392,17 +395,41 @@ | @@ -392,17 +395,41 @@ | ||
392 | $("body").removeClass("modal-open"); | 395 | $("body").removeClass("modal-open"); |
393 | $( "#modal-message" ).empty(); | 396 | $( "#modal-message" ).empty(); |
394 | $(".modal-backdrop.fade.in").remove(); | 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 | } else { | 409 | } else { |
396 | $( "#modal-message" ).empty(); | 410 | $( "#modal-message" ).empty(); |
397 | $(".modal-backdrop.fade.in").remove(); | 411 | $(".modal-backdrop.fade.in").remove(); |
398 | $( "#modal-message" ).append( data ); | 412 | $( "#modal-message" ).append( data ); |
399 | $("#send-message-modal").modal("show"); | 413 | $("#send-message-modal").modal("show"); |
414 | + $("html, body").animate({ scrollTop: 0 }, "slow"); | ||
400 | } | 415 | } |
401 | }, | 416 | }, |
402 | error: function(data){ | 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 | </script> | 434 | </script> |
408 | {% endblock %} | 435 | {% endblock %} |
webpage/views.py
@@ -513,6 +513,8 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): | @@ -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 | class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): | 518 | class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): |
517 | log_component = 'resources' | 519 | log_component = 'resources' |
518 | log_action = 'send' | 520 | log_action = 'send' |
@@ -541,11 +543,17 @@ class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): | @@ -541,11 +543,17 @@ class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView): | ||
541 | users = (self.request.POST.get('users[]','')).split(",") | 543 | users = (self.request.POST.get('users[]','')).split(",") |
542 | user = self.request.user | 544 | user = self.request.user |
543 | subject = self.webpage.topic.subject | 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 | def get_context_data(self, **kwargs): | 558 | def get_context_data(self, **kwargs): |
551 | context = super(SendMessage,self).get_context_data() | 559 | context = super(SendMessage,self).get_context_data() |