From 97d3996d2e15496dd7d962623f4fc00f584b7e00 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Tue, 21 Feb 2012 17:49:41 +0100 Subject: [PATCH] Top menubar modifications. see #204 --- admin/models.py | 6 ++++ admin/templatetags/admin_extras.py | 33 +++++++++++----------- lib/templatetags/libextras.py | 44 ++++++++++++++++++++++++++++++ static/css/default.css | 6 +++- static/js/common.js | 6 +++- templates/nlayout.html | 18 ++---------- 6 files changed, 80 insertions(+), 33 deletions(-) diff --git a/admin/models.py b/admin/models.py index 9055bd63a..b53a2228b 100644 --- a/admin/models.py +++ b/admin/models.py @@ -124,6 +124,12 @@ class User(DUser): def has_mailbox(self): return len(self.mailbox_set.all()) != 0 + @property + def fullname(self): + if self.first_name != "": + return "%s %s" % (self.first_name, self.last_name) + return self.username + def belongs_to_group(self, name): """Simple shortcut to check if this user is a member of a specific group. diff --git a/admin/templatetags/admin_extras.py b/admin/templatetags/admin_extras.py index 76f0ba1c8..e71e665cf 100644 --- a/admin/templatetags/admin_extras.py +++ b/admin/templatetags/admin_extras.py @@ -14,46 +14,47 @@ genders = { @register.simple_tag def admin_menu(user): - entries = [ - {"name" : "admin", - "img" : static_url('pics/admin.png'), - "label" : _("Admin"), - "class" : "topdropdown", - "menu" : [] - } - ] + # entries = [ + # {"name" : "admin", + # "img" : static_url('pics/admin.png'), + # "label" : _("Admin"), + # "class" : "topdropdown", + # "menu" : [] + # } + # ] + entries = [] if user.has_perm("admin.view_domains"): - entries[0]["menu"] += [ + entries += [ {"name" : "domains", "url" : reverse(admin.views.domains), "label" : _("Domains"), "img" : static_url("pics/domains.png")} ] elif user.has_perm("admin.view_mailboxes"): - entries[0]["menu"] += [ + entries += [ {"name" : "mailboxes", "url" : reverse(admin.views.domains), "label" : _("Mailboxes"), "img" : static_url("pics/mailbox.png")} ] - entries[0]["menu"] += \ + entries += \ events.raiseQueryEvent("AdminMenuDisplay", "top_menu", user) if user.has_perm("auth.view_permissions"): - entries[0]["menu"] += [ + entries += [ {"name" : "permissions", "url" : reverse(admin.views.permissions), - "label" : _("Permissions"), + "label" : _("Accounts"), "img" : static_url("pics/permissions.png")} ] if user.is_superuser: - entries[0]["menu"] += [ + entries += [ {"name" : "settings", "img" : static_url("pics/settings.png"), - "label" : _("Settings"), + "label" : _("Modoboa"), "url" : reverse(admin.views.viewparameters)} ] - if not len(entries[0]["menu"]): + if not len(entries): return "" return render_to_string("common/menulist.html", {"entries" : entries, "user" : user}) diff --git a/lib/templatetags/libextras.py b/lib/templatetags/libextras.py index 8f0c172c0..ba083a0cf 100644 --- a/lib/templatetags/libextras.py +++ b/lib/templatetags/libextras.py @@ -3,8 +3,12 @@ import os from django.conf import settings from django import template from django.contrib import messages +from django.template.loader import render_to_string +from django.core.urlresolvers import reverse +from django.utils.translation import ugettext as _ from modoboa.lib import events from modoboa.lib.sysutils import exec_cmd +from modoboa.lib.webutils import static_url register = template.Library() @@ -55,3 +59,43 @@ def load_optionalmenu(user): menu = events.raiseQueryEvent("UserMenuDisplay", "top_menu_middle", user) return template.loader.render_to_string('common/menulist.html', {"entries" : menu, "user" : user}) + +@register.simple_tag +def user_menu(user): + entries = [ + {"name" : "user", + "img" : static_url('pics/administrators.png'), + "label" : user.fullname, + "class" : "topdropdown", + "menu" : [ + {"name" : "changepwd", + "url" : reverse("modoboa.userprefs.views.changepassword"), + "img" : static_url("pics/edit.png"), + "label" : _("Change password"), + "class" : "boxed", + "rel" : "{handler:'iframe',size:{x:360,y:200},closeBtn:true}"}, + {"name" : "preferences", + "img" : static_url("pics/user.png"), + "label" : _("Preferences"), + "url" : reverse("modoboa.userprefs.views.preferences")}, + {"name" : "logout", + "url" : reverse("modoboa.auth.views.dologout"), + "label" : _("Logout"), + "img" : static_url("pics/logout.png")} + ] + } + ] + if user.belongs_to_group('SimpleUsers'): + entries[0]["menu"] += [{ + "name" : "setforwards", + "url" : reverse("modoboa.userprefs.views.setforward"), + "img" : static_url("pics/alias.png"), + "label" : _("Forward"), + "class" : "boxed", + "rel" : "{handler:'iframe',size:{x:360,y:350},closeBtn:true}" + }] + + entries[0]["menu"] += events.raiseQueryEvent("UserMenuDisplay", "options_menu", user) + + return render_to_string("common/menulist.html", + {"entries" : entries, "user" : user}) diff --git a/static/css/default.css b/static/css/default.css index ff9301157..2ea12f27d 100644 --- a/static/css/default.css +++ b/static/css/default.css @@ -29,6 +29,10 @@ div#topmenubar { bottom: auto; } +#usermenubox { + margin-right: 5px; +} + div#footer { position: absolute; height: 30px; @@ -247,7 +251,7 @@ div.right { border-bottom: 5px solid #333; border-right: 5px solid #333; border-left: 5px solid #333; - width: 150px; + /*width: 150px;*/ float: left; position: relative; z-index: 4; diff --git a/static/js/common.js b/static/js/common.js index 78218ef30..db031efd6 100644 --- a/static/js/common.js +++ b/static/js/common.js @@ -72,8 +72,12 @@ function parse_menubar(id) { duration: 200 }); + var coords = elem.getCoordinates(); + myFx.wrapper.setStyles({ - "position" : "absolute" + position : "absolute", + /*top: 30,*/ + left : coords['left'] }); myFx.hide(); diff --git a/templates/nlayout.html b/templates/nlayout.html index 976fefb9b..d4be362d1 100644 --- a/templates/nlayout.html +++ b/templates/nlayout.html @@ -28,26 +28,14 @@
-
+
    -
  • - {% if user.first_name %} - {{ user.first_name }} {{ user.last_name }} - {% else %} - {{ user.username }} - {% endif %} - / -
  • -
  • - {% url modoboa.auth.views.dologout as logout_url %} - - {% trans "Logout" %} -
  • + {% user_menu user %}