Commit 8a2587b55909bdfb78019e8a376e5e8ff72143b2

Authored by Jailson Dias
1 parent b2d33ad0

Ajustes no código de tópico, colocando para salvar as alterações feitas no tópic…

…o e colocando a mensagem de que o tópico foi atualizado com sucesso #377
courses/forms.py
... ... @@ -8,7 +8,7 @@ class UpdateCourseForm(CourseForm):
8 8 class Meta: model = Course fields = ('name', 'category', 'coordenator','public') labels = { 'name': _('Name'), 'category': _('Category'), 'coordenator': _('Coordenator'), 'public':_('Public'), } help_texts = { 'name': _('Course name'), 'coordenator': _('Course Coordenator'), 'public':_('To define if the course can be accessed by people not registered'), } widgets = { 'category': forms.Select(), 'coordenator': forms.Select(), } class SubjectForm(forms.ModelForm): def clean_end_date(self): end_date = self.cleaned_data['end_date'] if('init_date' in self.cleaned_data): init_date = self.cleaned_data['init_date'] if init_date and end_date and end_date < init_date: raise forms.ValidationError(_('The end date may not be before the start date.')) return end_date
9 9 class Meta: model = Subject fields = ('name', 'description','init_date', 'end_date', 'visible',) labels = { 'name': _('Name'), 'description': _('Description'), 'init_date': _('Start date'), 'end_date': _('End date'), 'visible': _('Is it visible?'), } help_texts = { 'name': _("Subjects's name"), 'description': _("Subjects's description"), 'init_date': _('Start date of the subject'), 'end_date': _('End date of the subject'), 'visible': _('Is the subject visible?'), } widgets = { 'description':SummernoteWidget(), }
10 10 class TopicForm(forms.ModelForm):
11   - class Meta: model = Topic fields = ('name', 'description',) labels = { 'name': _('Name'), 'description': _('Description'), } help_texts = { 'name': _("Topic's name"), 'description': _("Topic's description"), } widgets = { 'description':SummernoteWidget(), }
  11 + class Meta: model = Topic fields = ('name', 'description','visible') labels = { 'name': _('Name'), 'description': _('Description'), 'visible': _('Is the topic visible?'), } help_texts = { 'name': _("Topic's name"), 'description': _("Topic's description"), 'visible': _('Is it visible?'), } widgets = { 'description':SummernoteWidget(), }
