Enable infinite scroll for the quota listing.

see #585
This commit is contained in:
Antoine Nguyen
2014-10-15 12:21:03 +02:00
parent aee0e86838
commit d219680904
10 changed files with 95 additions and 59 deletions
@@ -296,6 +296,24 @@ Identities.prototype = {
});
},
/**
* Add a type to let the server know what kind of object we expect.
*
* @this Listing
*/
get_load_page_args: function() {
var args = Admin.prototype.get_load_page_args.call(this);
if (this.navobj.getbaseurl() == "list") {
args.objtype = "identity";
this.options.eor_message = gettext("No more identity to show");
} else {
args.objtype = "quota";
this.options.eor_message = gettext("No more quota to show");
}
return args;
},
/**
* A new page has been received, inject it.
*
@@ -313,6 +331,14 @@ Identities.prototype = {
* @param {Object} data - response of the ajax call (JSON)
*/
list_cb: function(data) {
if ($(".sidebar li.active").length === 0) {
var menu = this.navobj.getbaseurl();
if (menu == "list") {
menu = "identities";
}
$("a[name={0}]".format(menu)).parent().addClass("active");
}
$("#objects_table thead tr").html(data.headers);
Admin.prototype.list_cb.call(this, data);
this.init_identity_links(data);
},
@@ -7,17 +7,10 @@
$(document).ready(function() {
admin = new Identities({
domain_list_url: "{% url 'admin:domain_flat_list' %}",
load_page_url: "{% url 'admin:_identity_list' %}"
load_page_url: "{% url 'admin:identity_page' %}"
});
});
</script>
{% extra_static_content "identities" user %}
{% endblock %}
{% block actions %}{% identities_menu user "identities" %}{% endblock %}
{% block table_header %}
<th id="identity" class="sortable" data-sort_order="identity" width="">{% trans "Name" %}</th>
<th id="name_or_rcpt" class="sortable" data-sort_order="name_or_rcpt" width="">{% trans "Fullname/Recipient" %}</th>
<th id="tags" class="sortable" data-sort_order="tags" width="">{% trans "Tags" %}</th>
<th id="actions" width="">{% trans "Actions" %}</th>
{% endblock %}
@@ -0,0 +1,5 @@
{% load i18n %}
<th id="identity" class="sortable" data-sort_order="identity" width="">{% trans "Name" %}</th>
<th id="name_or_rcpt" class="sortable" data-sort_order="name_or_rcpt" width="">{% trans "Fullname/Recipient" %}</th>
<th id="tags" class="sortable" data-sort_order="tags" width="">{% trans "Tags" %}</th>
<th id="actions" width="">{% trans "Actions" %}</th>
@@ -0,0 +1,5 @@
{% load i18n %}
<th width="50%" class="sortable" data-sort_order="address">{% trans "Address" %}</th>
<th class="sortable" data-sort_order="quota_value__bytes">{% trans "Value" %}</th>
<th class="sortable" data-sort_order="quota">{% trans "Limit" %}</th>
<th class="sortable" data-sort_order="quota_usage" id="quotabar">{% trans "Usage (%)" %}</th>
@@ -1,24 +1,15 @@
{% load i18n lib_tags admin_tags %}
<table class="table table-fixed">
<thead>
<tr>
<th width="50%" class="sortable" data-sort_order="address">{% trans "Address" %}</th>
<th class="sortable" data-sort_order="quota_value__bytes">{% trans "Value" %}</th>
<th class="sortable" data-sort_order="quota">{% trans "Limit" %}</th>
<th class="sortable" data-sort_order="quota_usage" id="quotabar">{% trans "Usage (%)" %}</th>
</tr>
</thead>
<tbody>
{% for mbox in mboxes %}<tr>
<td>{% identity_modify_link mbox.user "mail" %}</td>
<td>{{ mbox.get_quota }}M</td>
<td>{{ mbox.quota }}M</td>
<td name="quota">
<div id="quotabar" rel="tooltip" title="{{ mbox.get_quota_in_percent }}%"
class="progress">
<div class="{% progress_color mbox.get_quota_in_percent %}" style="width: {{ mbox.get_quota_in_percent }}%"></div>
</div>
</td>
</tr>{% endfor %}
</tbody>
</table>
{% load lib_tags admin_tags %}
{% for mbox in mboxes %}
<tr>
<td>{% identity_modify_link mbox.user "mail" %}</td>
<td>{{ mbox.get_quota }}M</td>
<td>{{ mbox.quota }}M</td>
<td name="quota">
<div id="quotabar" rel="tooltip" title="{{ mbox.get_quota_in_percent }}%"
class="progress">
<div class="{% progress_color mbox.get_quota_in_percent %}" style="width: {{ mbox.get_quota_in_percent }}%"></div>
</div>
</td>
</tr>
{% endfor %}
@@ -119,8 +119,7 @@ def identities_menu(user, selection=None):
return render_to_string('common/menulist.html', {
"entries": entries,
"user": user,
"selection": selection
"user": user
})
+1
View File
@@ -23,6 +23,7 @@ urlpatterns += patterns(
url(r'^identities/$', 'identities', name="identity_list"),
url(r'^identities/list/$', '_identities', name="_identity_list"),
url(r'^identities/quotas/$', 'list_quotas', name="quota_list"),
url(r'^identities/page/$', 'get_next_page', name="identity_page"),
url(r'^accounts/list/$', 'accounts_list', name="account_list"),
url(r'^accounts/new/$', 'newaccount', name="account_add"),
+39 -23
View File
@@ -54,6 +54,8 @@ def _identities(request):
if page is None:
context["length"] = 0
else:
context["headers"] = _render_to_string(
request, "admin/identity_headers.html", {})
context["rows"] = _render_to_string(
request, "admin/identities_table.html", {
"identities": page.object_list
@@ -63,30 +65,9 @@ def _identities(request):
return render_to_json_response(context)
@login_required
@user_passes_test(
lambda u: u.has_perm("admin.add_user") or u.has_perm("admin.add_alias")
)
@ensure_csrf_cookie
def identities(request, tplname="admin/identities.html"):
return render(request, tplname, {
"selection": "identities",
"deflocation": "list/"
})
@login_required
@permission_required("core.add_user")
def accounts_list(request):
accs = User.objects.filter(is_superuser=False) \
.exclude(groups__name='SimpleUsers')
res = [a.username for a in accs.all()]
return render_to_json_response(res)
@login_required
@permission_required("admin.add_mailbox")
def list_quotas(request, tplname="admin/quotas.html"):
def list_quotas(request):
from modoboa.lib.dbutils import db_type
sort_order, sort_dir = get_sort_order(request.GET, "address")
@@ -118,8 +99,10 @@ def list_quotas(request, tplname="admin/quotas.html"):
if page is None:
context["length"] = 0
else:
context["headers"] = _render_to_string(
request, "admin/quota_headers.html", {})
context["rows"] = _render_to_string(
request, tplname, {
request, "admin/quotas.html", {
"mboxes": page
}
)
@@ -127,6 +110,39 @@ def list_quotas(request, tplname="admin/quotas.html"):
return render_to_json_response(context)
@login_required
@user_passes_test(
lambda u: u.has_perm("admin.add_user") or u.has_perm("admin.add_alias")
or u.has_perm("admin.add_mailbox")
)
def get_next_page(request):
"""Return the next page of the identity list."""
if request.GET.get("objtype", "identity") == "identity":
return _identities(request)
return list_quotas(request)
@login_required
@user_passes_test(
lambda u: u.has_perm("admin.add_user") or u.has_perm("admin.add_alias")
)
@ensure_csrf_cookie
def identities(request, tplname="admin/identities.html"):
return render(request, tplname, {
"selection": "identities",
"deflocation": "list/"
})
@login_required
@permission_required("core.add_user")
def accounts_list(request):
accs = User.objects.filter(is_superuser=False) \
.exclude(groups__name='SimpleUsers')
res = [a.username for a in accs.all()]
return render_to_json_response(res)
@login_required
@permission_required("core.add_user")
@transaction.commit_on_success
-1
View File
@@ -3,7 +3,6 @@ from datetime import datetime
from django import template
from django.template import Template, Context
from django.template.loader import render_to_string
from modoboa.lib import events
+2 -1
View File
@@ -129,7 +129,7 @@ Listing.prototype = {
*/
end_of_list_reached: function(element) {
$("#" + this.options.main_table_id).after(
$("<div class='alert alert-info text-center'>{0}</div>".format(
$("<div id='eor_message' class='alert alert-info text-center'>{0}</div>".format(
this.options.eor_message
))
);
@@ -151,6 +151,7 @@ Listing.prototype = {
if ($scroll_container.data("infinite-scroll") !== undefined) {
$scroll_container.infinite_scroll("reset_loaded_pages", data.pages);
$scroll_container.infinite_scroll("resume");
$("#eor_message").remove();
} else {
$scroll_container.infinite_scroll({
initial_pages: data.pages,