Commit 33e67bf5 by Dányi Bence

school: delete groups

parent 0016478b
......@@ -49,4 +49,5 @@ urlpatterns = patterns('',
url(r'^group/new/$', 'school.views.group_new', name='group_new'),
url(r'^ajax/group/(?P<gid>\d+)/add/$', 'school.views.group_ajax_add_new_member', name='group_ajax_add_new_member'),
url(r'^ajax/group/(?P<gid>\d+)/remove/$', 'school.views.group_ajax_remove_member', name='group_ajax_remove_member'),
url(r'^ajax/group/delete/$', 'school.views.group_ajax_delete', name='group_ajax_delete'),
)
......@@ -168,34 +168,56 @@ $(function() {
$('#new-member').click(function() {
$('#new-member-form').toggle();
});
$('#new-member-form input').click(function(e){
$('#new-member-form input').click(function(e) {
e.stopPropagation();
});
$('#new-member-form input[type=submit]').click(function(){
var neptun=$(this).prev().val();
$('#new-member-form input[type=submit]').click(function() {
var neptun = $(this).prev().val();
$.ajax({
type: 'POST',
url: '/ajax/group/'+$(this).data('id')+'/add/',
data: 'neptun='+neptun,
url: '/ajax/group/' + $(this).data('id') + '/add/',
data: 'neptun=' + neptun,
dataType: 'json',
success: function(data){
success: function(data) {
window.location.reload();
}
}).error(function(data){
}).error(function(data) {
//TODO: fancy modal alert
alert(JSON.parse(data.responseText).status);
})
});
$('#group-members .remove').click(function(e){
e.preventDefault(); e.stopPropagation();
$('#group-members .remove').click(function(e) {
e.preventDefault();
e.stopPropagation();
$.ajax({
type: 'POST',
url: '/ajax/group/'+$(this).data('gid')+'/remove/',
data: 'neptun='+$(this).data('neptun'),
success: function(data){
url: '/ajax/group/' + $(this).data('gid') + '/remove/',
data: 'neptun=' + $(this).data('neptun'),
success: function(data) {
window.location.reload();
}
});
});
$('#groups .delete').click(function(e) {
e.preventDefault();
e.stopPropagation();
var gid = $(this).data('id');
var name = $(this).data('name');
vm_confirm_popup(
interpolate(
gettext('Are you sure deleting <strong>%s</strong>'), [name]), gettext('Delete'), function() {
$.ajax({
type: 'POST',
url: '/ajax/group/delete/',
data: 'gid=' + gid,
success: function() {
window.location.reload();
}
}).error(function() {
window.location.reload();
})
})
})
/**
......
......@@ -12,6 +12,11 @@
<li class="wm">
<div class="summary">
<div class="name">{{ group.name }}</div>
<div class="actions">
<a href="#" class="delete" data-id="{{group.id}}" data-name="{{group.name}}">
<img src="/static/icons/minus-circle.png" alt="{% trans "Delete" %}" />
</a>
</div>
<div class="clear"></div>
</div>
<div class="details">
......
......@@ -199,3 +199,11 @@ def group_ajax_remove_member(request, gid):
return HttpResponse(json.dumps({
'status': 'OK'
}))
@login_required
def group_ajax_delete(request):
group = get_object_or_404(Group, id=request.POST['gid'])
group.delete()
return HttpResponse(json.dumps({
'status': 'OK'
}))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment