Commit 082830a137173cdf9fdfcabc61b4e0379f8af1d4

Authored by Jailson Dias
1 parent 54304f2c

colocando a opção de enviar mensagem junto com o texto quando for enviar uma men…

…sagem para varias pessoas no relatorio de pdf_file
pdf_file/templates/pdf_file/relatorios.html
@@ -34,7 +34,7 @@ @@ -34,7 +34,7 @@
34 array_n_did.push([input,"{{data_json.1}}","{{data_json.2}}", "{{data_json.3}}"]); 34 array_n_did.push([input,"{{data_json.1}}","{{data_json.2}}", "{{data_json.3}}"]);
35 {% endfor%} 35 {% endfor%}
36 var json_n_did = {"data":array_n_did}; 36 var json_n_did = {"data":array_n_did};
37 - var column_n_did = [{"string":'<a href="javascript:void(0);" onclick="return openmodal();"> {% trans "Send message" %}</a>'},{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":"Action don't realized"}]; 37 + var column_n_did = [{"string":'<a href="javascript:void(0);" onclick="return openmodal();"> {% trans "Send message" %}</a>'},{"string":'{% trans "User" %}'},{"string":'{% trans "Group" %}'},{"string":"{% trans "Action don't realized" %}"}];
38 </script> 38 </script>
39 39
40 40
@@ -138,6 +138,7 @@ @@ -138,6 +138,7 @@
138 table.draw(data_table, options); 138 table.draw(data_table, options);
139 } 139 }
140 } 140 }
  141 +
141 var table = new google.visualization.Table(document.getElementById('table_div')); 142 var table = new google.visualization.Table(document.getElementById('table_div'));
142 google.visualization.events.addListener(table, 'sort', function(e) {ordenar(e)}); 143 google.visualization.events.addListener(table, 'sort', function(e) {ordenar(e)});
143 table.draw(data_table, options); 144 table.draw(data_table, options);
@@ -205,13 +206,13 @@ @@ -205,13 +206,13 @@
205 </div> 206 </div>
206 </div> 207 </div>
207 208
208 - <div class="row"> 209 + <div class="row">
209 <div class="col-md-10 col-md-offset-1"> 210 <div class="col-md-10 col-md-offset-1">
210 <div class="text-center"> 211 <div class="text-center">
211 <ul class="list-inline nav-justified"> 212 <ul class="list-inline nav-justified">
212 <li> 213 <li>
213 <ul id="view-table" class="list-inline text-right"> 214 <ul id="view-table" class="list-inline text-right">
214 - <li><h3 id="title-table">{{history_table}}</h3></li> 215 + <li><h3 id="title-table"></h3></li>
215 </ul> 216 </ul>
216 </li> 217 </li>
217 <li> 218 <li>
@@ -222,8 +223,9 @@ @@ -222,8 +223,9 @@
222 </li> 223 </li>
223 </ul> 224 </ul>
224 </div> 225 </div>
225 -  
226 - <div id="table_div"></div> 226 + <form id="google-chart-checkbox" action="" method="get">
  227 + <div id="table_div"></div>
  228 + </form>
