Skip to content

Commit

Permalink
CRUD - agora com Delete de Board Members
Browse files Browse the repository at this point in the history
- modal para confirmar o delete.
- cambio ``messages.info`` por ``messages.success`` quando a operação teve sucesso.
- a view function, precisa da permissão: ``'editorialmanager.delete_editorialmember``
- cambio: "Save" por "Proceed" para que fique mais claro na ação de Delete.
  • Loading branch information
jfunez committed Sep 17, 2014
1 parent fb016d8 commit b6ffa35
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 27 deletions.
61 changes: 39 additions & 22 deletions scielomanager/editorialmanager/templates/board/board_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
{% block content %}

<style>
.accordion-board-members li > div { padding-left: 10px; padding-right: 10px; }
.accordion-board-members li > div:hover { background-color: #f5f5f5; }
.accordion-board-members li>div { padding-left: 10px; padding-right: 10px; }
.accordion-board-members li div.btn-group .btn { margin-top: 25px; }
.accordion-board-members li div:hover { background-color: #f5f5f5; }
</style>

<ul class="breadcrumb">
Expand Down Expand Up @@ -74,27 +75,42 @@ <h5>{% trans "Editorial Board" %}:</h5>
<ul class="unstyled accordion-board-members">
{% for member in role.list %}
<li>

<div class="span12">
<strong>{{ member.get_full_name }}</strong>
<p>
{% if member.email %}
<a href="mailto:{{ member.email }}">
<i class="icon-envelope"></i> {{ member.email }}
</a>
{% endif %}
{% if member.institution %} &bull; {{ member.institution }}{% endif %}
{% if member.city %} &bull; {{ member.city }} {% endif %}
{% if member.state %} &bull; {{ member.state }} {% endif %}
{% if member.country %} &bull; {{ member.country }} {% endif %}
{% if perms.editorialmanager.change_editorialmember %}
<a data-target='#id_modal_form' data-toggle="modal" href="{% url editorial.board.edit journal.pk member.pk %}" class="btn btn-mini btn-primary pull-right">
<i class="icon-pencil"></i> {% trans "Edit" %}
</a>
{% endif %}
</p>
<div class="board-member-details">

<div class="span12">
<div class="span10">

<h4><strong>{{ member.get_full_name }}</strong></h4>
<p>
{% if member.email %}
<a href="mailto:{{ member.email }}">
<i class="icon-envelope"></i> {{ member.email }}
</a>
{% endif %}
{% if member.institution %} &bull; {{ member.institution }}{% endif %}
{% if member.city %} &bull; {{ member.city }} {% endif %}
{% if member.state %} &bull; {{ member.state }} {% endif %}
{% if member.country %} &bull; {{ member.country }} {% endif %}
</p>
</div>
{# actions: edit, delete #}
<div class="span2 pull-right">

<div class="btn-group pull-right">
{% if perms.editorialmanager.change_editorialmember %}
<a data-target='#id_modal_form' data-toggle="modal" href="{% url editorial.board.edit journal.pk member.pk %}" class="btn btn-mini btn-primary">
<i class="icon-pencil"></i> {% trans "Edit" %}
</a>
{% endif %}
{% if perms.editorialmanager.delete_editorialmember %}
<a data-target='#id_modal_delete_member' data-toggle="modal" href="{% url editorial.board.delete journal.pk member.pk %}" class="btn btn-mini btn-danger">
<i class="icon-remove"></i> {% trans "Delete" %}
</a>
{% endif %}
</div>

</div>
</div>

</li>
{% endfor %}
</ul>
Expand All @@ -121,5 +137,6 @@ <h5>{% trans "Editorial Board" %}:</h5>
</div>

{% modal_form title="Edit Member" %}
{% modal_form title="Confirm to delete this Member" modal_id="id_modal_delete_member" %}

{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% extends "base_lv1.html" %}
{% load i18n %}


{% block content %}

<ul class="breadcrumb">
<li><a href="{% url editorial.index %}">{% trans 'Journals' %}</a><span class="divider">/</span></li>
<li><a href="{{ board_url }}">{% trans 'Editorial Board' %}</a><span class="divider">/</span></li>
<li class="active">{% trans 'Delete Board Member' %}</li>
</ul>


<h2>{% trans "Delete Board Member" %}?:</h2>
<div id="board-member-form" class="well">

{% include "board/board_member_delete_data.html" %}

<div class="row-fluid">
<a class="btn btn-danger pull-left" href="{{ board_url }}">{% trans "Back to Board" %}</a>
<button class="btn-submit btn btn-success pull-right">{% trans "Confirm" %}</button>
</div>
</div>

{% endblock content %}

{% block extrafooter %}
{{ block.super }}
<script>
$(function() {
$('.btn-submit').click(function(event) {
$('#board-member-form').find('form').submit();
});
$('input').addClass('span12');
$(".chzn-select").chosen({
no_results_text: "{% trans 'No results found for' %}:",
width: "100%",
});
});
</script>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{% load i18n %}

<form action="{{ post_url|default:'' }}" method="POST" class="form-horizontal">
{% csrf_token %}
<div class="alert alert-error">
<h4>{% trans "This operation cannot be undone" %}</h4>
<p>{% trans "And to restore it you will need to create a new member" %}</p>
</div>
<table class="table table-bordered table-hover table-condensed">
<tbody>
<tr>
<td class="span2"><strong>{% trans "First name" %}:</strong></td>
<td>{{ board_member.first_name }}</td>
</tr>
<tr>
<td class="span2"><strong>{% trans "Last name" %}:</strong></td>
<td>{{ board_member.last_name }}</td>
</tr>
<tr>
<td class="span2"><strong>{% trans "Email" %}:</strong></td>
<td>
<a href="mailto:{{ board_member.email }}">
<i class="icon-envelope"></i> {{ board_member.email }}
</a>
</td>
</tr>
<tr>
<td class="span2"><strong>{% trans "Role" %}:</strong></td>
<td>{{ board_member.role.name }}</td>
</tr>
{# optional fields #}
{% if board_member.institution %}
<tr>
<td class="span2"><strong>{% trans "Institution" %}:</strong></td>
<td>{{ board_member.institution }}</td>
</tr>
{% endif %}
{% if board_member.link_cv %}
<tr>
<td class="span2"><strong>{% trans "Link CV" %}:</strong></td>
<td><a href="{{ board_member.link_cv }}">{{ board_member.link_cv }}</a></td>
</tr>
{% endif %}
{% if board_member.city %}
<tr>
<td class="span2"><strong>{% trans "City" %}:</strong></td>
<td>{{ board_member.city }}</a></td>
</tr>
{% endif %}
{% if board_member.state %}
<tr>
<td class="span2"><strong>{% trans "State" %}:</strong></td>
<td>{{ board_member.state }}</a></td>
</tr>
{% endif %}
{% if board_member.country %}
<tr>
<td class="span2" ><strong>{% trans "Country" %}:</strong></td>
<td>{{ board_member.country }}</a></td>
</tr>
{% endif %}
</tbody>
</table>

</form>


4 changes: 3 additions & 1 deletion scielomanager/editorialmanager/templates/modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
<h3>{{title}}</h3>
</div>
<div class="modal-body">
<img src="{% static 'img/select2-spinner.gif' %}" alt="">
<p class="text-center">
<img src="{% static 'img/select2-spinner.gif' %}" alt="">
</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">{% trans "Close" %}</button>
Expand Down
6 changes: 4 additions & 2 deletions scielomanager/editorialmanager/templates/modal_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
<h3>{{title}}</h3>
</div>
<div class="modal-body">
<img src="{% static 'img/select2-spinner.gif' %}" alt="">
<p class="text-center">
<img src="{% static 'img/select2-spinner.gif' %}" alt="">
</p>
</div>
<div class="modal-footer">
<a class="btn btn-danger pull-left" data-dismiss="modal">{% trans "Close" %}</a>
<button class="btn-submit btn btn-success pull-right">{% trans "Save" %}</button>
<button class="btn-submit btn btn-success pull-right">{% trans "Proceed" %}</button>
</div>
</div>
1 change: 1 addition & 0 deletions scielomanager/editorialmanager/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
url(r'^board/(?P<journal_id>\d+)/$', views.board, name="editorial.board"),
url(r'^board/(?P<journal_id>\d+)/members/(?P<issue_id>\d+)/add/$', views.add_board_member, name="editorial.board.add"),
url(r'^board/(?P<journal_id>\d+)/members/(?P<member_id>\d+)/edit/$', views.edit_board_member, name="editorial.board.edit"),
url(r'^board/(?P<journal_id>\d+)/members/(?P<member_id>\d+)/delete/$', views.delete_board_member, name="editorial.board.delete"),
)
33 changes: 31 additions & 2 deletions scielomanager/editorialmanager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def edit_journal(request, journal_id):
journal = journalform.save()
missionformset.save()

messages.info(request, _('Journal updated successfully.'))
messages.success(request, _('Journal updated successfully.'))

return HttpResponseRedirect(reverse('editorial.index'))
else:
Expand Down Expand Up @@ -120,7 +120,7 @@ def edit_board_member(request, journal_id, member_id):
form = forms.EditorialMemberForm(request.POST, instance=board_member)
if form.is_valid():
form.save()
messages.info(request, _('Board Member updated successfully.'))
messages.success(request, _('Board Member updated successfully.'))
return HttpResponseRedirect(board_url)
else:
messages.error(request, _('Check mandatory fields.'))
Expand Down Expand Up @@ -183,3 +183,32 @@ def add_board_member(request, journal_id, issue_id):

context['form'] = form
return render_to_response(template_name, context, context_instance=RequestContext(request))


@permission_required('editorialmanager.delete_editorialmember', login_url=settings.AUTHZ_REDIRECT_URL)
def delete_board_member(request, journal_id, member_id):
# check if user have correct access to view the journal:
if not Journal.userobjects.active().filter(pk=journal_id).exists():
messages.error(request, _('The journal is not available for you.'))
return HttpResponseRedirect(reverse('editorial.index'))

if request.is_ajax():
template_name = 'board/board_member_delete_data.html'
else:
template_name = 'board/board_member_delete.html'

board_member = get_object_or_404(models.EditorialMember, id=member_id)
board_url = reverse('editorial.board', args=[journal_id, ])
post_url = reverse('editorial.board.delete', args=[journal_id, member_id, ])
context = {
'board_member': board_member,
'post_url': post_url,
'board_url': board_url,
}
if request.method == "POST":
# record audit log
board_member.delete()
messages.success(request, _('Board Member DELETED successfully.'))
return HttpResponseRedirect(board_url)

return render_to_response(template_name, context, context_instance=RequestContext(request))

0 comments on commit b6ffa35

Please sign in to comment.