Commit b2d33ad037a0e63b53afa151f43a0fc7a1b772c2

Authored by Jailson Dias
1 parent bccb1139

concertando modal e opção de deletar subject #376

courses/forms.py
@@ -5,7 +5,7 @@ class CourseForm(forms.ModelForm): @@ -5,7 +5,7 @@ class CourseForm(forms.ModelForm):
5 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 = { 5 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 = {
6 'category': forms.Select(), 'coordenator': forms.Select(), } 6 'category': forms.Select(), 'coordenator': forms.Select(), }
7 class UpdateCourseForm(CourseForm): 7 class UpdateCourseForm(CourseForm):
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): init_date = self.cleaned_data['init_date'] end_date = self.cleaned_data['end_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 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 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(), } 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 class TopicForm(forms.ModelForm): 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',) labels = { 'name': _('Name'), 'description': _('Description'), } help_texts = { 'name': _("Topic's name"), 'description': _("Topic's description"), } widgets = { 'description':SummernoteWidget(), }
courses/static/js/course.js
@@ -55,9 +55,11 @@ function subscribe(elem, url, id, confirm_message) { @@ -55,9 +55,11 @@ function subscribe(elem, url, id, confirm_message) {
55 55
56 var RemoveCourse = { 56 var RemoveCourse = {
57 remove: function(url,dados,id_li_link){ 57 remove: function(url,dados,id_li_link){
58 - $('#course').modal('hide'); 58 + $('#course').modal().hide();
59 $.post(url,dados, function(data){ 59 $.post(url,dados, function(data){
60 $(id_li_link).remove(); 60 $(id_li_link).remove();
  61 + // alert("certo");
  62 + $('body').removeClass('modal-open');
61 $("#modal_course").empty(); 63 $("#modal_course").empty();
62 $(".modal-backdrop.in").remove(); 64 $(".modal-backdrop.in").remove();
63 alertify.success("Course removed successfully!"); 65 alertify.success("Course removed successfully!");
courses/static/js/modal_subject.js
1 var RemoveSubject = { 1 var RemoveSubject = {
2 remove: function(url,dados,id_li_link){ 2 remove: function(url,dados,id_li_link){
3 - $('#subject').modal('hide'); 3 + $("#subject").modal('toggle');
4 $.post(url,dados, function(data){ 4 $.post(url,dados, function(data){
5 $(id_li_link).remove(); 5 $(id_li_link).remove();
6 - $("#modal_subject").empty();  
7 - $("#accordion").remove(); 6 + $('body').removeClass('modal-open');
  7 + $("#modal_course").empty();
8 $(".modal-backdrop.in").remove(); 8 $(".modal-backdrop.in").remove();
9 alertify.success("Subject removed successfully!"); 9 alertify.success("Subject removed successfully!");
10 - setTimeout(function () { location.reload(1); }, 2000);  
11 }).fail(function(){ 10 }).fail(function(){
12 - $("#modal_subject").empty();  
13 - $("#modal_subject").append(data); 11 + $("#modal_course").empty();
  12 + $("#modal_course").append(data);
14 $('#subject').modal('show'); 13 $('#subject').modal('show');
15 }); 14 });
16 } 15 }
17 } 16 }
18 -  
19 var delete_subject = { 17 var delete_subject = {
20 get: function (url, id_modal, id_div_modal){ 18 get: function (url, id_modal, id_div_modal){
21 $.get(url, function(data){ 19 $.get(url, function(data){
22 if($(id_modal).length){ 20 if($(id_modal).length){
23 $(id_div_modal).empty(); 21 $(id_div_modal).empty();
24 - $(id_div_modal).append(data);  
25 - } else {  
26 - $(id_div_modal).append(data);  
27 } 22 }
  23 + $(id_div_modal).append(data);
28 $(id_modal).modal('show'); 24 $(id_modal).modal('show');
29 }); 25 });
30 } 26 }
31 -};  
32 \ No newline at end of file 27 \ No newline at end of file
  28 +};
courses/templates/course/delete.html
@@ -34,5 +34,3 @@ @@ -34,5 +34,3 @@
34 </div> 34 </div>
35 </div> 35 </div>
36 </div> 36 </div>
37 -<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>  
38 -<script src="{% static 'js/course.js' %}"></script>  
courses/templates/course/view.html
@@ -64,7 +64,7 @@ alertify.success(&#39;{{message}}&#39;); @@ -64,7 +64,7 @@ alertify.success(&#39;{{message}}&#39;);
64 </div> 64 </div>
65 <div class="cards-detail"> 65 <div class="cards-detail">
66 {% for subject in subjects %} 66 {% for subject in subjects %}
67 - <div class="panel panel-default panel_{{ subject.id }}"> 67 + <div class="panel panel-default panel_{{ subject.id }}" id="subject_{{subject.slug}}">
68 <div class="panel-heading heading_{{subject.id}} subject ui-sortable-handle"> 68 <div class="panel-heading heading_{{subject.id}} subject ui-sortable-handle">
69 <div class="row"> 69 <div class="row">
70 <div class="col-xs-9 col-md-6 titleTopic"> 70 <div class="col-xs-9 col-md-6 titleTopic">
@@ -81,7 +81,7 @@ alertify.success(&#39;{{message}}&#39;); @@ -81,7 +81,7 @@ alertify.success(&#39;{{message}}&#39;);
81 <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> 81 <ul class="dropdown-menu pull-right" aria-labelledby="moreActions">
82 <li><a href="{% url 'course:replicate_subject' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Replicate" %}</a></li> 82 <li><a href="{% url 'course:replicate_subject' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Replicate" %}</a></li>
83 <li><a href="{% url 'course:update_subject' subject.slug %}"> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Edit" %}</a></li> 83 <li><a href="{% url 'course:update_subject' subject.slug %}"> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Edit" %}</a></li>
84 - <li><a href="{% url 'course:delete_subject' subject.slug %}" ><i class="fa fa-trash fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Remove" %}</a></li> 84 + <li><a href="javascript:delete_subject.get('{% url 'course:delete_subject' subject.slug %}?view=index','#subject','#modal_course')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i>&nbsp;{% trans 'Remove' %}</a></li>
85 </ul> 85 </ul>
86 </div> 86 </div>
87 </div> 87 </div>
courses/templates/subject/create.html
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
19 <label for="{{ field.auto_id }}"> {{ field.label }}</label> 19 <label for="{{ field.auto_id }}"> {{ field.label }}</label>
20 {% endif %} 20 {% endif %}
21 {% if field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%} 21 {% if field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%}
22 - <input type="text" class="form-control date-picker" name="{{field.name}}" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> 22 + {% render_field field class='form-control date-picker'%}
23 {% elif field.auto_id == 'id_visible' %} 23 {% elif field.auto_id == 'id_visible' %}
24 <div class="checkbox"> 24 <div class="checkbox">
25 <label> 25 <label>
@@ -30,6 +30,21 @@ @@ -30,6 +30,21 @@
30 {% render_field field class='form-control'%} 30 {% render_field field class='form-control'%}
31 {% endif %} 31 {% endif %}
32 <span class="help-block">{{ field.help_text }}</span> 32 <span class="help-block">{{ field.help_text }}</span>
  33 + {% if field.errors %}
  34 + <div class="row">
  35 + </br>
  36 + <div class="alert alert-danger alert-dismissible" role="alert">
  37 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  38 + <span aria-hidden="true">&times;</span>
  39 + </button>
  40 + <ul>
  41 + {% for error in field.errors %}
  42 + <li>{{ error }}</li>
  43 + {% endfor %}
  44 + </ul>
  45 + </div>
  46 + </div>
  47 + {% endif %}
33 </div> 48 </div>
34 {% endfor %} 49 {% endfor %}
35 <div class="col-lg-offset-4 col-lg-4"> 50 <div class="col-lg-offset-4 col-lg-4">
@@ -44,6 +59,7 @@ @@ -44,6 +59,7 @@
44 59
45 $('.date-picker').datepicker({ 60 $('.date-picker').datepicker({
46 language: locale, 61 language: locale,
  62 + startDate: "dateToday",
47 }); 63 });
48 </script> 64 </script>
49 {% endblock content %} 65 {% endblock content %}
courses/templates/subject/delete.html
@@ -22,15 +22,16 @@ @@ -22,15 +22,16 @@
22 <!-- Don't remove that!!! --> 22 <!-- Don't remove that!!! -->
23 <button type="button" class="btn btn-raised btn-default" data-dismiss="modal">{% trans "Close" %}</button> 23 <button type="button" class="btn btn-raised btn-default" data-dismiss="modal">{% trans "Close" %}</button>
24 <button type="submit" id="button" form="delete_form" class="btn btn-primary btn-raised">{% trans "Delete" %}</button> 24 <button type="submit" id="button" form="delete_form" class="btn btn-primary btn-raised">{% trans "Delete" %}</button>
25 - <script>  
26 - $("#delete_form").submit(function(event) {  
27 - RemoveCourse.remove("{% url 'course:delete_subject' subject.slug %}",$(this).serialize(),"#subject_{{subject.slug}}");  
28 - event.preventDefault();  
29 - });  
30 - </script> 25 +
  26 + {% if index %}
  27 + <script>
  28 + $("#delete_form").submit(function(event) {
  29 + RemoveSubject.remove("{% url 'course:delete_subject' subject.slug %}",$(this).serialize(),"#subject_{{subject.slug}}");
  30 + event.preventDefault();
  31 + });
  32 + </script>
  33 + {% endif %}
31 </div> 34 </div>
32 </div> 35 </div>
33 </div> 36 </div>
34 </div> 37 </div>
35 -<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>  
36 -<script src="{% static 'js/modal_subject.js' %}"></script>  
courses/templates/subject/index.html
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 <script type = "text/javascript" src="{% static 'js/topic_editation_presentation.js' %}"></script> 10 <script type = "text/javascript" src="{% static 'js/topic_editation_presentation.js' %}"></script>
11 <script type = "text/javascript" src="{% static 'js/links.js' %}"></script> 11 <script type = "text/javascript" src="{% static 'js/links.js' %}"></script>
12 <script src="{% static 'js/modal_poll.js' %}"></script> 12 <script src="{% static 'js/modal_poll.js' %}"></script>
  13 + <script src="{% static 'js/modal_subject.js' %}"></script>
13 {% endblock %} 14 {% endblock %}
14 15
15 {% block breadcrumbs %} 16 {% block breadcrumbs %}
@@ -35,7 +36,7 @@ @@ -35,7 +36,7 @@
35 <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> 36 <ul class="dropdown-menu pull-right" aria-labelledby="moreActions">
36 <li><a href="{% url 'course:replicate_subject' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Replicate" %}</a></li> 37 <li><a href="{% url 'course:replicate_subject' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Replicate" %}</a></li>
37 <li><a href="{% url 'course:update_subject' subject.slug %}"> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Edit" %}</a></li> 38 <li><a href="{% url 'course:update_subject' subject.slug %}"> <i class="fa fa-pencil fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Edit" %}</a></li>
38 - <li><a href="{% url 'course:delete_subject' subject.slug %}" ><i class="fa fa-trash fa-fw" aria-hidden="true"></i>&nbsp; {% trans "Remove" %}</a></li> 39 + <li><a href="javascript:delete_subject.get('{% url 'course:delete_subject' subject.slug %}?view=index','#subject','#modal_subject')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i>&nbsp;{% trans 'Remove' %}</a></li>
39 </ul> 40 </ul>
40 </div> 41 </div>
41 {% endif %} 42 {% endif %}
@@ -102,4 +103,7 @@ @@ -102,4 +103,7 @@
102 </div> 103 </div>
103 </div> 104 </div>
104 </div> 105 </div>
  106 + <div id="modal_subject">
  107 +
  108 + </div>
105 {% endblock %} 109 {% endblock %}
courses/templates/subject/update.html
1 {% extends 'subject/index.html' %} 1 {% extends 'subject/index.html' %}
2 2
3 -{% load static i18n permission_tags widget_tweaks django_bootstrap_breadcrumbs %} 3 +{% load static i18n permission_tags widget_tweaks django_bootstrap_breadcrumbs course_value_field %}
4 4
5 {% block breadcrumbs %} 5 {% block breadcrumbs %}
6 {{ block.super }} 6 {{ block.super }}
7 - {% breadcrumb 'Update subject' 'course:update_subject' %} 7 + {% breadcrumb 'Replicate subject' 'course:replicate_subject' %}
8 {% endblock breadcrumbs %} 8 {% endblock breadcrumbs %}
9 9
10 {% block content %} 10 {% block content %}
@@ -15,14 +15,45 @@ @@ -15,14 +15,45 @@
15 {% csrf_token %} 15 {% csrf_token %}
16 {% for field in form %} 16 {% for field in form %}
17 <div class="form-group {% if field.errors %} has-error{% endif %}"> 17 <div class="form-group {% if field.errors %} has-error{% endif %}">
18 - <label for="{{ field.auto_id }}" class="control-label label-static"> {{ field.label }}</label>  
19 - 18 + {% if field.auto_id != 'id_visible' %}
  19 + <label for="{{ field.auto_id }}"> {{ field.label }}</label>
  20 + {% endif %}
20 {% if field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%} 21 {% if field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%}
21 - <input type="text" class="form-control date-picker" name="{{field.name}}" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> 22 + {% render_field field class='form-control date-picker'%}
  23 + {% elif field.auto_id == 'id_visible' %}
  24 + {% value_subject_field subject field.name as value_field %}
  25 + <div class="checkbox">
  26 + <label>
  27 + <input type="checkbox" name="{{field.name}}" {% if value_field %}checked="checked"{% endif %}><span class="checkbox-material"></span> {{field.name}}
  28 + </label>
  29 + </div>
22 {% else %} 30 {% else %}
23 - {% render_field field class='form-control' placeholder=field.label%} 31 + {% if field.errors %}
  32 + {% render_field field class='form-control' %}
  33 + {% else %}
  34 + {% if field.auto_id == 'id_description'%}
  35 + <textarea class="form-control" cols="80" id="{{field.auto_id}}" name="{{field.name}}" rows="5">{{field.value}}</textarea>
  36 + {% else %}
  37 + {% render_field field class='form-control'%}
  38 + {% endif %}
  39 + {% endif %}
24 {% endif %} 40 {% endif %}
25 <span class="help-block">{{ field.help_text }}</span> 41 <span class="help-block">{{ field.help_text }}</span>
  42 + {% if field.errors %}
  43 + <div class="row">
  44 + </br>
  45 + <div class="alert alert-danger alert-dismissible" role="alert">
  46 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  47 + <span aria-hidden="true">&times;</span>
  48 + </button>
  49 + <ul>
  50 + {% for error in field.errors %}
  51 + <li>{{ error }}</li>
  52 + {% endfor %}
  53 + </ul>
  54 + </div>
  55 + </div>
  56 + {% endif %}
26 </div> 57 </div>
27 {% endfor %} 58 {% endfor %}
28 <div class="col-lg-offset-4 col-lg-4"> 59 <div class="col-lg-offset-4 col-lg-4">
@@ -37,6 +68,10 @@ @@ -37,6 +68,10 @@
37 68
38 $('.date-picker').datepicker({ 69 $('.date-picker').datepicker({
39 language: locale, 70 language: locale,
  71 + startDate: "dateToday",
  72 + });
  73 + $(document).ready(function() {
  74 + $('#id_description').summernote();
40 }); 75 });
41 </script> 76 </script>
42 {% endblock content %} 77 {% endblock content %}
courses/views.py
@@ -933,6 +933,10 @@ class DeleteSubjectView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.Dele @@ -933,6 +933,10 @@ class DeleteSubjectView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.Dele
933 context['subjects'] = self.object.course.subjects.filter(Q(visible=True) | Q(professors__in=[self.request.user])) 933 context['subjects'] = self.object.course.subjects.filter(Q(visible=True) | Q(professors__in=[self.request.user]))
934 if (has_role(self.request.user,'system_admin')): 934 if (has_role(self.request.user,'system_admin')):
935 context['subjects'] = self.object.course.subjects.all() 935 context['subjects'] = self.object.course.subjects.all()
  936 + if (self.request.GET.get('view') == 'index'):
  937 + context['index'] = True
  938 + else:
  939 + context['index'] = False
936 return context 940 return context
937 941
938 def get_success_url(self): 942 def get_success_url(self):