227 <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 text-center"> 229 <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 text-center">
228 <ul class="pagination"> 230 <ul class="pagination">
229 231
@@ -231,44 +233,14 @@ @@ -231,44 +233,14 @@
231 </div> 233 </div>
232 </div> 234 </div>
233 </div> 235 </div>
234 - <!-- Modal (remember to change the ids!!!) -->  
235 - <div class="modal fade" id="send-message-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">  
236 - <div class="modal-dialog" role="document">  
237 - <div class="modal-content">  
238 - <!-- Modal Body -->  
239 - <div class="modal-body">  
240 - <!-- Put ONLY your content here!!! -->  
241 - <h3>{% trans "Message: " %}</h3>  
242 - <form id="text_chat_form" action="" method="GET">  
243 - <textarea id="message" name="message" rows="5" cols="80"></textarea>  
244 - </form>  
245 - </div>  
246 - <!-- Modal Footer -->  
247 - <div id="delete-category-footer"class="modal-footer">  
248 - <!-- Don't remove that!!! -->  
249 - <button type="button" class="btn btn-default btn-raised" data-dismiss="modal">{% trans "Close" %}</button>  
250 - <a href="javascript:void(0)" onclick="return sendMessage()" form="text_chat_form" class="btn btn-success btn-raised erase-button">{% trans "Send" %}</a>  
251 - </div>  
252 - </div>  
253 - </div>  
254 - </div>  
255 - 236 + <div id="modal-message"></div>
256 <div class="row"> 237 <div class="row">
257 <br><br> 238 <br><br>
258 </div> 239 </div>
259 </div> 240 </div>
260 241
261 <script type="text/javascript"> 242 <script type="text/javascript">
262 - $('#message').summernote({  
263 - dialogsInBody: true,  
264 - disableDragAndDrop: true,  
265 - height: 150,  
266 - toolbar: [  
267 - // [groupName, [list of button]]  
268 - ['style', ['bold', 'italic']],  
269 - ['insert', ['link']]  
270 - ]  
271 - }); 243 +
272 $("#title-table").text(search.length + " {% trans 'record(s)' %}"); 244 $("#title-table").text(search.length + " {% trans 'record(s)' %}");
273 function putpagination(data = json_history["data"], load_histoty = true){ 245 function putpagination(data = json_history["data"], load_histoty = true){
274 var len = Math.ceil(data.length / 20); 246 var len = Math.ceil(data.length / 20);
@@ -384,6 +356,15 @@ @@ -384,6 +356,15 @@
384 $(".active").removeClass("active"); 356 $(".active").removeClass("active");
385 $("#" + pag).addClass("active"); 357 $("#" + pag).addClass("active");
386 } 358 }
  359 +
  360 + function openmodal(){
  361 + $( "#modal-message" ).empty();
  362 + $.get( "{% url 'pdf_files:send_message' pdf_file.slug %}", function( data ) {
  363 + $( "#modal-message" ).append( data );
  364 + $("#send-message-modal").modal("show");
  365 + });
  366 + }
  367 +
