Merge branch 'modellist-170' of git://github.com/ludw/django-admin2 into ludw-modellist-170

This commit is contained in:
Daniel Greenfeld 2013-06-03 23:26:42 +02:00
commit 5be8972dac
3 changed files with 37 additions and 21 deletions

View file

@ -9,8 +9,8 @@ $(function() {
for (var ix = 0; ix < selectCheckboxen.length; ix++) {
if ($(selectCheckboxen[ix]).prop('checked')) {
count++;
};
};
}
}
selectAllCheckbox.prop('checked', count == selectCheckboxen.length);
selectedCount.text(count);
};
@ -23,4 +23,15 @@ $(function() {
selectCheckboxen.click(function(e) {
updateSelectedCount();
});
var actionDropdownLink = element.find('.dropdown-menu a');
actionDropdownLink.click(function (e) {
e.preventDefault();
var form = $(this).closest('form');
form.find('input[name="' + $(this).data('name') + '"]').val(
$(this).data('value'));
form.submit();
});
});

View file

@ -19,16 +19,22 @@
<div id="model-list" class="row">
<form id="model-list-form" class="form-inline" method="post">
{% csrf_token %}
<div class="span12">
<div class="navbar">
{% csrf_token %}
<select name="action">
{% for action in actions %}
<option value="{{ action.name }}">{{ action.description }}</option>
{% endfor %}
</select>
<button type="Submit" class="btn">Go</button>
<span id="selected-count">0</span> of {{ object_list|length }} selected
<div class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown">
Actions
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
{% for action in actions %}
<li><a tabindex="-1" href="#" data-name="action" data-value="{{ action.name }}">{{ action.description }}</a></li>
{% endfor %}
</ul>
</div>
<input type="hidden" name="action" value="" />
<small class="muted"><span id="selected-count">0</span> of {{ object_list|length }} selected</small>
<div class="pull-right">
{% if permissions.has_add_permission %}
<a href="{% url view|admin2_urlname:'create' %}" class="btn"><i class="icon-plus"></i> {% blocktrans with model_verbose_name=model|model_verbose_name %}Add {{ model_verbose_name }}{% endblocktrans %}</a>
@ -38,23 +44,22 @@
<table class="table table-bordered table-striped">
<thead>
<th><input type="checkbox" class="model-select-all"></th>
<th>{{ model_name }}</th>
<th class="checkbox-column"><input type="checkbox" class="model-select-all"></th>
<th>{{ model_name|capfirst }}</th>
</thead>
<tbody>
{% for obj in object_list %}
<tr>
<td><input type="checkbox" class="model-select" name="selected_model_pk" value="{{ obj.pk }}"></td>
<td>
{{ obj }}
{% if permissions.has_view_permission %}
<a href="{% url view|admin2_urlname:'detail' pk=obj.pk %}">{% trans "Detail" %}</a>
{% endif %}
{% if permissions.has_change_permission %}
<a href="{% url view|admin2_urlname:'update' pk=obj.pk %}">{% trans "Edit" %}</a>
{% endif %}
{% if permissions.has_delete_permission %}
<a href="{% url view|admin2_urlname:'delete' pk=obj.pk %}">{% trans "Delete" %}</a>
<a href="{% url view|admin2_urlname:'update' pk=obj.pk %}">{{ obj }}</a>
{% else %}
{% if permissions.has_view_permission %}
<a href="{% url view|admin2_urlname:'detail' pk=obj.pk %}">{{ obj }}</a>
{% else %}
{{ obj }}
{% endif %}
{% endif %}
</td>
</tr>

View file

@ -32,7 +32,7 @@ class PostListTest(BaseIntegrationTest):
def test_actions_displayed(self):
response = self.client.get(reverse("admin2:blog_post_index"))
self.assertInHTML('<option value="DeleteSelectedAction">Delete selected items</option>', response.content)
self.assertInHTML('<a tabindex="-1" href="#" data-name="action" data-value="DeleteSelectedAction">Delete selected items</a>', response.content)
def test_delete_selected_post(self):
post = Post.objects.create(title="a_post_title", body="body")