Commit 1979c41be7f3d305a2af7ca89303390cea15a212
1 parent
2aee4eaf
Exists in
master
and in
3 other branches
added delete modal template
Showing
6 changed files
with
95 additions
and
2 deletions
Show diff stats
... | ... | @@ -0,0 +1,27 @@ |
1 | +var RemoveSubject = { | |
2 | + remove: function(url,dados,id_li_link){ | |
3 | + $("#subject").modal('toggle'); | |
4 | + $.post(url,dados, function(data){ | |
5 | + $(id_li_link).remove(); | |
6 | + $('body').removeClass('modal-open'); | |
7 | + $("#modal_course").empty(); | |
8 | + $(".modal-backdrop.in").remove(); | |
9 | + alertify.success("Subject removed successfully!"); | |
10 | + }).fail(function(){ | |
11 | + $("#modal_course").empty(); | |
12 | + $("#modal_course").append(data); | |
13 | + $('#subject').modal('show'); | |
14 | + }); | |
15 | + } | |
16 | +} | |
17 | +var delete_subject = { | |
18 | + get: function (url, id_modal, id_div_modal){ | |
19 | + $.get(url, function(data){ | |
20 | + if($(id_modal).length){ | |
21 | + $(id_div_modal).empty(); | |
22 | + } | |
23 | + $(id_div_modal).append(data); | |
24 | + $(id_modal).modal('show'); | |
25 | + }); | |
26 | + } | |
27 | +}; | |
0 | 28 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,37 @@ |
1 | +{% load static i18n permission_tags %} | |
2 | + | |
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"> | |
9 | + | |
10 | + <h4 class="modal-title" id="myModalLabel">{% trans "Delete Subject" %}</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-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> | |
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 %} | |
34 | + </div> | |
35 | + </div> | |
36 | + </div> | |
37 | +</div> | |
0 | 38 | \ No newline at end of file | ... | ... |
subjects/templates/subjects/list.html
... | ... | @@ -5,6 +5,7 @@ |
5 | 5 | |
6 | 6 | {% block javascript%} |
7 | 7 | {{ block.super }} |
8 | + <script type="text/javascript" src=" {% static "subjects/js/modal_subject.js" %} "></script> | |
8 | 9 | {% endblock%} |
9 | 10 | |
10 | 11 | {% block breadcrumbs %} |
... | ... | @@ -67,7 +68,8 @@ |
67 | 68 | <li><a href="{% url 'categories:replicate' category.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> |
68 | 69 | {% endif %} |
69 | 70 | <li><a href="{% url 'categories:update' category.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> |
70 | - <li><a href="javascript:delete_course.get('{% url 'categories:delete' category.slug %}?view=index','#category','#modal_course')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
71 | + <li> | |
72 | + <a href="javascript:delete_course.get('{% url 'categories:delete' category.slug %}?view=index','#category','#modal_course')" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
71 | 73 | </ul> |
72 | 74 | {% endif %} |
73 | 75 | <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> | ... | ... |
subjects/templates/subjects/subject_card.html
... | ... | @@ -27,7 +27,7 @@ |
27 | 27 | <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> |
28 | 28 | <li><a href="{% url 'subjects:replicate' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> |
29 | 29 | <li><a href="{% url 'subjects:update' subject.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> |
30 | - <li><a href="#"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
30 | + <li><a href="javascript:delete_subject.get('{% url 'subjects:delete' subject.slug %}','#subject','#modal_subject')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
31 | 31 | </ul> |
32 | 32 | {% endif %} |
33 | 33 | <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> | ... | ... |
subjects/urls.py
... | ... | @@ -8,5 +8,6 @@ urlpatterns = [ |
8 | 8 | url(r'^create/(?P<slug>[\w_-]+)/$', views.SubjectCreateView.as_view(), name='create'), |
9 | 9 | url(r'^replicate/(?P<subject_slug>[\w_-]+)/$', views.SubjectCreateView.as_view(), name='replicate'), |
10 | 10 | url(r'^update/(?P<slug>[\w_-]+)/$', views.SubjectUpdateView.as_view(), name='update'), |
11 | + url(r'^delete/(?P<slug>[\w_-]+)/$', views.SubjectDeleteView.as_view(), name='delete'), | |
11 | 12 | #url(r'^modal/(?P<subject_slug>[\w_-]+)/$', views.subscribe_subject(), name='subscribe'), |
12 | 13 | ] |
13 | 14 | \ No newline at end of file | ... | ... |
subjects/views.py
... | ... | @@ -203,6 +203,32 @@ class SubjectUpdateView(LogMixin, UpdateView): |
203 | 203 | return reverse_lazy('subjects:index') |
204 | 204 | |
205 | 205 | |
206 | + | |
207 | +class SubjectDeleteView(LoginRequiredMixin, HasRoleMixin, LogMixin, DeleteView): | |
208 | + | |
209 | + login_url = reverse_lazy("users:login") | |
210 | + redirect_field_name = 'next' | |
211 | + model = Subject | |
212 | + template_name = 'subject/delete.html' | |
213 | + | |
214 | + def dispatch(self, *args, **kwargs): | |
215 | + subject = get_object_or_404(Subject, slug = self.kwargs.get('slug')) | |
216 | + | |
217 | + return super(SubjectDeleteView, self).dispatch(*args, **kwargs) | |
218 | + | |
219 | + def get_context_data(self, **kwargs): | |
220 | + context = super(SubjectDeleteView, self).get_context_data(**kwargs) | |
221 | + | |
222 | + return context | |
223 | + | |
224 | + def get_success_url(self): | |
225 | + | |
226 | + | |
227 | + | |
228 | + #super(DeleteSubjectView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
229 | + | |
230 | + return reverse_lazy('subjects:index') | |
231 | + | |
206 | 232 | def subscribe_subject(request, subject_slug): |
207 | 233 | subject = get_object_or_404(Subject, slug= subject_slug) |
208 | 234 | subject.students.add(request.user) | ... | ... |