387 function sendMessage(){ 368 function sendMessage(){
388 $("#send-message-modal").modal("hide"); 369 $("#send-message-modal").modal("hide");
389 var checked = $("#google-chart-checkbox").serializeArray(); 370 var checked = $("#google-chart-checkbox").serializeArray();
@@ -391,19 +372,36 @@ @@ -391,19 +372,36 @@
391 for (var i in checked){ 372 for (var i in checked){
392 email.push(checkbox[checked[i]["name"]]); 373 email.push(checkbox[checked[i]["name"]]);
393 } 374 }
394 - var message = $("#text_chat_form").serializeArray()[0]["value"]; 375 + $('<input />').attr('type', 'hidden')
  376 + .attr('name', "users[]")
  377 + .attr('value', email)
  378 + .appendTo('#text_chat_form');
  379 +
  380 + var formData = new FormData($('#text_chat_form').get(0));
395 $.ajax({ 381 $.ajax({
396 - type: "GET",  
397 - data: {"message":message,"users[]":email},  
398 - url: "{% url 'pdf_files:send_message' subject.slug %}",  
399 - success: function(msg){  
400 - console.log(msg);  
401 - $('#message').summernote("reset");  
402 - }  
403 - });  
404 - }  
405 - function openmodal(){  
406 - $("#send-message-modal").modal("show"); 382 + url: "{% url 'pdf_files:send_message' pdf_file.slug %}",
  383 + type: "POST",
  384 + data: formData,
  385 + cache: false,
  386 + processData: false,
  387 + contentType: false,
  388 + success: function(data) {
  389 + if (data["message"]){
  390 + console.log("success");
  391 + $("body").removeClass("modal-open");
  392 + $( "#modal-message" ).empty();
  393 + $(".modal-backdrop.fade.in").remove();
  394 + } else {
  395 + $( "#modal-message" ).empty();
  396 + $(".modal-backdrop.fade.in").remove();
  397 + $( "#modal-message" ).append( data );
  398 + $("#send-message-modal").modal("show");
  399 + }
  400 + },
  401 + error: function(data){
  402 + console.log("erro");
  403 + }
  404 + });
407 } 405 }
408 </script> 406 </script>
409 {% endblock %} 407 {% endblock %}
pdf_file/templates/pdf_file/send_message.html 0 → 100644
@@ -0,0 +1,112 @@ @@ -0,0 +1,112 @@
  1 +
  2 + {% load widget_tweaks i18n %}
  3 + <!-- Modal (remember to change the ids!!!) -->
  4 +<div class="modal fade" id="send-message-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  5 + <div class="modal-dialog" role="document">
  6 + <div class="modal-content">
  7 + <!-- Modal Body -->
  8 + <div class="modal-body">
  9 + <form id="text_chat_form" action="" method="POST" enctype="multipart/form-data">
  10 + {% csrf_token %}
  11 + {% comment %}Area para o Texto{% endcomment %}
  12 + <div class="form-group{% if form.has_error %} has-error {% endif %}">
  13 + <label for="{{ form.comment.auto_id }}">{{ form.comment.label }}: <span>*</span></label>
  14 + {% render_field form.comment class='form-control text_simple_wysiwyg' %}
  15 +
  16 + <span id="helpBlock" class="help-block">{{ form.comment.help_text }}</span>
  17 +
  18 + {% if form.comment.errors %}
  19 + <div class="alert alert-danger alert-dismissible" role="alert">
  20 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  21 + <span aria-hidden="true">&times;</span>
  22 + </button>
  23 + <ul>
  24 + {% for error in form.comment.errors %}
  25 + <li>{{ error }}</li>
  26 + {% endfor %}
  27 + </ul>
  28 + </div>
  29 + {% endif %}
  30 + </div>
  31 + {% comment %}Area para anexar a imagem {% endcomment %}
  32 + <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput">
  33 + {% render_field form.image %}
  34 +
  35 + <div class="filedrag">
  36 + {% trans 'Click or drop the picture here' %}<br />
  37 +
  38 + <small>{% trans 'The picture could not exceed 5MB.' %}</small>
  39 + </div>
  40 +
  41 + {% if form.image.errors %}
  42 + <div class="alert alert-danger alert-dismissible" role="alert">
  43 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  44 + <span aria-hidden="true">&times;</span>
  45 + </button>
  46 + <ul>
  47 + {% for error in form.image.errors %}
  48 + <li>{{ error }}</li>
  49 + {% endfor %}
  50 + </ul>
  51 + </div>
  52 + {% endif %}
  53 +
  54 + </div>
  55 + </form>
  56 + </div>
  57 + <!-- Modal Footer -->
  58 + <div id="delete-category-footer"class="modal-footer">
  59 + <!-- Don't remove that!!! -->
  60 + <button type="button" class="btn btn-default btn-raised" data-dismiss="modal">{% trans "Close" %}</button>
  61 + <a href="javascript:void(0)" onclick="return sendMessage()" form="text_chat_form" class="btn btn-success btn-raised erase-button">{% trans "Send" %}</a>
  62 + </div>
  63 + </div>
  64 + </div>
  65 +</div>
  66 +
  67 +<script type="text/javascript">
  68 +
  69 + $('.text_simple_wysiwyg').summernote({
  70 + dialogsInBody: true,
  71 + disableDragAndDrop: true,
  72 + height: 150,
  73 + toolbar: [
  74 + // [groupName, [list of button]]
  75 + ['style', ['bold', 'italic']],
  76 + ['insert', ['link']]
  77 + ]
  78 + });
  79 +
  80 + if (window.File && window.FileList && window.FileReader) {
  81 + Init();
  82 + }
  83 +
  84 + function Init() {
  85 + var small = $("#id_image"),
  86 + filedrag = $(".filedrag"),
  87 + common = $(".common-file-input");
  88 +
  89 + // file select
  90 + small.on("change", FileSelectHandler);
  91 +
  92 + // is XHR2 available?
  93 + var xhr = new XMLHttpRequest();
  94 + if (xhr.upload) {
  95 + // file drop
  96 + filedrag.on("drop", FileSelectHandler);
  97 + filedrag.attr('style', 'display:block');
  98 + common.attr('style', 'display:none');
  99 + }
  100 + }
  101 +
  102 + // file selection
  103 + function FileSelectHandler(e) {
  104 + var files = e.target.files || e.dataTransfer.files,
  105 + parent = $(e.target.offsetParent);
  106 +
  107 + // process all File objects
  108 + for (var i = 0, f; f = files[i]; i++) {
  109 + parent.find('.filedrag').html(f.name);
  110 + }
  111 + }
  112 +</script>
