Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #148 from davidw93/bug710075
Browse files Browse the repository at this point in the history
Bug 710075 - Infinite Scroll on groups

Also fixes a bug in infinite.js (impacts search view)
  • Loading branch information
tallowen committed Mar 5, 2012
2 parents 5a1e64f + a7427ae commit d22c3fe
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 19 deletions.
28 changes: 26 additions & 2 deletions apps/groups/templates/groups/show.html
Expand Up @@ -8,6 +8,13 @@
box-content search-page group-name-{{ group.name }}
{% endblock %}

{% block site_js %}
<script src="{{ url('jsi18n') }}"></script>
{{ js('common') }}
{{ js('search') }}
{% include "includes/webtrends_desktop.html" %}
{% endblock %}

{% block main_content %}
{% trans name=group.name %}
<h1>Users in Group "{{ name }}"</h1>
Expand All @@ -31,8 +38,25 @@ <h1>Users in Group "{{ name }}"</h1>
<div class="clear"></div>

<div class="blue-pastels">
{% for profile in profiles %}
{{ search_result(profile) }}
<form method="GET" id="search-form" action="#">
<input type="hidden" name="limit" id="limit" value="{{ limit }}">
</form>
{% for person in people %}
{{ search_result(person) }}
{% endfor %}
{% if show_pagination %}
<div data-pages={{ num_pages }} class="pagination">
{% for page in people.paginator.page_range %}
{% if page == people.number %}
<span>{{ page }}</span>
{% else %}
<a href="#">{{ page }}</a>
{% endif %}
{% endfor %}
</div>
<div id="final-result">
<span>Showing all {{ people.paginator.count }} results.</span>
</div>
{% endif %}
</div>
{% endblock main_content %}
49 changes: 41 additions & 8 deletions apps/groups/views.py
Expand Up @@ -11,7 +11,7 @@
from funfactory.urlresolvers import reverse

from .models import Group
from phonebook.forms import PAGINATION_LIMIT
from phonebook import forms
from phonebook.views import vouch_required

log = commonware.log.getLogger('m.groups')
Expand All @@ -20,7 +20,7 @@
@login_required
def index(request):
"""Lists all public groups (in use) on Mozillians."""
paginator = Paginator(Group.objects.all(), PAGINATION_LIMIT)
paginator = Paginator(Group.objects.all(), forms.PAGINATION_LIMIT)

page = request.GET.get('page')
try:
Expand Down Expand Up @@ -56,19 +56,52 @@ def search(request):

@vouch_required
def show(request, id, url=None):
"""List all users with this group."""
""" List all users with this group."""
if not url:
redirect(reverse('group', args=[group.id, group.url]))


form = forms.SearchForm(request.GET)
group = get_object_or_404(Group, id=id)

# Redirect to the full URL if it wasn't supplied
if not url:
redirect(reverse('group', args=[group.id, group.url]))
limit = forms.PAGINATION_LIMIT
if form.is_valid():
limit = form.cleaned_data['limit']

page = request.GET.get('page', 1)

in_group = (request.user.get_profile()
.groups.filter(id=group.id).count())
profiles = group.userprofile_set.all()

data = dict(group=group, in_group=in_group, profiles=profiles)
return render(request, 'groups/show.html', data)
paginator = Paginator(profiles, limit)

people = []
try:
people = paginator.page(page)
except PageNotAnInteger:
people = paginator.page(1)
except EmptyPage:
people = paginator.page(paginator.num_pages)

show_pagination = False
num_pages = 0
if paginator.count > forms.PAGINATION_LIMIT:
show_pagination = True
num_pages = len(people.paginator.page_range)

d = dict(people=people,
group=group,
in_group=in_group,
form=form,
limit=limit,
show_pagination=show_pagination,
num_pages=num_pages)

if request.is_ajax():
return render(request, 'search_ajax.html', d)

return render(request, 'groups/show.html', d)


@require_POST
Expand Down
2 changes: 1 addition & 1 deletion apps/phonebook/views.py
Expand Up @@ -149,7 +149,7 @@ def search(request):
num_pages=num_pages)

if request.is_ajax():
return render(request, 'phonebook/search_ajax.html', d)
return render(request, 'search_ajax.html', d)

return render(request, 'phonebook/search.html', d)

Expand Down
18 changes: 10 additions & 8 deletions media/js/infinite.js
Expand Up @@ -22,18 +22,20 @@
return cease;
},
callback: function(i) {
cease = (pages <= i);
$.ajax({
data:{'page': i + 1},
dataType: 'html',
success: function(data) {
paginator.before($(data));
}
});
cease = (pages < i);
if (cease) {
// Show the user that we have stopped scrolling on purpose.
results.show()
} else {
$.ajax({
data:{'page': i + 1},
dataType: 'html',
success: function(data) {
paginator.before($(data));
}
});
}

}
});
});
Expand Down
File renamed without changes.

0 comments on commit d22c3fe

Please sign in to comment.