Use same url to toggle participant status.

This commit is contained in:
Emanuel Schuetze 2012-05-19 19:22:20 +02:00
parent 3a52cd56c6
commit 189c975137
5 changed files with 25 additions and 35 deletions

View File

@ -15,12 +15,10 @@ $(function() {
dataType: 'json',
success: function(data) {
if (data.active) {
newclass = 'active';
link.addClass('active');
} else {
newclass = 'inactive';
link.removeClass('active');
}
link.removeClass('active inactive').addClass(newclass);
link.attr('href', data.link);
}
});
});

View File

@ -4,16 +4,7 @@
* :copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
* :license: GNU GPL, see LICENSE for more details.
*/
a.status_link.active span {
background-image: url(../images/icons/on.png);
background-repeat: no-repeat;
background-position: center;
width: 16px;
height: 16px;
display: inline-block;
}
a.status_link.inactive span {
a.status_link span {
background-image: url(../images/icons/off.png);
background-repeat: no-repeat;
background-position: center;
@ -21,3 +12,6 @@ a.status_link.inactive span {
height: 16px;
display: inline-block;
}
a.status_link.active span {
background-image: url(../images/icons/on.png);
}

View File

@ -87,8 +87,8 @@
<td><span style="width: 1px; white-space: nowrap;">
<a href="{% url user_edit user.id %}"><img src="{% static 'images/icons/edit.png' %}" title="{%trans 'Edit participant' %}"></a>
<a href="{% url user_delete user.id %}"><img src="{% static 'images/icons/delete.png' %}" title="{%trans 'Delete participant' %}"></a>
<a class="status_link {% if user.is_active %}active{% else %}inactive{% endif %}"
href="{% if user.is_active %}{% url user_inactive user.id %}{% else %}{% url user_active user.id %}{% endif %}"
<a class="status_link {% if user.is_active %}active{% endif %}"
href="{% url user_status user.id %}"
title="{%trans 'Change status (active/inactive)' %}">
<span></span>
</a>

View File

@ -41,16 +41,9 @@ urlpatterns = patterns('participant.views',
name='user_delete',
),
url(r'^(?P<user_id>\d+)/active/$',
'user_set_active',
{'active': True},
name='user_active',
),
url(r'^(?P<user_id>\d+)/inactive/$',
'user_set_active',
{'active': False},
name='user_inactive',
url(r'^(?P<user_id>\d+)/status/$',
'user_set_status',
name='user_status',
),
url(r'^import$',

View File

@ -198,21 +198,26 @@ def user_delete(request, user_id):
@permission_required('participant.can_manage_participant')
@template('confirm.html')
def user_set_active(request, user_id, active=True):
def user_set_status(request, user_id):
try:
user = User.objects.get(pk=user_id)
user.is_active = active
if user.is_active:
user.is_active = False
else:
user.is_active = True
user.save()
except User.DoesNotExist:
messages.error(request, _('Participant %d does not exist.') % int(user_id))
messages.error(request, _('Participant ID %d does not exist.') % int(user_id))
return redirect(reverse('user_overview'))
if request.is_ajax():
if active:
link = reverse('user_inactive', args=[user.id])
else:
link = reverse('user_active', args=[user.id])
return ajax_request({'active': active,
'link': link})
link = reverse('user_status', args=[user.id])
return ajax_request({'active': user.is_active})
# set success messages for page reload only (= not ajax request)
if user.is_active:
messages.success(request, _('<b>%s</b> is now <b>present</b>.') % user)
else:
messages.success(request, _('<b>%s</b> is now <b>absent</b>.') % user)
return redirect(reverse('user_overview'))
@permission_required('participant.can_manage_participant')