0 \ No newline at end of file 113 \ No newline at end of file
pdf_file/urls.py
@@ -4,10 +4,10 @@ from django.contrib.auth import views as auth_views @@ -4,10 +4,10 @@ from django.contrib.auth import views as auth_views
4 from . import views 4 from . import views
5 5
6 urlpatterns = [ 6 urlpatterns = [
7 - url(r'^create/(?P<slug>[\w_-]+)/$', views.PDFFileCreateView.as_view(), name='create'),  
8 - url(r'^update/(?P<topic_slug>[\w_-]+)/(?P<slug>[\w_-]+)/$', views.UpdateView.as_view(), name = 'update'),  
9 - url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteView.as_view(), name = 'delete'),  
10 - url(r'^view/(?P<slug>[\w_-]+)/$', views.ViewPDFFile.as_view(), name = 'view'),  
11 - url(r'^chart/(?P<slug>[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'),  
12 - url(r'^send-message/(?P<slug>[\w_-]+)/$', views.sendMessage, name = 'send_message'), 7 + url(r'^create/(?P<slug>[\w_-]+)/$', views.PDFFileCreateView.as_view(), name='create'),
  8 + url(r'^update/(?P<topic_slug>[\w_-]+)/(?P<slug>[\w_-]+)/$', views.UpdateView.as_view(), name = 'update'),
  9 + url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteView.as_view(), name = 'delete'),
  10 + url(r'^view/(?P<slug>[\w_-]+)/$', views.ViewPDFFile.as_view(), name = 'view'),
  11 + url(r'^chart/(?P<slug>[\w_-]+)/$', views.StatisticsView.as_view(), name = 'get_chart'),
  12 + url(r'^send-message/(?P<slug>[\w_-]+)/$', views.SendMessage.as_view(), name = 'send_message'),
13 ] 13 ]
pdf_file/views.py
@@ -19,6 +19,10 @@ from topics.models import Topic, Resource @@ -19,6 +19,10 @@ from topics.models import Topic, Resource
19 from .models import PDFFile 19 from .models import PDFFile
20 from pendencies.forms import PendenciesForm 20 from pendencies.forms import PendenciesForm
21 21
  22 +from chat.models import Conversation, TalkMessages
  23 +from users.models import User
  24 +from subjects.models import Subject
  25 +from webpage.forms import FormModalMessage
22 26
23 27
24 class ViewPDFFile(LoginRequiredMixin, LogMixin, generic.TemplateView): 28 class ViewPDFFile(LoginRequiredMixin, LogMixin, generic.TemplateView):
@@ -154,9 +158,6 @@ class PDFFileCreateView(LoginRequiredMixin, LogMixin , generic.CreateView): @@ -154,9 +158,6 @@ class PDFFileCreateView(LoginRequiredMixin, LogMixin , generic.CreateView):
154 if not self.object.topic.visible and not self.object.topic.repository: 158 if not self.object.topic.visible and not self.object.topic.repository:
155 self.object.visible = False 159 self.object.visible = False
156 160
157 - if form.cleaned_data["all_students"]:  
158 - self.object.students.add(*self.object.topic.subject.students.all())  
159 -  
160 self.object.save() 161 self.object.save()
161 162
162 pend_form = pendencies_form.save(commit = False) 163 pend_form = pendencies_form.save(commit = False)
@@ -412,6 +413,8 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): @@ -412,6 +413,8 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView):
412 context["init_date"] = start_date 413 context["init_date"] = start_date
413 context["end_date"] = end_date 414 context["end_date"] = end_date
414 alunos = pdf_file.students.all() 415 alunos = pdf_file.students.all()
  416 + if pdf_file.all_students :
  417 + alunos = pdf_file.topic.subject.students.all()
