From fbe5cc215f9470221723129999085345afe99b21 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Fri, 6 Apr 2012 10:14:43 +0200 Subject: [PATCH] Identities: * Removed 'edit' button * Clicking on an identity name now opens the edit box fixes #213 --- admin/tables.py | 8 +++++- admin/templatetags/admin_extras.py | 42 +++++++++--------------------- lib/tables.py | 10 +++++-- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/admin/tables.py b/admin/tables.py index 301e1ea5e..c5c715632 100644 --- a/admin/tables.py +++ b/admin/tables.py @@ -54,7 +54,13 @@ class ExtensionsTable(tables.Table): class IdentitiesTable(tables.Table): idkey = "id" - identity = tables.Column("identity", label=ugettext_noop("Email/Username")) + identity = tables.LinkColumn( + "identity", label=ugettext_noop("Email/Username"), + modal=True, + urlpattern={"User" : "modoboa.admin.views.editaccount", + "Alias" : "modoboa.admin.views.editdlist"}, + modalcb={"User" : "editaccount_cb", "Alias" : "dlistform_cb"} + ) name_or_rcpt = tables.Column("name_or_rcpt", label=ugettext_noop("Fullname/Recipient")) actions = tables.ActionColumn("actions", label=ugettext_noop("Actions"), width="70px", align="center", diff --git a/admin/templatetags/admin_extras.py b/admin/templatetags/admin_extras.py index 933e10090..43040fde4 100644 --- a/admin/templatetags/admin_extras.py +++ b/admin/templatetags/admin_extras.py @@ -122,39 +122,23 @@ def domain_actions(user, domid): return render_actions(actions) -@register.simple_tag -def account_actions(user, accountid): - actions = [ - {"name" : "editaccount", - "url" : reverse(admin.views.editaccount, args=[accountid]), - "img" : "icon-edit", - "modal" : True, - "modalcb" : "editaccount_cb", - "title" : _("Edit account")}, - {"name" : "delaccount", - "url" : reverse(admin.views.delaccount) + "?selection=%s" % accountid, - "img" : "icon-trash", - "title" : _("Delete this account")}, - ] - return render_actions(actions) - @register.simple_tag def identity_actions(user, iid): name, objid = iid.split(':') if name == "User": - return account_actions(user, objid) - actions = [ - {"name" : "editdlist", - "url" : reverse(admin.views.editdlist, args=[objid]), - "img" : "icon-edit", - "modal" : True, - "modalcb" : "dlistform_cb", - "title" : _("Edit distribution list")}, - {"name" : "deldlist", - "url" : reverse(admin.views.deldlist) + "?selection=%s" % objid, - "img" : "icon-trash", - "title" : _("Delete this distribution list")}, - ] + actions = [ + {"name" : "delaccount", + "url" : reverse(admin.views.delaccount) + "?selection=%s" % objid, + "img" : "icon-trash", + "title" : _("Delete this account")}, + ] + else: + actions = [ + {"name" : "deldlist", + "url" : reverse(admin.views.deldlist) + "?selection=%s" % objid, + "img" : "icon-trash", + "title" : _("Delete this distribution list")}, + ] return render_actions(actions) @register.simple_tag diff --git a/lib/tables.py b/lib/tables.py index a4c931572..cca913077 100644 --- a/lib/tables.py +++ b/lib/tables.py @@ -74,8 +74,14 @@ class ActionColumn(Column): class LinkColumn(Column): def render(self, rowid, value): - linkdef = dict(url=reverse(self.urlpattern, args=[rowid]), label=value, - modal=self.modal, modalcb=self.modalcb) + linkdef = dict(label=value, modal=self.modal) + if type(self.urlpattern) == dict: + t, value = rowid.split(":") + linkdef.update(url=reverse(self.urlpattern[t], args=[value]), + modalcb=self.modalcb[t]) + else: + linkdef.update(url=reverse(self.urlpattern, args=[rowid]), + modalcb=self.modalcb) return render_link(linkdef) class Table(object):