Commit 3dda2ca0 by Oláh István Gergely

dashboard: fix group-details member-removing ajax

parent 86c09737
/* rename */ /* rename */
$("#group-details-h1-name, .group-details-rename-button").click(function() { $("#group-details-h1-name, .group-details-rename-button").click(function() {
$("#group-details-h1-name").hide(); $("#group-details-h1-name").hide();
...@@ -25,3 +24,44 @@ ...@@ -25,3 +24,44 @@
}); });
return false; return false;
}); });
/* for Node removes buttons */
$('.delete-from-group').click(function() {
var href = $(this).attr('href');
var group = $(this).data('group_pk');
var member = $(this).data('member_pk');
var dir = window.location.pathname.indexOf('list') == -1;
addModalConfirmation(removeMember,
{ 'url': href,
'data': [],
'group_pk': group,
'member_pk': member,
'type': "user",
'redirect': dir});
return false;
});
function removeMember(data) {
$.ajax({
type: 'POST',
url: data['url'],
headers: {"X-CSRFToken": getCookie('csrftoken')},
success: function(re, textStatus, xhr) {
if(!data['redirect']) {
selected = [];
addMessage(re['message'], 'success');
$('a[data-'+data['type']+'-pk="' + data['pk'] + '"]').closest('tr').fadeOut(function() {
$(this).remove();
});
} else {
window.location.replace('/dashboard');
}
},
error: function(xhr, textStatus, error) {
addMessage('Uh oh :(', 'danger')
}
});
}
{% load i18n %}
<div class="modal fade" id="confirmation-modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
{% if text %}
{{ text }}
{% else %}
{%blocktrans with object=object%}
Are you sure you want to remove <strong>{{ member }}</strong> from <strong>{{ object }}</strong>?
{%endblocktrans%}
{% endif %}
<br />
<div class="pull-right" style="margin-top: 15px;">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button id="confirmation-modal-button" type="button" class="btn btn-warning">Remove</button>
</div>
<div class="clearfix"></div>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<thead><tr><th></th><th>{% trans "Who" %}</th><th></th><th></th></tr></thead> <thead><tr><th></th><th>{% trans "Who" %}</th><th></th><th></th></tr></thead>
{% for i in users %} {% for i in users %}
<tr><td><i class="icon-user"></i></td><td>{{i.username}}</td> <tr><td><i class="icon-user"></i></td><td>{{i.username}}</td>
<td><a data-groupmember-pk="{{i.pk}}" href="{% url "dashboard.views.remove-user" user_pk=i.pk group_pk=group.pk %}?next={{ request.path }}" class="real-link groupmember-delete btn btn-link btn-xs"><i class="icon-remove"><span class="sr-only">{% trans "remove" %}</span></i></a></td></tr> <td><a data-group_pk="{{ group.pk }}" data-member_pk="{{i.pk}}" href="{% url "dashboard.views.remove-user" member_pk=i.pk group_pk=group.pk %}?next={{ request.path }}" class="real-link delete-from-group btn btn-link btn-xs"><i class="icon-remove"><span class="sr-only">{% trans "remove" %}</span></i></a></td></tr>
{% endfor %} {% endfor %}
<tr><td><i class="icon-plus"></i></td> <tr><td><i class="icon-plus"></i></td>
<td><input type="text" class="form-control" name="list-new-name" <td><input type="text" class="form-control" name="list-new-name"
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
<option{%if id = i.level%} selected="selected"{%endif%} value="{{id}}">{{name}}</option> <option{%if id = i.level%} selected="selected"{%endif%} value="{{id}}">{{name}}</option>
{% endfor %} {% endfor %}
</select></td> </select></td>
<td class="user-remove"><a data-groupaclmember-pk="{{i.user.id}}" href="{% url "dashboard.views.remove-acluser" user_pk=i.user.pk group_pk=group.pk %}?next={{ request.path }}" class="real-link groupacl-delete btn btn-link btn-xs"><i class="icon-remove"><span class="sr-only">{% trans "remove" %}</span></i></a></td></tr> <td class="user-remove"><a data-group_pk="{{ group.pk }}" data-member_pk="{{i.user.pk }}" href="{% url "dashboard.views.remove-acluser" member_pk=i.user.pk group_pk=group.pk %}?next={{ request.path }}" class="real-link delete-from-group btn btn-link btn-xs"><i class="icon-remove"><span class="sr-only">{% trans "remove" %}</span></i></a></td></tr>
{% endfor %} {% endfor %}
{% for i in acl.groups %} {% for i in acl.groups %}
<tr><td><i class="icon-user"></i></td><td>{{ i.group }}</td> <tr><td><i class="icon-user"></i></td><td>{{ i.group }}</td>
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
<option{%if id = i.level%} selected="selected"{%endif%} value="{{id}}">{{name}}</option> <option{%if id = i.level%} selected="selected"{%endif%} value="{{id}}">{{name}}</option>
{% endfor %} {% endfor %}
</select></td> </select></td>
<td class="user-remove"><a data-groupaclmember-pk="{{i.group.pk }}" href="{% url "dashboard.views.remove-aclgroup" user_pk=i.group.pk group_pk=group.pk %}?next={{ request.path }}" class="real-link groupacl-delete btn btn-link btn-xs"><i class="icon-remove"><span class="sr-only">{% trans "remove" %}</span></i></a></td></tr> <td class="user-remove"><a data-group_pk="{{ i.pk }}"data-member_pk="{{i.group.pk }}" href="{% url "dashboard.views.remove-aclgroup" member_pk=i.group.pk group_pk=group.pk %}?next={{ request.path }}" class="real-link delete-from-group btn btn-link btn-xs"><i class="icon-remove"><span class="sr-only">{% trans "remove" %}</span></i></a></td></tr>
{% endfor %} {% endfor %}
<tr><td><i class="icon-plus"></i></td> <tr><td><i class="icon-plus"></i></td>
<td><input type="text" class="form-control" name="perm-new-name" <td><input type="text" class="form-control" name="perm-new-name"
......
...@@ -103,13 +103,13 @@ urlpatterns = patterns( ...@@ -103,13 +103,13 @@ urlpatterns = patterns(
name="dashboard.views.disk-add"), name="dashboard.views.disk-add"),
url(r'^profile/$', MyPreferencesView.as_view(), url(r'^profile/$', MyPreferencesView.as_view(),
name="dashboard.views.profile"), name="dashboard.views.profile"),
url(r'^group/(?P<group_pk>\d+)/remove/acl/user/(?P<user_pk>\d+)/$', url(r'^group/(?P<group_pk>\d+)/remove/acl/user/(?P<member_pk>\d+)/$',
GroupRemoveAclUserView.as_view(), GroupRemoveAclUserView.as_view(),
name="dashboard.views.remove-acluser"), name="dashboard.views.remove-acluser"),
url(r'^group/(?P<group_pk>\d+)/remove/acl/group/(?P<user_pk>\d+)/$', url(r'^group/(?P<group_pk>\d+)/remove/acl/group/(?P<member_pk>\d+)/$',
GroupRemoveAclGroupView.as_view(), GroupRemoveAclGroupView.as_view(),
name="dashboard.views.remove-aclgroup"), name="dashboard.views.remove-aclgroup"),
url(r'^group/(?P<group_pk>\d+)/remove/user/(?P<user_pk>\d+)/$', url(r'^group/(?P<group_pk>\d+)/remove/user/(?P<member_pk>\d+)/$',
GroupRemoveUserView.as_view(), GroupRemoveUserView.as_view(),
name="dashboard.views.remove-user"), name="dashboard.views.remove-user"),
url(r'^group/create/$', GroupCreate.as_view(), url(r'^group/create/$', GroupCreate.as_view(),
......
...@@ -1012,7 +1012,7 @@ class GroupRemoveUserView(LoginRequiredMixin, DeleteView): ...@@ -1012,7 +1012,7 @@ class GroupRemoveUserView(LoginRequiredMixin, DeleteView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(GroupRemoveUserView, self).get_context_data(**kwargs) context = super(GroupRemoveUserView, self).get_context_data(**kwargs)
try: try:
context['member'] = User.objects.get(pk=self.user_pk) context['member'] = User.objects.get(pk=self.member_pk)
except User.DoesNotExist: except User.DoesNotExist:
raise Http404() raise Http404()
return context return context
...@@ -1024,8 +1024,8 @@ class GroupRemoveUserView(LoginRequiredMixin, DeleteView): ...@@ -1024,8 +1024,8 @@ class GroupRemoveUserView(LoginRequiredMixin, DeleteView):
else: else:
return reverse_lazy('dashboard.views.group-list') return reverse_lazy('dashboard.views.group-list')
def get(self, request, user_pk, *args, **kwargs): def get(self, request, member_pk, *args, **kwargs):
self.user_pk = user_pk self.member_pk = member_pk
return super(GroupRemoveUserView, self).get(request, *args, **kwargs) return super(GroupRemoveUserView, self).get(request, *args, **kwargs)
def get_template_names(self): def get_template_names(self):
...@@ -1042,7 +1042,7 @@ class GroupRemoveUserView(LoginRequiredMixin, DeleteView): ...@@ -1042,7 +1042,7 @@ class GroupRemoveUserView(LoginRequiredMixin, DeleteView):
return _("Member successfully removed from group!") return _("Member successfully removed from group!")
def delete(self, request, *args, **kwargs): def delete(self, request, *args, **kwargs):
self.remove_member(kwargs["user_pk"]) self.remove_member(kwargs["member_pk"])
success_url = self.get_success_url() success_url = self.get_success_url()
success_message = self.get_success_message() success_message = self.get_success_message()
...@@ -1071,7 +1071,7 @@ class GroupRemoveAclGroupView(GroupRemoveUserView): ...@@ -1071,7 +1071,7 @@ class GroupRemoveAclGroupView(GroupRemoveUserView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(GroupRemoveUserView, self).get_context_data(**kwargs) context = super(GroupRemoveUserView, self).get_context_data(**kwargs)
try: try:
context['member'] = Group.objects.get(pk=self.user_pk) context['member'] = Group.objects.get(pk=self.member_pk)
except User.DoesNotExist: except User.DoesNotExist:
raise Http404() raise Http404()
return context return context
......
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