Commit a4d0a0ff3c9a31ee63a5c99f4ae15dd60481a046
1 parent
4e06051e
Exists in
master
and in
5 other branches
improviment detail course #214
Showing
8 changed files
with
132 additions
and
75 deletions
Show diff stats
courses/static/js/course.js
| ... | ... | @@ -49,27 +49,41 @@ function subscribe(elem, url, id, confirm_message) { |
| 49 | 49 | |
| 50 | 50 | /* |
| 51 | 51 | * |
| 52 | -* Function to delete a course | |
| 52 | +* Function to delete a course | |
| 53 | 53 | * |
| 54 | 54 | */ |
| 55 | -function delete_course(url, course, message, return_url) { | |
| 56 | - alertify.confirm(message, function(){ | |
| 57 | - var csrftoken = getCookie('csrftoken'); | |
| 58 | 55 | |
| 59 | - $.ajax({ | |
| 60 | - method: 'post', | |
| 61 | - beforeSend: function (request) { | |
| 62 | - request.setRequestHeader('X-CSRFToken', csrftoken); | |
| 63 | - }, | |
| 64 | - url: url, | |
| 65 | - success: function(data) { | |
| 66 | - alertify.alert('Remove Course', 'Course removed successfully!', function(){ | |
| 67 | - window.location.href = return_url; | |
| 68 | - }); | |
| 69 | - } | |
| 70 | - }); | |
| 71 | - }); | |
| 56 | +var RemoveCourse = { | |
| 57 | + remove: function(url,dados,id_li_link){ | |
| 58 | + $('#course').modal('hide'); | |
| 59 | + $.post(url,dados, function(data){ | |
| 60 | + $(id_li_link).remove(); | |
| 61 | + $("#modal_course").empty(); | |
| 62 | + $("#accordion").remove(); | |
| 63 | + $(".modal-backdrop.in").remove(); | |
| 64 | + alertify.success("Course removed successfully!"); | |
| 65 | + setTimeout(function () { location.reload(1); }, 2000); | |
| 66 | + }).fail(function(){ | |
| 67 | + $("#modal_course").empty(); | |
| 68 | + $("#modal_course").append(data); | |
| 69 | + $('#course').modal('show'); | |
| 70 | + }); | |
| 71 | + } | |
| 72 | 72 | } |
| 73 | + | |
| 74 | +var delete_course = { | |
| 75 | + get: function (url, id_modal, id_div_modal){ | |
| 76 | + $.get(url, function(data){ | |
| 77 | + if($(id_modal).length){ | |
| 78 | + $(id_div_modal).empty(); | |
| 79 | + $(id_div_modal).append(data); | |
| 80 | + } else { | |
| 81 | + $(id_div_modal).append(data); | |
| 82 | + } | |
| 83 | + $(id_modal).modal('show'); | |
| 84 | + }); | |
| 85 | + } | |
| 86 | +}; | |
| 73 | 87 | /* |
| 74 | 88 | * |
| 75 | 89 | * Function to load create course's form | ... | ... |
| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | +var RemoveSubject = { | |
| 2 | + remove: function(url,dados,id_li_link){ | |
| 3 | + $('#subject').modal('hide'); | |
| 4 | + $.post(url,dados, function(data){ | |
| 5 | + $(id_li_link).remove(); | |
| 6 | + $("#modal_subject").empty(); | |
| 7 | + $("#accordion").remove(); | |
| 8 | + $(".modal-backdrop.in").remove(); | |
| 9 | + alertify.success("Subject removed successfully!"); | |
| 10 | + setTimeout(function () { location.reload(1); }, 2000); | |
| 11 | + }).fail(function(){ | |
| 12 | + $("#modal_subject").empty(); | |
| 13 | + $("#modal_subject").append(data); | |
| 14 | + $('#subject').modal('show'); | |
| 15 | + }); | |
| 16 | + } | |
| 17 | +} | |
| 18 | + | |
| 19 | +var delete_subject = { | |
| 20 | + get: function (url, id_modal, id_div_modal){ | |
| 21 | + $.get(url, function(data){ | |
| 22 | + if($(id_modal).length){ | |
| 23 | + $(id_div_modal).empty(); | |
| 24 | + $(id_div_modal).append(data); | |
| 25 | + } else { | |
| 26 | + $(id_div_modal).append(data); | |
| 27 | + } | |
| 28 | + $(id_modal).modal('show'); | |
| 29 | + }); | |
| 30 | + } | |
| 31 | +}; | |
| 0 | 32 | \ No newline at end of file | ... | ... |
courses/templates/category/delete.html
| 1 | +{% load static i18n permission_tags %} | |
| 1 | 2 | |
| 2 | -{% extends 'course/view.html' %} | |
| 3 | +<!-- Modal (remember to change the ids!!!) --> | |
| 4 | +<div class="modal fade" id="course" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
| 5 | + <div class="modal-dialog" role="document"> | |
| 6 | + <div class="modal-content"> | |
| 7 | + <!-- Modal Header --> | |
| 8 | + <div class="modal-header"> | |
| 3 | 9 | |
| 4 | -{% load static i18n %} | |
| 5 | - | |
| 6 | -{% block breadcrumbs %} | |
| 7 | - <ol class="breadcrumb"> | |
| 8 | - <li><a href="{% url 'app:index' %}">{% trans 'Home' %}</a></li> | |
| 9 | - <li><a href="{% url 'course:view' course.slug %}">{{ course }}</a></li> | |
| 10 | - </ol> | |
| 11 | -{% endblock %} | |
| 12 | - | |
| 13 | -{% block content %} | |
| 14 | -<div class="panel panel-default"> | |
| 15 | - <div class="panel-body"> | |
| 16 | - <form action="" method="post"> | |
| 10 | + <h4 class="modal-title" id="myModalLabel">{% trans "Delete Category" %}</h4> | |
| 11 | + </div> | |
| 12 | + <!-- Modal Body --> | |
| 13 | + <div class="modal-body"> | |
| 14 | + <!-- Put ONLY your content here!!! --> | |
| 15 | + <form id="delete_form" action="" method="post"> | |
| 17 | 16 | {% csrf_token %} |
| 18 | - <h2>{% trans 'Are you sure you want to delete the course' %} "{{course}}"?</h2> | |
| 19 | - <input type="submit" class="btn btn-raised btn-success btn-lg" value="{% trans 'Yes' %}" /> | |
| 20 | - <a href="{% url 'course:view' course.slug%}" class="btn btn-raised btn-danger btn-lg">{% trans 'No' %}</a> | |
| 17 | + <p>{% trans 'Are you sure you want to delete the category' %} "{{category.name}}"?</p> | |
| 21 | 18 | </form> |
| 19 | + </div> | |
| 20 | + <!-- Modal Footer --> | |
| 21 | + <div class="modal-footer"> | |
| 22 | + <!-- Don't remove that!!! --> | |
| 23 | + <button type="button" class="btn btn-danger btn-raised" data-dismiss="modal">{% trans "Close" %}</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 | + Subimite.remove("{% url 'course:delete_cat' category.slug %}",$(this).serialize(),"#category_{{category.slug}}"); | |
| 28 | + event.preventDefault(); | |
| 29 | + }); | |
| 30 | + </script> | |
| 31 | + </div> | |
| 32 | + </div> | |
| 22 | 33 | </div> |
| 23 | 34 | </div> |
| 24 | -{% endblock %} | |
| 25 | 35 | \ No newline at end of file |
| 36 | +<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> | |
| 37 | +<script src="{% static 'js/modal_category.js' %}"></script> | ... | ... |
courses/templates/course/course_card.html
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | </button> |
| 21 | 21 | <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> |
| 22 | 22 | <li><a href="{% url 'course:replicate_course' course.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> |
| 23 | - <li><a href="javascript:delete_course('{% url 'course:delete' course.slug %}', '{{ course.slug }}', '{% trans "Are you sure you want to delete this course?" %}', '{% url 'course:manage' %}')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
| 23 | + <li><a href="javascript:delete_course.get('{% url 'course:delete' course.slug %}','#course','#modal_course')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
| 24 | 24 | </ul> |
| 25 | 25 | </div> |
| 26 | 26 | </div> |
| ... | ... | @@ -63,4 +63,5 @@ |
| 63 | 63 | </div> |
| 64 | 64 | </div> |
| 65 | 65 | </div> |
| 66 | -</div> | |
| 67 | 66 | \ No newline at end of file |
| 67 | +</div> | |
| 68 | + <script type="text/javascript" src="{% static 'js/course.js' %}"></script> | |
| 68 | 69 | \ No newline at end of file | ... | ... |
courses/templates/course/delete.html
| ... | ... | @@ -24,7 +24,7 @@ |
| 24 | 24 | <button type="submit" id="button" form="delete_form" class="btn btn-primary btn-raised">{% trans "Delete" %}</button> |
| 25 | 25 | <script> |
| 26 | 26 | $("#delete_form").submit(function(event) { |
| 27 | - RemoverCurso.remove("{% url 'course:delete' course.slug %}",$(this).serialize(),"#course_{{course.slug}}"); | |
| 27 | + RemoveCourse.remove("{% url 'course:delete' course.slug %}",$(this).serialize(),"#course_{{course.slug}}"); | |
| 28 | 28 | event.preventDefault(); |
| 29 | 29 | }); |
| 30 | 30 | </script> | ... | ... |
courses/templates/course/view.html
| ... | ... | @@ -9,6 +9,7 @@ |
| 9 | 9 | |
| 10 | 10 | {% block javascript %} |
| 11 | 11 | <script type="text/javascript" src="{% static 'js/course.js' %}"></script> |
| 12 | + <script type="text/javascript" src="{% static 'js/modal_subject.js' %}"></script> | |
| 12 | 13 | {% endblock %} |
| 13 | 14 | |
| 14 | 15 | {% block breadcrumbs %} |
| ... | ... | @@ -128,27 +129,6 @@ |
| 128 | 129 | |
| 129 | 130 | <div class="panel panel-info"> |
| 130 | 131 | </div> |
| 131 | - | |
| 132 | - | |
| 133 | -<!-- MODAL REMOVE --> | |
| 134 | -<div class="modal" id="removeSubject"> | |
| 135 | - <div class="modal-dialog"> | |
| 136 | - <div class="modal-content"> | |
| 137 | - <div class="modal-header"> | |
| 138 | - <button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button> | |
| 139 | - <h4 class="modal-title"></h4> | |
| 140 | - </div> | |
| 141 | - <div class="modal-body"> | |
| 142 | - <p>{% trans "Are you sure you want to remove this subject?" %}</p> | |
| 143 | - </div> | |
| 144 | - <div class="modal-footer"> | |
| 145 | - | |
| 146 | - <a href="http://127.0.0.1:8080/html/screens/users/teacher/home_course_teacher.html" target="_self"><button type="button" class="btn btn-primary">{% trans "Confirm" %}</button></a> | |
| 147 | - | |
| 148 | - </div> | |
| 149 | - </div> | |
| 150 | - </div> | |
| 151 | -</div> | |
| 152 | 132 | </div> |
| 153 | 133 | <div class="cards-detail"> |
| 154 | 134 | {% for subject in subjects %} |
| ... | ... | @@ -171,7 +151,7 @@ |
| 171 | 151 | </button> |
| 172 | 152 | <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> |
| 173 | 153 | <li><a href="javascript:void(0)" data-toggle="modal" data-target="#myModal3"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i> {% trans 'Replicate' %}</a></li> |
| 174 | - <li><a href="javascript:subject.get('{% url 'course:delete_subject' subject.slug %}','#subject','#modal_subject');" data-toggle="modal" data-target="#removeSubject"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
| 154 | + <li><a href="javascript:delete_subject.get('{% url 'course:delete_subject' subject.slug %}','#subject','#modal_subject')" data-toggle="modal" data-target="#removeSubject"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
| 175 | 155 | </ul> |
| 176 | 156 | </div> |
| 177 | 157 | </div> |
| ... | ... | @@ -221,5 +201,6 @@ |
| 221 | 201 | </div> |
| 222 | 202 | </div> |
| 223 | 203 | </div> |
| 204 | +<div class="row" id="modal_subject"> | |
| 224 | 205 | |
| 225 | 206 | {% endblock %} | ... | ... |
courses/templates/subject/delete.html
| 1 | -{% extends 'subject/index.html' %} | |
| 1 | +{% load static i18n permission_tags %} | |
| 2 | 2 | |
| 3 | -{% load static i18n permission_tags widget_tweaks %} | |
| 3 | +<!-- Modal (remember to change the ids!!!) --> | |
| 4 | +<div class="modal fade" id="subject" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
| 5 | + <div class="modal-dialog" role="document"> | |
| 6 | + <div class="modal-content"> | |
| 7 | + <!-- Modal Header --> | |
| 8 | + <div class="modal-header"> | |
| 4 | 9 | |
| 5 | -{% block content %} | |
| 6 | - | |
| 7 | -<div class="panel panel-default"> | |
| 8 | - <div class="panel-body"> | |
| 9 | - <form action="" method="post"> | |
| 10 | - {% csrf_token %} | |
| 11 | - <h2>{% trans 'Are you sure you want to delete the subject' %} "{{subject}}"?</h2> | |
| 12 | - <input type="submit" class="btn btn-raised btn-success btn-lg" value="{% trans 'Yes' %}" /> | |
| 13 | - <a href="{% url 'course:view_subject' subject.slug%}" class="btn btn-raised btn-danger btn-lg">{% trans 'No' %}</a> | |
| 14 | - </form> | |
| 10 | + <h4 class="modal-title" id="myModalLabel">{% trans "Delete Course" %}</h4> | |
| 11 | + </div> | |
| 12 | + <!-- Modal Body --> | |
| 13 | + <div class="modal-body"> | |
| 14 | + <!-- Put ONLY your content here!!! --> | |
| 15 | + <form id="delete_form" action="" method="post"> | |
| 16 | + {% csrf_token %} | |
| 17 | + <p>{% trans 'Are you sure you want to delete the subject' %} "{{subject.name}}"?</p> | |
| 18 | + </form> | |
| 19 | + </div> | |
| 20 | + <!-- Modal Footer --> | |
| 21 | + <div class="modal-footer"> | |
| 22 | + <!-- Don't remove that!!! --> | |
| 23 | + <button type="button" class="btn btn-danger btn-raised" data-dismiss="modal">{% trans "Close" %}</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> | |
| 31 | + </div> | |
| 32 | + </div> | |
| 15 | 33 | </div> |
| 16 | 34 | </div> |
| 17 | - | |
| 18 | -{% endblock content %} | |
| 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/views.py
| ... | ... | @@ -308,7 +308,7 @@ class DeleteCourseView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.Delet |
| 308 | 308 | if has_role(self.request.user,'system_admin'): |
| 309 | 309 | courses = Course.objects.all() |
| 310 | 310 | elif has_role(self.request.user,'professor'): |
| 311 | - courses = self.request.user.courses.all() | |
| 311 | + courses = self.request.user.courses_professors.all() | |
| 312 | 312 | context['courses'] = courses |
| 313 | 313 | context['title'] = course.name |
| 314 | 314 | ... | ... |