12 12 class ActivityFileForm(forms.ModelForm): name = forms.CharField( required=False, max_length=100, widget=forms.TextInput(attrs={ 'placeholder': 'Nome', 'class': 'form-control' },)) pdf = forms.URLField(required=True, widget=S3DirectWidget( dest='activitys', html=(
13 13 '<div class="s3direct" data-policy-url="{policy_url}">' ' <a class="file-link" target="_blank" href="{file_url}">{file_name}</a>' ' <a class="file-remove" href="#remove">Remover</a>' ' <input class="file-url" type="hidden" value="{file_url}" id="{element_id}" name="{name}" />' ' <input class="file-dest" type="hidden" value="{dest}">' ' <input class="file-input" type="file" />' ' <div class="progress">' ' <div class="progress-bar progress-bar-success progress-bar-striped active bar">' ' </div>' ' </div>' '</div>' )))
14 14 class Meta: model = ActivityFile fields = ['pdf','name']
... ...
courses/static/js/topic.js
1   -function openTopic(url, topic, btn) {
2   - var icon = btn.find('i');
3   - var action = '', log_id;
4   -
5   - if (icon.hasClass('fa-angle-down')) {
6   - icon.removeClass('fa-angle-down');
7   - icon.addClass('fa-angle-up');
8   - action = 'open';
9   - log_id = -1;
10   - } else {
11   - icon.addClass('fa-angle-down');
12   - icon.removeClass('fa-angle-up');
13   - action = 'close';
14   - log_id = $(".topic_" + topic).find(".log_id").val();
  1 +var topic = {
  2 + get: function (url, id_div, faz){
  3 + if(!$(id_div + ' div').length || faz == 'true'){
  4 + $.get(url, function(data){
  5 + $(id_div).empty();
  6 + $(id_div).append(data);
  7 + });
15 8 }
16   -
17   - $.ajax({
18   - url: url,
19   - data: {"action": action, "log_id": log_id},
20   - dataType: 'json',
21   - success: function (data) {
22   - if (action == 'open') {
23   - $(".topic_" + topic).find(".log_id").val(data.log_id);
24   - }
25   - },
26   - error: function(data) {
27   - console.log('Error');
28   - }
29   - });
30   -}
31 9 \ No newline at end of file
  10 + },
  11 + post: function(url,dados,id_div){
  12 + $.post(url,dados, function(data){
  13 + $(id_div).empty();
  14 + $.ajax({
  15 + method: "get",
  16 + url: data['url'],
  17 + success: function(view){
  18 + $(id_div).append(view);
  19 + }
  20 + });
  21 + alertify.success("Topic updated successfully!");
  22 + }).fail(function(data){
  23 + $(id_div).empty();
  24 + $(id_div).append(data);
  25 + });
  26 + }
  27 +};
... ...
courses/static/js/topic_editation_presentation.js
... ... @@ -1,15 +0,0 @@
1   -
2   -$(document).ready(function(){
3   - $(".editation").hide();
4   -});
5   -
6   -function show_editation(id_topic){
7   - $(".presentation_"+ id_topic).hide();
8   - $(".editation_"+ id_topic).show();
9   - $(".editation_"+ id_topic).find('#summernote').summernote({height: 300});
10   -};
11   -
12   -function show_presentation(id_topic){
13   - $(".editation_"+ id_topic).hide();
14   - $(".presentation_"+ id_topic).show();
15   -};
courses/templates/subject/create.html
... ... @@ -11,7 +11,7 @@
11 11  
12 12 <div class="panel panel-default">
13 13 <div class="panel-body">
14   - <form class="form-group " method="post" action="">
  14 + <form class="" method="post" action="">
15 15 {% csrf_token %}
16 16 {% for field in form %}
17 17 <div class="form-group {% if field.errors %} has-error{% endif %}">
... ...
courses/templates/subject/form_view_teacher.html
1   -{% load static i18n list_topic_foruns permission_tags widget_tweaks professor_access list_topic_exercises %}
2   -
3   -<script type="text/javascript" src="{% static 'js/topic.js' %}"></script>
4   -
5   -<div class="panel panel-default cards-detail">
6   - <div class="panel-heading topic">
7   - <div class="row">
8   - <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}}">
9   - <button class="btn btn-default btn-sm caret-square" onclick="openTopic('{% url 'course:topic_log' topic.id %}', '{{topic.id}}', $(this));"><i class="fa fa-angle-down fa-2x" aria-hidden="true"></i></button>
10   - </div>
11   - <div class="col-xs-9 col-md-9 titleTopic Topic-detail">
12   - <a href="{% url 'course:view_topic' topic.slug %}" role="button">
13   - <h4>{{topic}}</h4>
14   - </a>
15   - </div><!--column -->
16   - <div class="col-xs-3 col-md-2 divMoreActions">
17   - <div class="btn-group">
18   - <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
19   - <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i>
20   - </button>
21   -
22   - {# dropdown de topic com as opções de replicar, editar e deletar #}
23   - {% professor_subject topic.subject user as dropdown_topic %}
24   - {% if dropdown_topic %}
25   - <ul class="dropdown-menu pull-right" aria-labelledby="moreActions">
26   - <li><a href="{% url 'course:replicate_topic' topic.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Replicate" %}</a></li>
27   - <li><a href="javascript:show_editation('{{topic.slug}}')"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Edit" %}</a></li>
28   - <li><a href="{% url 'course:delete_topic' topic.slug %}"><i class="fa fa-trash fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Remove" %}</a></li>
29   - </ul>
30   -
31   -
32   - {% endif %}
33   - </div>
34   - </div>
35   - </div>
36   - </div>
37   - <div class="panel-collapse collapseTopic-{{topic.slug}} topic_{{ topic.id }} collapse" role="tabpanel" aria-labelledby="heading_{{topic.id}}" aria-expanded="false" aria-hidden="true">
38   - <input type="hidden" class="log_id" />
39   - <div class="panel-body">
40   -
41   - {# dados do tópico no modo de visualização #}
42   - <div class="presentation_{{topic.slug}}">
43   - <p>
44   - <i>
45   - {{topic.description|safe}}
46   - </i>
47   - </p>
48   - </div>
49   -
50   - {# dados dos topicos no modo de edição #}
51   - <div class="form-group editation editation_{{topic.slug}}">
52   - <label class="control-label" for="focusedInput2">{% trans 'Name Topic' %}</label>
53   - <input type="text" class="form-control" value="{{topic}}">
54   - </div>
55   - <div class="form-group editation editation_{{topic.slug}}">
56   - <label class="control-label" for="focusedInput2">{% trans 'Description' %}</label>
57   - <textarea class="form-control" rows="3" id="summernote">{{topic.description}}</textarea>
58   - </div>
59   -
60   - {# materiais do topico#}
61   - <div class="row">
62   - <div class="col-xs-6 col-md-6">
63   - <div class="resource_inline">
64   - <h4>{% trans 'Material' %}</h4>
65   - </div>
66   - <div class="resource_inline">
67   -
68   - {# dropdown de create material #}
69   - <div class="dropdown">
70   - <a href="#" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i></a>
71   - <ul class="dropdown-menu" aria-labelledby="dLabel">
72   - <li><a href="javascript:modal.get('{% url 'course:links:create_link' topic.slug %}', '#createLinksModal','#requisicoes_ajax') ">{% trans 'Create a Link' %}</a></li>
73   - <li><a href="javascript:modal.get('{% url 'course:file:create_file' topic.slug %}', '#fileModal', '#requisicoes_ajax')">{% trans "Create a file" %}</a></li>
74   - </ul>
75   - </div>
76   - </div>
77   - <div class="presentation_{{topic.slug}}">
78   -
79   - {# materiais do tópico no modo de visualização #}
80   - <ul>
81   - {% list_topic_file request topic %}
82   - {% list_topic_link request topic%}
83   - </ul>
84   - </div>
85   - <div class="editation editation_{{topic.slug}}">
86   -
87   - {# materiais do tópico no modo de edição #}
88   - <ul>
89   - {% list_topic_file_edit request topic %}
90   - {% list_topic_link_edit request topic%}
91   - </ul>
92   - </div>
93   - </div>
94   -
95   - {# avaliações do topico #}
96   - <div class="col-xs-6 col-md-6">
97   - <div class="resource_inline">
98   - <h4>{% trans 'Activities' %}</h4>
99   - </div>
100   - <div class="resource_inline">
101   -
102   - {# dropdown de avaliações #}
103   - <div class="dropdown">
104   - <a href="#" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i></a>
105   - <ul class="dropdown-menu" aria-labelledby="dLabel">
106   - <li><a href="javascript:createForum('{% url 'course:forum:create' %}', '{{ topic.id }}')">{% trans 'Create Forum' %}</a></li>
107   - <li><a href="javascript:modal.get('{% url 'course:poll:create_poll' topic.slug%}','#poll','#requisicoes_ajax');">{% trans 'Create Poll' %}</a></li>
108   - <li><a href="javascript:modal.get('{% url 'course:exercise:create_exercise' topic.slug %}', '#createExercisesModal','#requisicoes_ajax')">{% trans 'Delivery Material' %}</a></li>
109   - <li><a href="{% url 'course:exam:create_exam' topic.slug %}">{% trans 'Create exam' %}</a></li>
110   - </ul>
111   - </div>
112   - </div>
113   - <div class="presentation_{{topic.slug}}">
114   -
115   - {# avaliações do tópico no modo de visualização #}
116   - <ul>
117   - {% list_topic_poll request topic %}
118   - {% list_topic_foruns request topic %}
119   - {% list_topic_exercise request topic %}
120   - </ul>
121   - </div>
122   - <div class="editation editation_{{topic.slug}}">
123   -
124   - {# avaliações do tópico no modo de edição #}
125   - <ul>
126   - {% list_topic_poll_teacher request topic %}
127   - {% list_topic_foruns request topic %}
128   - </ul>
129   - </div>
130   - </div>
131   - </div>
132   -
133   - {# opções de cancelar e editar no modo de edição #}
134   - <div class="form-group editation editation_{{topic.slug}}">
135   - <div class="col-md-10">
136   - <a href="javascript:show_presentation('{{topic.slug}}')" class="btn btn-raised btn-default">{% trans 'Back' %}</a>
137   - {# <a href="javascript:show_presentation('{{topic.slug}}')" class="btn btn-raised btn-primary">{% trans 'Submit' %}</a>#}
138   - </div>
139   - </div>
140   - </div>
141   - </div>
142   -</div>
  1 +{% load static i18n %}
143 2  
144 3 <!-- MODALs -->
145 4  
... ... @@ -215,5 +74,3 @@
215 74 </div>
216 75 </div>
217 76 <!-- EndModal -->
218   -
219   -
... ...
courses/templates/subject/index.html
... ... @@ -7,10 +7,10 @@
7 7 <script src="{% static 'js/file.js' %}"></script>
8 8 <script type="text/javascript" src="{% static 'js/material.js' %}"></script>
9 9 <script type="text/javascript" src="{% static 'js/modals_requisitions.js' %}"></script>
10   - <script type = "text/javascript" src="{% static 'js/topic_editation_presentation.js' %}"></script>
11 10 <script type = "text/javascript" src="{% static 'js/links.js' %}"></script>
12 11 <script src="{% static 'js/modal_poll.js' %}"></script>
13 12 <script src="{% static 'js/modal_subject.js' %}"></script>
  13 + <script type="text/javascript" src="{% static 'js/topic.js' %}"></script>
14 14 {% endblock %}
15 15  
16 16 {% block breadcrumbs %}
... ... @@ -64,12 +64,13 @@
64 64  
65 65 {# lista de tópicos #}
66 66 {% for topic in topics %}
67   - {% professor_subject topic.subject user as topic_professor%}
68   - {% if topic_professor %}
69   - {% include "subject/form_view_teacher.html" %}
70   - {% else %}
71   - {% include "subject/form_view_student.html" %}
72   - {% endif %}
  67 + {% include "topic/index.html" %}
  68 + {# {% professor_subject topic.subject user as topic_professor%}#}
  69 + {# {% if topic_professor %}#}
  70 + {# {% include "subject/form_view_teacher.html" %}#}
  71 + {# {% else %}#}
  72 + {# {% include "subject/form_view_student.html" %}#}
  73 + {# {% endif %}#}
73 74 {% endfor %}
74 75  
75 76 {# botão create topic #}
... ...
courses/templates/subject/update.html
... ... @@ -11,7 +11,7 @@
11 11  
12 12 <div class="panel panel-default">
13 13 <div class="panel-body">
14   - <form class="form-group " method="post" action="">
  14 + <form class="" method="post" action="">
15 15 {% csrf_token %}
16 16 {% for field in form %}
17 17 <div class="form-group {% if field.errors %} has-error{% endif %}">
... ...
courses/templates/topic/delete.html
1 1 {% load static i18n permission_tags %}
2 2  
3 3 <!-- Modal (remember to change the ids!!!) -->
4   -<div class="modal fade" id="subject" tabindex="-1" role="dialog" aria-labelledby="{{topic.slug}}_delete">
  4 +<div class="modal fade" id="topic_delete" tabindex="-1" role="dialog" aria-labelledby="{{topic.slug}}_delete">
5 5 <div class="modal-dialog" role="document">
6 6 <div class="modal-content">
7 7 <!-- Modal Header -->
... ... @@ -12,7 +12,7 @@
12 12 <!-- Modal Body -->
13 13 <div class="modal-body">
14 14 <!-- Put ONLY your content here!!! -->
15   - <form id="delete_topic_{{topic.slug}}" action="" method="post">
  15 + <form id="topic_form" action="" method="post">
16 16 {% csrf_token %}
17 17 <p>{% trans 'Are you sure you want to delete the topic' %} "{{topic.name}}"?</p>
18 18 </form>
... ... @@ -21,10 +21,8 @@
21 21 <div class="modal-footer">
22 22 <!-- Don't remove that!!! -->
23 23 <button type="button" class="btn btn-default btn-raised" data-dismiss="modal">{% trans "Close" %}</button>
24   - <button type="submit" id="button" form="delete_topic_{{topic.slug}}" class="btn btn-primary btn-raised">{% trans "Delete" %}</button>
  24 + <button type="submit" id="button" form="topic_form" class="btn btn-primary btn-raised">{% trans "Delete" %}</button>
25 25 </div>
26 26 </div>
27 27 </div>
28 28 </div>
29   -<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
30   -<script src="{% static 'js/modal_subject.js' %}"></script>
... ...
courses/templates/topic/index.html
1   -{% extends 'subject/index.html' %}
  1 +{% load i18n professor_access %}
2 2  
3   -{% load static i18n permission_tags professor_access django_bootstrap_breadcrumbs %}
4   -
5   -
6   -{% block javascript %}
7   - <script type="text/javascript" src="{% static 'js/forum.js' %}"></script>
8   - <script src="{% static 'js/file.js' %}"></script>
9   - <script type="text/javascript" src="{% static 'js/material.js' %}"></script>
10   - <script type = "text/javascript" src="{% static 'links.js' %}"></script>
11   -{% endblock %}
12   -
13   -
14   -{% block breadcrumbs %}
15   - {{ block.super }}
16   - {% breadcrumb topic.name 'course:view_topic' topic.slug %}
17   -{% endblock %}
  3 +<div class="panel panel-default cards-detail">
  4 + <div class="panel-heading topic">
  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>
  8 + </div>
  9 + <div class="col-xs-9 col-md-9 titleTopic Topic-detail">
  10 + <a role="button">
  11 + <h4>{{topic}}</h4>
  12 + </a>
  13 + </div><!--column -->
  14 + <div class="col-xs-3 col-md-2 divMoreActions">
  15 + <div class="btn-group">
  16 + <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  17 + <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i>
  18 + </button>
18 19  
19   -{% block content %}
20   -<div class="col-md-12 col-xs-12 col-sm-12">
21   -<div class="panel panel-info">
22   - <div class="panel-heading course">
23   - <div class="row">
24   - <div class="col-md-10 col-sm-7 titleTopic">
25   - <h4> {{topic.name}}</h4>
26   - </div>
27   - <div class="col-xs-4 col-md-2 divMoreActions">
28   - {% professor_subject subject user as permissions%}
29   - {% if permissions %}
30   - <div class="btn-group">
31   - <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
32   - <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i>
33   - </button>
34   - <ul class="dropdown-menu pull-right" aria-labelledby="moreActions">
35   - <li>
36   - <a href="{% url 'course:replicate_topic' topic.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Replicate" %}</a>
37   - </li>
38   - <li>
39   - <a href="{% url 'course:update_subject' subject.slug %}" data-toggle="modal" data-target="#editSubject"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Edit" %}</a>
40   - </li>
41   - <li><a href="{% url 'course:delete_topic' topic.slug %}"><i class="fa fa-trash fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Remove" %}</a></li>
42   - </ul>
43   - </div>
  20 + {# dropdown de topic com as opções de replicar, editar e deletar #}
  21 + {% professor_subject topic.subject user as dropdown_topic %}
  22 + {% if dropdown_topic %}
  23 + <ul class="dropdown-menu pull-right" aria-labelledby="moreActions">
  24 + <li><a href="{% url 'course:replicate_topic' topic.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Replicate" %}</a></li>
  25 + <li><a href="javascript:topic.get('{% url 'course:update_topic' topic.slug %}','#content_topic_{{topic.slug}}','true');"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Edit" %}</a></li>
  26 + <li><a href="{% url 'course:delete_topic' topic.slug %}"><i class="fa fa-trash fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Remove" %}</a></li>
  27 + </ul>
44 28 {% endif %}
45 29 </div>
46   - </div>
47   - </div>
48   - <div class="panel-body">
49   - <p>
50   - {{topic.description|safe}}
51   - </p>
  30 + </div>
52 31 </div>
53 32 </div>
54   - <div class="panel panel-default">
55   - <div class="panel-body">
56   - {% include "topic/topic_card.html" %}
57   - </div>
  33 + <div class="panel-collapse collapseTopic-{{topic.slug}} topic_{{ topic.id }} collapse" role="tabpanel" aria-labelledby="heading_{{topic.id}}" aria-expanded="false" aria-hidden="true">
  34 + <div class="panel-body" id="content_topic_{{topic.slug}}">
  35 +
58 36 </div>
59   -</div>
60   - <div class="col-md-6">
61   - <h3>{% trans 'Students - Specific Exercises' %}</h3>
62   - <br/>
63 37 </div>
64   - {# mostra a lista de usuários caso seja um professor ou admin #}
65   - {% if user|has_role:'professor' or user|has_role:'system_admin' %}
66   - {% for user in users %}
67   - {% include "exercise/card_list_user.html" %}
68   - {% endfor %}
69   - {% endif %}
70   - {# caso seja um estudante, mostra a lista de exercícios proposta a ele #}
71   - {% if user|has_role:'student'%}
72   - {% for exercise in exercises %}
73   - {% include "exercise/card_topic_exercises.html" %}
74   - {% endfor %}
75   - {% endif %}
76   -{% endblock %}
  38 +</div>
... ...
courses/templates/topic/list_topic_foruns.html
... ... @@ -2,4 +2,4 @@
2 2 {% for forum in foruns %}
3 3 <li><i class="fa fa-commenting" aria-hidden="true"></i> <a id="forum_{{ forum.id }}" href="{% url 'course:forum:view' forum.slug %}"> {{ forum }}</a></li>
4 4 {% endfor %}
5   -</div>
6 5 \ No newline at end of file
  6 +</div>
... ...
courses/templates/topic/update.html
1   -{% extends 'subject/index.html' %}
  1 +{% load static i18n list_topic_foruns permission_tags widget_tweaks professor_access list_topic_exercises course_value_field %}
2 2  
3   -{% load static i18n permission_tags widget_tweaks %}
4   -
5   -{% block content %}
  3 +<form class="" id="form_topic_update" method="post" action="">
  4 + {% csrf_token %}
  5 + {% for field in form %}
  6 + <div class="form-group {% if field.errors %} has-error{% endif %}">
  7 + {% if field.auto_id != 'id_visible' %}
  8 + <label for="{{ field.auto_id }}"> {{ field.label }}</label>
  9 + {% endif %}
  10 + {% if field.auto_id == 'id_visible' %}
  11 + {% value_topic_field topic field.name as value_field %}
  12 + <div class="">
  13 + <label>
  14 + <input type="checkbox" class="" name="{{field.name}}" {% if value_field %}checked="checked"{% endif %}><span class="checkbox-material"></span> {{field.name}}
  15 + </label>
  16 + </div>
  17 + {% else %}
  18 + {% if field.errors %}
  19 + {% render_field field class='form-control' %}
  20 + {% else %}
  21 + {% if field.auto_id == 'id_description'%}
  22 + <textarea class="form-control" cols="80" id="{{field.auto_id}}" name="{{field.name}}" rows="5">{{field.value}}</textarea>
  23 + {% else %}
  24 + {% render_field field class='form-control'%}
  25 + {% endif %}
  26 + {% endif %}
  27 + {% endif %}
  28 + <span class="help-block">{{ field.help_text }}</span>
  29 + {% if field.errors %}
  30 + <div class="row">
  31 + </br>
  32 + <div class="alert alert-danger alert-dismissible" role="alert">
  33 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  34 + <span aria-hidden="true">&times;</span>
  35 + </button>
  36 + <ul>
  37 + {% for error in field.errors %}
  38 + <li>{{ error }}</li>
  39 + {% endfor %}
  40 + </ul>
  41 + </div>
  42 + </div>
  43 + {% endif %}
  44 + </div>
  45 + {% endfor %}
  46 +</form>
6 47  
7   -<div class="panel panel-default">
8   - <div class="panel-body">
9   - <form class="form-group " method="post" action="">
10   - {% csrf_token %}
11   - {% for field in form %}
12   - <div class="form-group {% if field.errors %} has-error{% endif %}">
13   - <label for="{{ field.auto_id }}" class="control-label label-static"> {{ field.label }}</label>
  48 +<div class="row">
  49 + <div class="col-xs-6 col-md-6">
  50 + <div class="resource_inline">
  51 + <h4>{% trans 'Material' %}</h4>
  52 + </div>
  53 + <div class="resource_inline">
14 54  
15   - {% render_field field class='form-control' placeholder=field.label%}
16   - <span class="help-block">{{ field.help_text }}</span>
  55 + {# dropdown de create material #}
  56 + <div class="dropdown">
  57 + <a href="#" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i></a>
  58 + <ul class="dropdown-menu" aria-labelledby="dLabel">
  59 + <li><a href="javascript:modal.get('{% url 'course:links:create_link' topic.slug %}', '#createLinksModal','#requisicoes_ajax') ">{% trans 'Create a Link' %}</a></li>
  60 + <li><a href="javascript:modal.get('{% url 'course:file:create_file' topic.slug %}', '#fileModal', '#requisicoes_ajax')">{% trans "Create a file" %}</a></li>
  61 + </ul>
17 62 </div>
18   - {% endfor %}
19   - <div class="col-lg-offset-4 col-lg-4">
20   - <button type="submit" class="btn btn-raised btn-primary btn-lg btn-block">{% trans 'Update' %}</button>
  63 + </div>
  64 + <div class="editation editation_{{topic.slug}}">
  65 +
  66 + {# materiais do tópico no modo de edição #}
  67 + <ul>
  68 + {% list_topic_file_edit request topic %}
  69 + {% list_topic_link_edit request topic%}
  70 + </ul>
  71 + </div>
  72 + </div>
21 73  
  74 + {# avaliações do topico #}
  75 + <div class="col-xs-6 col-md-6">
  76 + <div class="resource_inline">
  77 + <h4>{% trans 'Activities' %}</h4>
  78 + </div>
  79 + <div class="resource_inline">
  80 +
  81 + {# dropdown de avaliações #}
  82 + <div class="dropdown">
  83 + <a href="#" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i></a>
  84 + <ul class="dropdown-menu" aria-labelledby="dLabel">
  85 + <li><a href="javascript:createForum('{% url 'course:forum:create' %}', '{{ topic.id }}')">{% trans 'Create Forum' %}</a></li>
  86 + <li><a href="javascript:modal.get('{% url 'course:poll:create_poll' topic.slug%}','#poll','#requisicoes_ajax');">{% trans 'Create Poll' %}</a></li>
  87 + <li><a href="javascript:modal.get('{% url 'course:exercise:create_exercise' topic.slug %}', '#createExercisesModal','#requisicoes_ajax')">{% trans 'Delivery Material' %}</a></li>
  88 + <li><a href="{% url 'course:exam:create_exam' topic.slug %}">{% trans 'Create exam' %}</a></li>
  89 + </ul>
22 90 </div>
23   - </form>
  91 + </div>
  92 + {# avaliações do tópico no modo de edição #}
  93 + <ul>
  94 + {% list_topic_poll_teacher request topic %}
  95 + {% list_topic_foruns request topic %}
  96 + </ul>
  97 + </div>
  98 +</div>
  99 +
  100 +<div class="form-group">
  101 + <div class="col-md-10">
  102 + <a href="javascript:topic.get('{% url 'course:view_topic' topic.slug %}','#content_topic_{{topic.slug}}','true');" class="btn btn-raised btn-default">{% trans 'Back' %}</a>
  103 + <button type="submite" form="form_topic_update" class="btn btn-raised btn-primary">{% trans 'Submit' %}</a>
24 104 </div>
25 105 </div>
26 106  
27   -{% endblock content %}
  107 +<script type="text/javascript">
  108 + $(document).ready(function() {
  109 + $('#id_description').summernote();
  110 + });
  111 + $("#form_topic_update").submit(function(event) {
  112 + topic.post("{% url 'course:update_topic' topic.slug %}",$(this).serialize(), '#content_topic_{{topic.slug}}');
  113 + event.preventDefault();
  114 + });
  115 +</script>
... ...
courses/templates/topic/view.html 0 → 100644
... ... @@ -0,0 +1,55 @@
  1 +{% load static i18n list_topic_foruns permission_tags widget_tweaks professor_access list_topic_exercises %}
  2 +<p>
  3 + <i>
  4 + {{topic.description|safe}}
  5 + </i>
  6 +</p>
  7 +<div class="row">
  8 + <div class="col-xs-6 col-md-6">
  9 + <div class="resource_inline">
  10 + <h4>{% trans 'Material' %}</h4>
  11 + </div>
  12 + <div class="resource_inline">
  13 +
  14 + {# dropdown de create material #}
  15 + <div class="dropdown">
  16 + <a href="#" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i></a>
  17 + <ul class="dropdown-menu" aria-labelledby="dLabel">
  18 + <li><a href="javascript:modal.get('{% url 'course:links:create_link' topic.slug %}', '#createLinksModal','#requisicoes_ajax') ">{% trans 'Create a Link' %}</a></li>
  19 + <li><a href="javascript:modal.get('{% url 'course:file:create_file' topic.slug %}', '#fileModal', '#requisicoes_ajax')">{% trans "Create a file" %}</a></li>
  20 + </ul>
  21 + </div>
  22 + </div>
  23 + {# materiais do tópico no modo de visualização #}
  24 + <ul>
  25 + {% list_topic_file request topic %}
  26 + {% list_topic_link request topic%}
  27 + </ul>
  28 + </div>
  29 +
  30 + {# avaliações do topico #}
  31 + <div class="col-xs-6 col-md-6">
  32 + <div class="resource_inline">
  33 + <h4>{% trans 'Activities' %}</h4>
  34 + </div>
  35 + <div class="resource_inline">
  36 +
  37 + {# dropdown de avaliações #}
  38 + <div class="dropdown">
  39 + <a href="#" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i></a>
  40 + <ul class="dropdown-menu" aria-labelledby="dLabel">
  41 + <li><a href="javascript:createForum('{% url 'course:forum:create' %}', '{{ topic.id }}')">{% trans 'Create Forum' %}</a></li>
  42 + <li><a href="javascript:modal.get('{% url 'course:poll:create_poll' topic.slug%}','#poll','#requisicoes_ajax');">{% trans 'Create Poll' %}</a></li>
  43 + <li><a href="javascript:modal.get('{% url 'course:exercise:create_exercise' topic.slug %}', '#createExercisesModal','#requisicoes_ajax')">{% trans 'Delivery Material' %}</a></li>
  44 + <li><a href="{% url 'course:exam:create_exam' topic.slug %}">{% trans 'Create exam' %}</a></li>
  45 + </ul>
  46 + </div>
  47 + </div>
  48 + {# avaliações do tópico no modo de visualização #}
  49 + <ul>
  50 + {% list_topic_poll request topic %}
  51 + {% list_topic_foruns request topic %}
  52 + {% list_topic_exercise request topic %}
  53 + </ul>
  54 + </div>
  55 +</div>
... ...
courses/templatetags/course_value_field.py
... ... @@ -60,3 +60,14 @@ def value_subject_field(subject, field):
60 60 elif field == 'visible':
61 61 value = subject.visible
62 62 return value
  63 +
  64 +@register.simple_tag
  65 +def value_topic_field(topic, field):
  66 + value = ""
  67 + if field == 'name':
  68 + value = topic.name
  69 + elif field == 'description':
  70 + value = topic.description
  71 + elif field == 'visible':
  72 + value = topic.visible
  73 + return value
... ...
courses/views.py
... ... @@ -26,6 +26,7 @@ from rolepermissions.verifications import has_role
26 26 from users.models import User
27 27 import operator
28 28 import time
  29 +from django.http import JsonResponse
29 30  
30 31 #API IMPORTS
31 32 from rest_framework import viewsets, permissions
... ... @@ -530,7 +531,6 @@ class UpdateCatView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView):
530 531 def get_success_url(self):
531 532 objeto = self.object.name
532 533 messages.success(self.request, _('Category "%s" updated successfully!')%(objeto))
533   - #return reverse_lazy('course:update_cat', kwargs={'slug' : self.object.slug})
534 534 return reverse_lazy('course:manage_cat')
535 535  
536 536 class DeleteCatView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView):
... ... @@ -633,7 +633,7 @@ class UploadMaterialView(LoginRequiredMixin, generic.edit.CreateView):
633 633  
634 634 return self.success_url
635 635  
636   -class TopicsView(LoginRequiredMixin, LogMixin, generic.ListView):
  636 +class TopicsView(LoginRequiredMixin, LogMixin, generic.TemplateView):
637 637 log_component = "course"
638 638 log_resource = "topic"
639 639 log_action = "viewed"
... ... @@ -641,8 +641,7 @@ class TopicsView(LoginRequiredMixin, LogMixin, generic.ListView):
641 641  
642 642 login_url = reverse_lazy("core:home")
643 643 redirect_field_name = 'next'
644   - template_name = 'topic/index.html'
645   - context_object_name = 'topics'
  644 + template_name = 'topic/view.html'
646 645 model = Topic
647 646  
648 647 def dispatch(self, *args, **kwargs):
... ... @@ -671,33 +670,12 @@ class TopicsView(LoginRequiredMixin, LogMixin, generic.ListView):
671 670 return super(TopicsView, self).dispatch(*args, **kwargs)
672 671  
673 672 def get_queryset(self):
674   - topic = get_object_or_404(Topic, slug = self.kwargs.get('slug'))
675   - subject = topic.subject
676   - topics_q = Topic.objects.filter(subject = subject, visible=True)
677   -
678   - return topics_q
  673 + return get_object_or_404(Topic, slug = self.kwargs.get('slug'))
679 674  
680 675 def get_context_data(self, **kwargs):
681 676 topic = get_object_or_404(Topic, slug = self.kwargs.get('slug'))
682 677 context = super(TopicsView, self).get_context_data(**kwargs)
683   - activitys = Activity.objects.filter(topic__name = topic.name)
684   - students_activit = User.objects.filter(activities__in = Activity.objects.all())
685   - materials = Material.objects.filter(topic = topic)
686   -
687   - users = User.objects.filter(subject_student__in = Subject.objects.all())
688   - context['users'] = users
689   - exercises = Exercise.objects.filter(Q(students=self.request.user)|Q(professors=self.request.user))
690   - context['exercises'] = exercises
691   -
692 678 context['topic'] = topic
693   - context['subject'] = topic.subject
694   - context['course'] = topic.subject.course
695   - context['activitys'] = activitys
696   - context['students_activit'] = students_activit
697   - context['materials'] = materials
698   - context['form'] = ActivityForm
699   - context['title'] = topic.name
700   -
701 679 return context
702 680  
703 681  
... ... @@ -769,22 +747,16 @@ class UpdateTopicView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.Update
769 747 topic = get_object_or_404(Topic, slug = self.kwargs.get('slug'))
770 748 if(not has_object_permission('edit_topic', self.request.user, topic)):
771 749 return self.handle_no_permission()
772   - return super(UpdateTopicView, self).dispatch(*args, **kwargs)
  750 + context = super(UpdateTopicView, self).dispatch(*args, **kwargs)
  751 + return context
773 752  
774 753 def get_object(self, queryset=None):
775 754 return get_object_or_404(Topic, slug = self.kwargs.get('slug'))
776 755  
777   - def get_success_url(self):
778   - return reverse_lazy('course:view_subject', kwargs={'slug' : self.object.subject.slug})
779   -
780 756 def get_context_data(self, **kwargs):
781 757 context = super(UpdateTopicView, self).get_context_data(**kwargs)
782 758 topic = get_object_or_404(Topic, slug = self.kwargs.get('slug'))
783   - context['course'] = topic.subject.course
784   - context['subject'] = topic.subject
785   - context['subjects'] = topic.subject.course.subjects.filter(Q(visible=True) | Q(professors__in=[self.request.user]))
786   - if (has_role(self.request.user,'system_admin')):
787   - context['subjects'] = topic.subject.course.subjects.all()
  759 + context['topic'] = topic
788 760 return context
789 761  
790 762 def form_valid(self, form):
... ... @@ -804,7 +776,7 @@ class UpdateTopicView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.Update
804 776  
805 777 super(UpdateTopicView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
806 778  
807   - return super(UpdateTopicView, self).form_valid(form)
  779 + return JsonResponse({'url': reverse_lazy('course:view_topic', kwargs={'slug' : self.object.slug})})
808 780  
809 781 class CreateSubjectView(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, generic.edit.CreateView):
810 782 log_component = "course"
... ...