415 418
416 vis_ou = Log.objects.filter(context__contains={'pdffile_id':pdf_file.id},resource="pdffile",action="view",user_email__in=(aluno.email for aluno in alunos), datetime__range=(start_date,end_date + datetime.timedelta(minutes = 1))) 419 vis_ou = Log.objects.filter(context__contains={'pdffile_id':pdf_file.id},resource="pdffile",action="view",user_email__in=(aluno.email for aluno in alunos), datetime__range=(start_date,end_date + datetime.timedelta(minutes = 1)))
417 did,n_did,history = str(_("Realized")),str(_("Unrealized")),str(_("Historic")) 420 did,n_did,history = str(_("Realized")),str(_("Unrealized")),str(_("Historic"))
@@ -454,19 +457,42 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView): @@ -454,19 +457,42 @@ class StatisticsView(LoginRequiredMixin, LogMixin, generic.DetailView):
454 context["history_table"] = history 457 context["history_table"] = history
455 return context 458 return context
456 459
  460 +class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.FormView):
  461 + log_component = 'resources'
  462 + log_action = 'send'
  463 + log_resource = 'pdffile'
  464 + log_context = {}
  465 +
  466 + login_url = reverse_lazy("users:login")
  467 + redirect_field_name = 'next'
  468 +
  469 + template_name = 'pdf_file/send_message.html'
  470 + form_class = FormModalMessage
  471 +
  472 + def dispatch(self, request, *args, **kwargs):
  473 + slug = self.kwargs.get('slug', '')
  474 + pdf_file = get_object_or_404(PDFFile, slug = slug)
  475 + self.pdf_file = pdf_file
  476 +
  477 + if not has_subject_permissions(request.user, pdf_file.topic.subject):
  478 + return redirect(reverse_lazy('subjects:home'))
  479 +
  480 + return super(SendMessage, self).dispatch(request, *args, **kwargs)
  481 +
  482 + def form_valid(self, form):
  483 + message = form.cleaned_data.get('comment')
  484 + image = form.cleaned_data.get("image")
  485 + users = (self.request.POST.get('users[]','')).split(",")
  486 + user = self.request.user
  487 + subject = self.pdf_file.topic.subject
  488 + for u in users:
  489 + to_user = User.objects.get(email=u)
  490 + talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user)
  491 + created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject,image=image)
  492 + return JsonResponse({"message":"ok"})
  493 +
  494 + def get_context_data(self, **kwargs):
  495 + context = super(SendMessage,self).get_context_data()
  496 + context["pdf_file"] = get_object_or_404(PDFFile, slug=self.kwargs.get('slug', ''))
  497 + return context
457 498
458 -from chat.models import Conversation, TalkMessages  
459 -from users.models import User  
460 -from subjects.models import Subject  
461 -def sendMessage(request, slug):  
462 - message = request.GET.get('message','')  
463 - users = request.GET.getlist('users[]','')  
464 - user = request.user  
465 - subject = get_object_or_404(Subject,slug = slug)  
466 -  
467 - for u in users:  
468 - to_user = User.objects.get(email=u)  
469 - talk, create = Conversation.objects.get_or_create(user_one=user,user_two=to_user)  
470 - created = TalkMessages.objects.create(text=message,talk=talk,user=user,subject=subject)  
471 -  
472 - return JsonResponse({"message":"ok"})