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 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 6 'category': forms.Select(), 'coordenator': forms.Select(), }
7 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 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 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 55  
56 56 var RemoveCourse = {
57 57 remove: function(url,dados,id_li_link){
58   - $('#course').modal('hide');
  58 + $('#course').modal().hide();
59 59 $.post(url,dados, function(data){
60 60 $(id_li_link).remove();
  61 + // alert("certo");
  62 + $('body').removeClass('modal-open');
61 63 $("#modal_course").empty();
62 64 $(".modal-backdrop.in").remove();
63 65 alertify.success("Course removed successfully!");
... ...
courses/static/js/modal_subject.js
1 1 var RemoveSubject = {
2 2 remove: function(url,dados,id_li_link){
3   - $('#subject').modal('hide');
  3 + $("#subject").modal('toggle');
4 4 $.post(url,dados, function(data){
5 5 $(id_li_link).remove();
6   - $("#modal_subject").empty();
7   - $("#accordion").remove();
  6 + $('body').removeClass('modal-open');
  7 + $("#modal_course").empty();
8 8 $(".modal-backdrop.in").remove();
9 9 alertify.success("Subject removed successfully!");
10   - setTimeout(function () { location.reload(1); }, 2000);
11 10 }).fail(function(){
12   - $("#modal_subject").empty();
13   - $("#modal_subject").append(data);
  11 + $("#modal_course").empty();
  12 + $("#modal_course").append(data);
14 13 $('#subject').modal('show');
15 14 });
16 15 }
17 16 }
18   -
19 17 var delete_subject = {
20 18 get: function (url, id_modal, id_div_modal){
21 19 $.get(url, function(data){
22 20 if($(id_modal).length){
23 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 24 $(id_modal).modal('show');
29 25 });
30 26 }
31   -};
32 27 \ No newline at end of file
  28 +};
... ...
courses/templates/course/delete.html
... ... @@ -34,5 +34,3 @@
34 34 </div>
35 35 </div>
36 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 64 </div>
65 65 <div class="cards-detail">
66 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 68 <div class="panel-heading heading_{{subject.id}} subject ui-sortable-handle">
69 69 <div class="row">
70 70 <div class="col-xs-9 col-md-6 titleTopic">
... ... @@ -81,7 +81,7 @@ alertify.success(&#39;{{message}}&#39;);
81 81 <ul class="dropdown-menu pull-right" aria-labelledby="moreActions">
82 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 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 85 </ul>
86 86 </div>
87 87 </div>
... ...
courses/templates/subject/create.html
... ... @@ -19,7 +19,7 @@
19 19 <label for="{{ field.auto_id }}"> {{ field.label }}</label>
20 20 {% endif %}
21 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 23 {% elif field.auto_id == 'id_visible' %}
24 24 <div class="checkbox">
25 25 <label>
... ... @@ -30,6 +30,21 @@
30 30 {% render_field field class='form-control'%}
31 31 {% endif %}
32 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 48 </div>
34 49 {% endfor %}
35 50 <div class="col-lg-offset-4 col-lg-4">
... ... @@ -44,6 +59,7 @@
44 59  
45 60 $('.date-picker').datepicker({
46 61 language: locale,
  62 + startDate: "dateToday",
47 63 });
48 64 </script>
49 65 {% endblock content %}
... ...
courses/templates/subject/delete.html
... ... @@ -22,15 +22,16 @@
22 22 <!-- Don't remove that!!! -->
23 23 <button type="button" class="btn btn-raised btn-default" data-dismiss="modal">{% trans "Close" %}</button>
24 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 34 </div>
32 35 </div>
33 36 </div>
34 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 10 <script type = "text/javascript" src="{% static 'js/topic_editation_presentation.js' %}"></script>
11 11 <script type = "text/javascript" src="{% static 'js/links.js' %}"></script>
12 12 <script src="{% static 'js/modal_poll.js' %}"></script>
  13 + <script src="{% static 'js/modal_subject.js' %}"></script>
13 14 {% endblock %}
14 15  
15 16 {% block breadcrumbs %}
... ... @@ -35,7 +36,7 @@
35 36 <ul class="dropdown-menu pull-right" aria-labelledby="moreActions">
36 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 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 40 </ul>
40 41 </div>
41 42 {% endif %}
... ... @@ -102,4 +103,7 @@
102 103 </div>
103 104 </div>
104 105 </div>
  106 + <div id="modal_subject">
  107 +
  108 + </div>
105 109 {% endblock %}
... ...
courses/templates/subject/update.html
1 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 5 {% block breadcrumbs %}
6 6 {{ block.super }}
7   - {% breadcrumb 'Update subject' 'course:update_subject' %}
  7 + {% breadcrumb 'Replicate subject' 'course:replicate_subject' %}
8 8 {% endblock breadcrumbs %}
9 9  
10 10 {% block content %}
... ... @@ -15,14 +15,45 @@
15 15 {% csrf_token %}
16 16 {% for field in form %}
17 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 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 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 40 {% endif %}
25 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 57 </div>
27 58 {% endfor %}
28 59 <div class="col-lg-offset-4 col-lg-4">
... ... @@ -37,6 +68,10 @@
37 68  
38 69 $('.date-picker').datepicker({
39 70 language: locale,
  71 + startDate: "dateToday",
  72 + });
  73 + $(document).ready(function() {
  74 + $('#id_description').summernote();
40 75 });
41 76 </script>
42 77 {% endblock content %}
... ...
courses/views.py
... ... @@ -933,6 +933,10 @@ class DeleteSubjectView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.Dele
933 933 context['subjects'] = self.object.course.subjects.filter(Q(visible=True) | Q(professors__in=[self.request.user]))
934 934 if (has_role(self.request.user,'system_admin')):
935 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 940 return context
937 941  
938 942 def get_success_url(self):
... ...