Commit 0b1b57138dfb314142c7e0766ec9dad2f499fc62
1 parent
eb825b80
Exists in
master
and in
5 other branches
Changing topic structure to accordion
Showing
5 changed files
with
106 additions
and
20 deletions
Show diff stats
courses/static/js/topic.js
1 | 1 | var topic = { |
2 | - get: function (url, id_div, faz){ | |
2 | + get: function (button, url, id_div, faz){ | |
3 | 3 | if(!$(id_div + ' div').length || faz == 'true'){ |
4 | - $.get(url, function(data){ | |
5 | - $(id_div).empty(); | |
6 | - $(id_div).append(data); | |
7 | - }); | |
4 | + var opened = $("#topics").find(".fa-angle-up"); | |
5 | + | |
6 | + if (opened.length > 0) { | |
7 | + opened.removeClass("fa-angle-up"); | |
8 | + opened.addClass("fa-angle-down"); | |
9 | + var op_topic = opened.parent().parent().parent().parent().parent(); | |
10 | + | |
11 | + var log_id = op_topic.find(".log_id").val(); | |
12 | + var log_url = op_topic.find(".log_url").val(); | |
13 | + | |
14 | + topicLog(log_url, log_id, 'close', id_div); | |
15 | + | |
16 | + op_topic.find(".loaded").val("false"); | |
17 | + } | |
18 | + | |
19 | + //Changing button icon | |
20 | + button.find("i").removeClass('fa-angle-down'); | |
21 | + button.find("i").addClass('fa-angle-up'); | |
22 | + | |
23 | + $.get(url, function(data){ | |
24 | + $(id_div).empty(); | |
25 | + $(id_div).append(data); | |
26 | + }); | |
27 | + } else { | |
28 | + var loaded = $(id_div).find(".loaded").val(); | |
29 | + | |
30 | + if (loaded == "true") { | |
31 | + var opened = $("#topics").find(".fa-angle-up"); | |
32 | + | |
33 | + opened.removeClass("fa-angle-up"); | |
34 | + opened.addClass("fa-angle-down"); | |
35 | + var op_topic = opened.parent().parent().parent().parent().parent(); | |
36 | + | |
37 | + var log_id = op_topic.find(".log_id").val(); | |
38 | + var log_url = op_topic.find(".log_url").val(); | |
39 | + | |
40 | + topicLog(log_url, log_id, 'close', id_div); | |
41 | + | |
42 | + $(id_div).find(".loaded").val("false"); | |
43 | + } else { | |
44 | + var opened = $("#topics").find(".fa-angle-up"); | |
45 | + | |
46 | + opened.removeClass("fa-angle-up"); | |
47 | + opened.addClass("fa-angle-down"); | |
48 | + var op_topic = opened.parent().parent().parent().parent().parent(); | |
49 | + | |
50 | + var log_id = op_topic.find(".log_id").val(); | |
51 | + var log_url = op_topic.find(".log_url").val(); | |
52 | + | |
53 | + topicLog(log_url, log_id, 'close', op_topic); | |
54 | + | |
55 | + op_topic.find(".loaded").val("false"); | |
56 | + | |
57 | + var opened = $(id_div).parent().parent().find(".fa-angle-down"); | |
58 | + opened.removeClass("fa-angle-down"); | |
59 | + opened.addClass("fa-angle-up"); | |
60 | + | |
61 | + var log_url = $(id_div).find(".log_url").val(); | |
62 | + | |
63 | + topicLog(log_url, 0, 'open', id_div); | |
64 | + } | |
8 | 65 | } |
9 | 66 | }, |
10 | 67 | post: function(url,dados,id_div){ |
... | ... | @@ -35,3 +92,21 @@ var delete_topic = { |
35 | 92 | }); |
36 | 93 | } |
37 | 94 | }; |
95 | + | |
96 | +function topicLog(url, topic_log_id, action, topic_div) { | |
97 | + $.ajax({ | |
98 | + url: url, | |
99 | + data: {'action': action, 'log_id': topic_log_id}, | |
100 | + dataType: 'json', | |
101 | + success: function (data) { | |
102 | + if (action == 'open') { | |
103 | + $(topic_div).find(".log_id").val(data.log_id); | |
104 | + $(topic_div).find(".loaded").val("true"); | |
105 | + } | |
106 | + }, | |
107 | + error: function(data) { | |
108 | + console.log('Error: '); | |
109 | + console.log(data); | |
110 | + } | |
111 | + }) | |
112 | +} | |
38 | 113 | \ No newline at end of file | ... | ... |
courses/templates/subject/index.html
... | ... | @@ -63,15 +63,17 @@ |
63 | 63 | </div> |
64 | 64 | |
65 | 65 | {# lista de tópicos #} |
66 | - {% for topic in topics %} | |
67 | - {% include "topic/index.html" %} | |
66 | + <div class="panel-group" id="topics" role="tablist" aria-multiselectable="true"> | |
67 | + {% for topic in topics %} | |
68 | + {% include "topic/index.html" %} | |
68 | 69 | {# {% professor_subject topic.subject user as topic_professor%}#} |
69 | 70 | {# {% if topic_professor %}#} |
70 | 71 | {# {% include "subject/form_view_teacher.html" %}#} |
71 | 72 | {# {% else %}#} |
72 | 73 | {# {% include "subject/form_view_student.html" %}#} |
73 | 74 | {# {% endif %}#} |
74 | - {% endfor %} | |
75 | + {% endfor %} | |
76 | + </div> | |
75 | 77 | |
76 | 78 | {# botão create topic #} |
77 | 79 | {% professor_subject subject user as professor_sub %} | ... | ... |
courses/templates/topic/index.html
... | ... | @@ -3,8 +3,8 @@ |
3 | 3 | <div class="panel panel-default cards-detail"> |
4 | 4 | <div class="panel-heading topic"> |
5 | 5 | <div class="row"> |
6 | - <div class="col-md-1 moreAccordion" data-toggle="collapse" data-parent="#accordion-{{topic.slug}}" href=".collapseTopic-{{topic.slug}}" aria-expanded="false" aria-controls="collapseTopic-{{topic.slug}}"> | |
7 | - <button class="btn btn-default btn-sm caret-square" onclick="topic.get('{% url 'course:view_topic' topic.slug %}', '#content_topic_{{topic.slug}}', 'false');"><i class="fa fa-angle-down fa-2x" aria-hidden="true"></i></button> | |
6 | + <div class="col-md-1 moreAccordion" data-toggle="collapse" data-parent="#topics" href=".collapseTopic-{{topic.slug}}" aria-expanded="false" aria-controls="collapseTopic-{{topic.slug}}"> | |
7 | + <button class="btn btn-default btn-sm caret-square" onclick="topic.get($(this), '{% url 'course:view_topic' topic.slug %}', '#content_topic_{{topic.slug}}', 'false');"><i class="fa fa-angle-down fa-2x" aria-hidden="true"></i></button> | |
8 | 8 | </div> |
9 | 9 | <div class="col-xs-9 col-md-9 titleTopic Topic-detail"> |
10 | 10 | <a role="button"> | ... | ... |
courses/templates/topic/view.html
1 | 1 | {% load static i18n list_topic_foruns permission_tags widget_tweaks professor_access list_topic_exercises %} |
2 | +<!-- Block with Log info --> | |
3 | +<input type="hidden" class="log_id" value="{{ topic_log_id }}" /> | |
4 | +<input type="hidden" class="log_url" value="{% url 'course:topic_log' topic.id %}" /> | |
5 | +<input type="hidden" class="loaded" value="true" /> | |
6 | +<!-- Endblock --> | |
2 | 7 | <p> |
3 | 8 | <i> |
4 | 9 | {{topic.description|safe}} | ... | ... |
courses/views.py
... | ... | @@ -650,6 +650,19 @@ class TopicsView(LoginRequiredMixin, LogMixin, generic.TemplateView): |
650 | 650 | if(not has_object_permission('view_topic', self.request.user, topic)): |
651 | 651 | return self.handle_no_permission() |
652 | 652 | |
653 | + return super(TopicsView, self).dispatch(*args, **kwargs) | |
654 | + | |
655 | + def get_queryset(self): | |
656 | + return get_object_or_404(Topic, slug = self.kwargs.get('slug')) | |
657 | + | |
658 | + def get_context_data(self, **kwargs): | |
659 | + topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) | |
660 | + context = super(TopicsView, self).get_context_data(**kwargs) | |
661 | + context['topic'] = topic | |
662 | + | |
663 | + if(not has_object_permission('view_topic', self.request.user, topic)): | |
664 | + return self.handle_no_permission() | |
665 | + | |
653 | 666 | self.log_context['topic_id'] = topic.id |
654 | 667 | self.log_context['topic_name'] = topic.name |
655 | 668 | self.log_context['topic_slug'] = topic.slug |
... | ... | @@ -665,17 +678,8 @@ class TopicsView(LoginRequiredMixin, LogMixin, generic.TemplateView): |
665 | 678 | |
666 | 679 | super(TopicsView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
667 | 680 | |
668 | - self.request.session['log_id'] = Log.objects.latest('id').id | |
669 | - | |
670 | - return super(TopicsView, self).dispatch(*args, **kwargs) | |
681 | + context['topic_log_id'] = Log.objects.latest('id').id | |
671 | 682 | |
672 | - def get_queryset(self): | |
673 | - return get_object_or_404(Topic, slug = self.kwargs.get('slug')) | |
674 | - | |
675 | - def get_context_data(self, **kwargs): | |
676 | - topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) | |
677 | - context = super(TopicsView, self).get_context_data(**kwargs) | |
678 | - context['topic'] = topic | |
679 | 683 | return context |
680 | 684 | |
681 | 685 | ... | ... |