From daf81ec8fd837313de79c02575eb447e1f257bfe Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Fri, 13 Apr 2012 09:29:21 +0200 Subject: [PATCH] Stats: fixed bad behaviours. Notify: boxes are now correctly centered. see #204 --- extensions/stats/templates/stats/index.html | 3 ++- extensions/stats/views.py | 26 ++++++++++----------- static/js/notify.js | 7 +++--- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/extensions/stats/templates/stats/index.html b/extensions/stats/templates/stats/index.html index 80a8c24e9..17f2e10f1 100644 --- a/extensions/stats/templates/stats/index.html +++ b/extensions/stats/templates/stats/index.html @@ -7,7 +7,8 @@ diff --git a/extensions/stats/views.py b/extensions/stats/views.py index 5881d90b0..b7ac81e08 100644 --- a/extensions/stats/views.py +++ b/extensions/stats/views.py @@ -1,10 +1,6 @@ # coding: utf-8 -from django.http import HttpResponse -from django.core.urlresolvers import reverse from django.utils.translation import ugettext as _, ugettext_noop -from django.utils import simplejson from modoboa.lib.webutils import _render, _render_to_string, ajax_simple_response -from modoboa.lib.permissions import check_domain_access from modoboa.admin.models import Domain, Mailbox from django.contrib.auth.decorators \ import login_required, user_passes_test, permission_required @@ -23,19 +19,23 @@ periods = [{"name" : "day", "label" : ugettext_noop("Day")}, @login_required @permission_required("admin.view_mailboxes") -@check_domain_access def index(request): - domains = None + deflocation = "" + if request.user.is_superuser: + deflocation = "graphs/?view=global" + else: + if len(request.user.get_domains()): + deflocation = "graphs/?view=%s" % request.user.get_domains()[0].name + else: + raise ModoboaException(_("No statistics available")) + period = request.GET.get("period", "day") - domid = request.GET.get("domid", "") - - domains = request.user.get_domains() - return _render(request, 'stats/index.html', { "graphs" : graph_list, "periods" : periods, "period" : period, - "selection" : "stats" + "selection" : "stats", + "deflocation" : deflocation }) @login_required @@ -49,7 +49,7 @@ def graphs(request): graphs_loc=parameters.get_admin("GRAPHS_LOCATION")) if view == "global": if not request.user.is_superuser: - raise PermDeniedError(_("you're not allowed to see those statistics")) + raise PermDeniedException(_("you're not allowed to see those statistics")) tplvars.update(domain=view) else: try: @@ -57,7 +57,7 @@ def graphs(request): except Domain.DoesNotExist: raise ModoboaException(_("Domain not found. Please enter a full name")) if not request.user.can_access(domain): - raise PermDeniedError(_("You don't have access to this domain")) + raise PermDeniedException(_("You don't have access to this domain")) tplvars.update(domain=domain.name) if period == "custom": diff --git a/static/js/notify.js b/static/js/notify.js index c0226c3a9..ba15e28cc 100644 --- a/static/js/notify.js +++ b/static/js/notify.js @@ -14,6 +14,8 @@ var div = $("
", { id: bid, click: $.proxy(this.destroy_box, this) + }).css({ + position: "absolute" }); return div; @@ -26,10 +28,9 @@ set_position: function(box) { box.css({ - position: "absolute", top: this.options.top_position, left: "50%", - marginLeft: '-' + (box.outerWidth() / 2) + 'px' + 'margin-left': -box.outerWidth(true) / 2 }); }, @@ -46,8 +47,8 @@ nbox.addClass("alert-" + klass); } this.set_message(nbox, message); - this.set_position(nbox); this.$element.append(nbox); + this.set_position(nbox); if (timer != undefined) { window.setTimeout(function() { nbox.alert('close');