Commit 9eb35814cc7f360a9fc632fa9f2bb83481a3f2af
1 parent
d53ecb15
Exists in
master
and in
3 other branches
delete course is working but still has course inside it's name function, we have…
… to replace most of them for naming purposes
Showing
5 changed files
with
165 additions
and
8 deletions
Show diff stats
... | ... | @@ -0,0 +1,101 @@ |
1 | +var locale = navigator.language || navigator.userLanguage; | |
2 | + | |
3 | +$('.date-picker').datepicker({ | |
4 | + language: locale, | |
5 | +}); | |
6 | + | |
7 | +/* | |
8 | +* | |
9 | +* Function to get a cookie stored on browser | |
10 | +* | |
11 | +*/ | |
12 | +function getCookie(name) { | |
13 | + var cookieValue = null; | |
14 | + if (document.cookie && document.cookie !== '') { | |
15 | + var cookies = document.cookie.split(';'); | |
16 | + for (var i = 0; i < cookies.length; i++) { | |
17 | + var cookie = jQuery.trim(cookies[i]); | |
18 | + // Does this cookie string begin with the name we want? | |
19 | + if (cookie.substring(0, name.length + 1) === (name + '=')) { | |
20 | + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); | |
21 | + break; | |
22 | + } | |
23 | + } | |
24 | + } | |
25 | + return cookieValue; | |
26 | +} | |
27 | +/* | |
28 | +* | |
29 | +* Function to subscribe (works for courses and subjects) | |
30 | +* | |
31 | +*/ | |
32 | +function subscribe(elem, url, id, confirm_message) { | |
33 | + alertify.confirm(confirm_message, function(){ | |
34 | + $.ajax({ | |
35 | + dataType: "json", | |
36 | + url: url, | |
37 | + success: function (data) { | |
38 | + if (data.status == "ok") { | |
39 | + elem.remove(); | |
40 | + alertify.success(data.message); | |
41 | + $(".panel_"+id).find(".view_btn").show() | |
42 | + } else { | |
43 | + alertify.error(data.message); | |
44 | + } | |
45 | + } | |
46 | + }); | |
47 | + }); | |
48 | +} | |
49 | + | |
50 | +/* | |
51 | +* | |
52 | +* Function to delete a course | |
53 | +* | |
54 | +*/ | |
55 | + | |
56 | +var RemoveCourse = { | |
57 | + remove: function(url,dados,id_li_link){ | |
58 | + $('#category').modal().hide(); | |
59 | + $.post(url,dados, function(data){ | |
60 | + $(id_li_link).remove(); | |
61 | + // alert("certo"); | |
62 | + $('body').removeClass('modal-open'); | |
63 | + $("#modal_course").empty(); | |
64 | + $(".modal-backdrop.in").remove(); | |
65 | + alertify.success("Course removed successfully!"); | |
66 | + // setTimeout(function () { location.reload(1); }, 1); | |
67 | + }).fail(function(){ | |
68 | + $("#modal_course").empty(); | |
69 | + $("#modal_course").append(data); | |
70 | + $('#course').modal('show'); | |
71 | + }); | |
72 | + } | |
73 | +} | |
74 | + | |
75 | +var delete_course = { | |
76 | + get: function (url, id_modal, id_div_modal){ | |
77 | + $.get(url, function(data){ | |
78 | + if($(id_modal).length){ | |
79 | + $(id_div_modal).empty(); | |
80 | + $(id_div_modal).append(data); | |
81 | + } else { | |
82 | + $(id_div_modal).append(data); | |
83 | + } | |
84 | + $(id_modal).modal('show'); | |
85 | + }); | |
86 | + } | |
87 | +}; | |
88 | +/* | |
89 | +* | |
90 | +* Function to load create course's form | |
91 | +* | |
92 | +*/ | |
93 | +function replicate_course(url, course) { | |
94 | + $.ajax({ | |
95 | + url: url, | |
96 | + data: {'form': course}, | |
97 | + success: function(data) { | |
98 | + $(".course_replicate_form").html(data); | |
99 | + } | |
100 | + }); | |
101 | +} | ... | ... |
... | ... | @@ -0,0 +1,36 @@ |
1 | +{% load static i18n permission_tags %} | |
2 | + | |
3 | +<!-- Modal (remember to change the ids!!!) --> | |
4 | +<div class="modal fade" id="category" 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 Category" %}</h4> | |
11 | + </div> | |
12 | + <!-- Modal Body --> | |
13 | + <div class="modal-body"> | |
14 | + <!-- Put ONLY your content here!!! --> | |
15 | + <form id="delete_form" action="{% url 'categories:delete' category.slug %}" method="post"> | |
16 | + {% csrf_token %} | |
17 | + <p>{% trans 'Are you sure you want to delete the category' %} "{{category.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-default 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 | + {% if index %} | |
26 | + <script> | |
27 | + $("#delete_form").submit(function(event) { | |
28 | + RemoveCourse.remove("{% url 'categories:delete' category.slug %}",$(this).serialize(),"#course_{{category.slug}}"); | |
29 | + event.preventDefault(); | |
30 | + }); | |
31 | + </script> | |
32 | + {% endif %} | |
33 | + </div> | |
34 | + </div> | |
35 | + </div> | |
36 | +</div> | |
0 | 37 | \ No newline at end of file | ... | ... |
categories/templates/categories/list.html
... | ... | @@ -37,16 +37,21 @@ |
37 | 37 | <a class="category-course-link" data-toggle="collapse" href="#{{category.slug}}">{{category.name}}</a> |
38 | 38 | </h4> |
39 | 39 | |
40 | - {% if user|has_role:'sys_admin' %} | |
41 | - <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | |
40 | + {% if user.is_staff %} | |
41 | + <div class="col-xs-6 col-md-6 divMoreActions" > | |
42 | + <div class="btn-group"> | |
43 | + <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | |
44 | + <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> | |
45 | + </button> | |
46 | + <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | |
42 | 47 | <li><a href="#"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> |
43 | 48 | <li><a href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> |
44 | - <li><a href="#"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
49 | + <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> | |
45 | 50 | </ul> |
51 | + </div> | |
52 | + </div> | |
46 | 53 | |
47 | - {% endif %} | |
48 | - | |
49 | - {% if user|has_role:'student' %} | |
54 | + {% else %} | |
50 | 55 | <a href=""><i class="fa fa-list" aria-hidden="true"></i></a> |
51 | 56 | <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a> |
52 | 57 | ... | ... |
categories/urls.py
... | ... | @@ -4,5 +4,5 @@ from . import views |
4 | 4 | urlpatterns = [ |
5 | 5 | url(r'^$', views.IndexView.as_view(), name='index'), |
6 | 6 | url(r'^create/$', views.CreateCategory.as_view(), name='create'), |
7 | - | |
7 | + url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteCategory.as_view(), name='delete'), | |
8 | 8 | ] |
9 | 9 | \ No newline at end of file | ... | ... |
categories/views.py
1 | 1 | from django.shortcuts import render |
2 | -from django.views.generic import ListView, CreateView | |
2 | +from django.views.generic import ListView, CreateView, DeleteView | |
3 | 3 | from .models import Category |
4 | 4 | from django.core.urlresolvers import reverse_lazy |
5 | 5 | from rolepermissions.verifications import has_role |
... | ... | @@ -74,3 +74,18 @@ class CreateCategory(HasRoleMixin, CreateView): |
74 | 74 | self.object = form.save() |
75 | 75 | #TODO: Implement log calls |
76 | 76 | return super(CreateCategory, self).form_valid(form) |
77 | + | |
78 | + | |
79 | +class DeleteCategory(HasRoleMixin, DeleteView): | |
80 | + | |
81 | + login_url = reverse_lazy("users:login") | |
82 | + redirect_field_name = 'next' | |
83 | + model = Category | |
84 | + template_name = 'categories/delete.html' | |
85 | + | |
86 | + | |
87 | + def get_success_url(self): | |
88 | + | |
89 | + return reverse_lazy('categories:index') | |
90 | + | |
91 | + | ... | ... |