From 0b1b57138dfb314142c7e0766ec9dad2f499fc62 Mon Sep 17 00:00:00 2001 From: Zambom Date: Thu, 8 Dec 2016 19:16:40 -0300 Subject: [PATCH] Changing topic structure to accordion --- courses/static/js/topic.js | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- courses/templates/subject/index.html | 8 +++++--- courses/templates/topic/index.html | 4 ++-- courses/templates/topic/view.html | 5 +++++ courses/views.py | 24 ++++++++++++++---------- 5 files changed, 106 insertions(+), 20 deletions(-) diff --git a/courses/static/js/topic.js b/courses/static/js/topic.js index dcaee37..72c532a 100644 --- a/courses/static/js/topic.js +++ b/courses/static/js/topic.js @@ -1,10 +1,67 @@ var topic = { - get: function (url, id_div, faz){ + get: function (button, url, id_div, faz){ if(!$(id_div + ' div').length || faz == 'true'){ - $.get(url, function(data){ - $(id_div).empty(); - $(id_div).append(data); - }); + var opened = $("#topics").find(".fa-angle-up"); + + if (opened.length > 0) { + opened.removeClass("fa-angle-up"); + opened.addClass("fa-angle-down"); + var op_topic = opened.parent().parent().parent().parent().parent(); + + var log_id = op_topic.find(".log_id").val(); + var log_url = op_topic.find(".log_url").val(); + + topicLog(log_url, log_id, 'close', id_div); + + op_topic.find(".loaded").val("false"); + } + + //Changing button icon + button.find("i").removeClass('fa-angle-down'); + button.find("i").addClass('fa-angle-up'); + + $.get(url, function(data){ + $(id_div).empty(); + $(id_div).append(data); + }); + } else { + var loaded = $(id_div).find(".loaded").val(); + + if (loaded == "true") { + var opened = $("#topics").find(".fa-angle-up"); + + opened.removeClass("fa-angle-up"); + opened.addClass("fa-angle-down"); + var op_topic = opened.parent().parent().parent().parent().parent(); + + var log_id = op_topic.find(".log_id").val(); + var log_url = op_topic.find(".log_url").val(); + + topicLog(log_url, log_id, 'close', id_div); + + $(id_div).find(".loaded").val("false"); + } else { + var opened = $("#topics").find(".fa-angle-up"); + + opened.removeClass("fa-angle-up"); + opened.addClass("fa-angle-down"); + var op_topic = opened.parent().parent().parent().parent().parent(); + + var log_id = op_topic.find(".log_id").val(); + var log_url = op_topic.find(".log_url").val(); + + topicLog(log_url, log_id, 'close', op_topic); + + op_topic.find(".loaded").val("false"); + + var opened = $(id_div).parent().parent().find(".fa-angle-down"); + opened.removeClass("fa-angle-down"); + opened.addClass("fa-angle-up"); + + var log_url = $(id_div).find(".log_url").val(); + + topicLog(log_url, 0, 'open', id_div); + } } }, post: function(url,dados,id_div){ @@ -35,3 +92,21 @@ var delete_topic = { }); } }; + +function topicLog(url, topic_log_id, action, topic_div) { + $.ajax({ + url: url, + data: {'action': action, 'log_id': topic_log_id}, + dataType: 'json', + success: function (data) { + if (action == 'open') { + $(topic_div).find(".log_id").val(data.log_id); + $(topic_div).find(".loaded").val("true"); + } + }, + error: function(data) { + console.log('Error: '); + console.log(data); + } + }) +} \ No newline at end of file diff --git a/courses/templates/subject/index.html b/courses/templates/subject/index.html index 421a206..e19176c 100644 --- a/courses/templates/subject/index.html +++ b/courses/templates/subject/index.html @@ -63,15 +63,17 @@ {# lista de tópicos #} - {% for topic in topics %} - {% include "topic/index.html" %} +
+ {% for topic in topics %} + {% include "topic/index.html" %} {# {% professor_subject topic.subject user as topic_professor%}#} {# {% if topic_professor %}#} {# {% include "subject/form_view_teacher.html" %}#} {# {% else %}#} {# {% include "subject/form_view_student.html" %}#} {# {% endif %}#} - {% endfor %} + {% endfor %} +
{# botão create topic #} {% professor_subject subject user as professor_sub %} diff --git a/courses/templates/topic/index.html b/courses/templates/topic/index.html index 8cd20a0..983efa3 100644 --- a/courses/templates/topic/index.html +++ b/courses/templates/topic/index.html @@ -3,8 +3,8 @@
-