mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
wip: UI refactoring
* Displaying more information when editing a domain (adminstrators, dates) * Various fixes see #204
This commit is contained in:
@@ -141,6 +141,16 @@ def identity_actions(user, iid):
|
||||
]
|
||||
return render_actions(actions)
|
||||
|
||||
@register.simple_tag
|
||||
def domadmin_actions(daid, domid):
|
||||
actions = [dict(
|
||||
name="removeperm",
|
||||
url=reverse(admin.views.remove_permission) + "?domid=%s&daid=%s" % (domid, daid),
|
||||
img="icon-trash",
|
||||
title=_("Remove this permission")
|
||||
)]
|
||||
return render_actions(actions)
|
||||
|
||||
@register.simple_tag
|
||||
def loadadminextmenu(user):
|
||||
menu = events.raiseQueryEvent("AdminMenuDisplay", "admin_menu_box", user)
|
||||
|
||||
@@ -19,6 +19,7 @@ urlpatterns = patterns(
|
||||
(r'^settings/extensions/save/$', 'saveextensions'),
|
||||
|
||||
(r'^permissions/searchaccount/$', 'search_account'),
|
||||
(r'^permissions/remove/$', 'remove_permission'),
|
||||
|
||||
(r'^identities/$', 'identities'),
|
||||
(r'^identities/import/$', 'import_identities'),
|
||||
|
||||
+33
-7
@@ -69,7 +69,7 @@ def _validate_domain(request, form, successmsg, commonctx, tplname,
|
||||
@login_required
|
||||
@permission_required("admin.add_domain")
|
||||
@transaction.commit_on_success
|
||||
def newdomain(request):
|
||||
def newdomain(request, tplname="admin/newdomainform.html"):
|
||||
events.raiseEvent("CanCreate", request.user, "domains")
|
||||
def newdomain_cb(user, domain):
|
||||
grant_access_to_object(user, domain, is_owner=True)
|
||||
@@ -83,30 +83,39 @@ def newdomain(request):
|
||||
if request.method == "POST":
|
||||
form = DomainForm(request.POST)
|
||||
return _validate_domain(request, form, _("Domain created"), commonctx,
|
||||
"admin/domainform.html",
|
||||
callback=newdomain_cb)
|
||||
tplname, callback=newdomain_cb)
|
||||
form = DomainForm()
|
||||
commonctx["form"] = form
|
||||
return _render(request, "common/generic_modal_form.html", commonctx)
|
||||
return _render(request, tplname, commonctx)
|
||||
|
||||
@login_required
|
||||
@permission_required("admin.change_domain")
|
||||
def editdomain(request, dom_id, tplname="admin/domainform.html"):
|
||||
def editdomain(request, dom_id, tplname="admin/editdomainform.html"):
|
||||
domain = Domain.objects.get(pk=dom_id)
|
||||
if not request.user.can_access(domain):
|
||||
raise PermDeniedException(_("You can't edit this domain"))
|
||||
|
||||
commonctx = {"title" : _("Domain editing"),
|
||||
domadmins = map(lambda oaccess: oaccess.user, domain.owners.all())
|
||||
domadmins = filter(
|
||||
lambda u: request.user.can_access(u) and not u.is_superuser,
|
||||
domadmins
|
||||
)
|
||||
if not request.user.is_superuser:
|
||||
domadmins = filter(lambda u: u.group == "DomainAdmins", domadmins)
|
||||
|
||||
commonctx = {"title" : domain.name,
|
||||
"action_label" : _("Update"),
|
||||
"action_classes" : "submit",
|
||||
"action" : reverse(editdomain, args=[dom_id]),
|
||||
"formid" : "domform"}
|
||||
"formid" : "domform",
|
||||
"domain" : domain}
|
||||
if request.method == "POST":
|
||||
form = DomainForm(request.POST, instance=domain)
|
||||
return _validate_domain(request, form, _("Domain modified"), commonctx, tplname)
|
||||
|
||||
form = DomainForm(instance=domain)
|
||||
commonctx["form"] = form
|
||||
commonctx["domadmins"] = domadmins
|
||||
return _render(request, tplname, commonctx)
|
||||
|
||||
@login_required
|
||||
@@ -420,6 +429,23 @@ def search_account(request):
|
||||
result = map(lambda u: u.username, users.all())
|
||||
return ajax_simple_response(result)
|
||||
|
||||
@login_required
|
||||
@permission_required("admin.add_domain")
|
||||
def remove_permission(request):
|
||||
domid = request.GET.get("domid", None)
|
||||
daid = request.GET.get("daid", None)
|
||||
if domid is None or daid is None:
|
||||
raise AdminError(_("Invalid request"))
|
||||
try:
|
||||
account = User.objects.get(pk=daid)
|
||||
domain = Domain.objects.get(pk=domid)
|
||||
except (User.DoesNotExist, Domain.DoesNotExist):
|
||||
raise AdminError(_("Invalid request"))
|
||||
if not request.user.can_access(account) or not request.user.can_access(domain):
|
||||
raise AdminError(_("Permission denied"))
|
||||
ungrant_access_to_object(domain, account)
|
||||
return ajax_simple_response(dict(status="ok"))
|
||||
|
||||
@login_required
|
||||
@user_passes_test(lambda u: u.is_superuser)
|
||||
def viewparameters(request, tplname='admin/parameters.html'):
|
||||
|
||||
@@ -165,6 +165,14 @@ Webmail.prototype = {
|
||||
});
|
||||
},
|
||||
|
||||
go_back_to_listing: function() {
|
||||
var curmb = this.get_current_mailbox();
|
||||
this.navobject.delparam("mailid").delparam("mbox")
|
||||
.setparams({action: "listmailbox", mbox: curmb});
|
||||
this.restore_nav_params();
|
||||
this.navobject.update();
|
||||
},
|
||||
|
||||
/*
|
||||
* Enable or disable edit and remove actions for the currently
|
||||
* selected mailbox.
|
||||
@@ -838,11 +846,7 @@ Webmail.prototype = {
|
||||
$("#listing").css("overflow", "hidden");
|
||||
$("a[name=close]").click($.proxy(function(e) {
|
||||
e.preventDefault();
|
||||
var curmb = this.get_current_mailbox();
|
||||
this.navobject.delparam("mailid").delparam("mbox")
|
||||
.setparams({action: "listmailbox", mbox: curmb});
|
||||
this.restore_nav_params();
|
||||
this.navobject.update();
|
||||
this.go_back_to_listing();
|
||||
}, this));
|
||||
},
|
||||
|
||||
@@ -863,7 +867,7 @@ Webmail.prototype = {
|
||||
|
||||
delete_callback: function(data) {
|
||||
if (data.status == "ok") {
|
||||
history.go(-2);
|
||||
this.go_back_to_listing();
|
||||
$("body").notify("success", gettext("Message deleted"), 2000);
|
||||
} else {
|
||||
$("body").notify("error", data.respmsg);
|
||||
|
||||
@@ -2,3 +2,25 @@
|
||||
text-align: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
span.title {
|
||||
margin-left: 40px;
|
||||
margin-bottom: 10px;
|
||||
float: left;
|
||||
font-weight: bold;
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
table#domadmins th#actions {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
table#domadmins td[name="actions"] {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.search {
|
||||
width: 85%;
|
||||
-webkit-border-radius:14px;-moz-border-radius:14px;border-radius:14px;
|
||||
padding-left: 14px;
|
||||
}
|
||||
@@ -7,6 +7,18 @@ function domainform_cb() {
|
||||
error_cb: domainform_cb
|
||||
});
|
||||
});
|
||||
$("a[name=removeperm]").click(function(e) {
|
||||
var $tr = $(this).parent().parent();
|
||||
simple_ajax_request.apply(this, [e, {
|
||||
ok_cb: function(resp) {
|
||||
$tr.remove();
|
||||
if (!$("#domadmins").children("tr").length) {
|
||||
$("#admins").html('<div class="alert alert-info">'
|
||||
+ gettext("No domain administrator defined") + "</div>");
|
||||
}
|
||||
}
|
||||
}]);
|
||||
});
|
||||
}
|
||||
|
||||
function accountform_init() {
|
||||
|
||||
+9
-3
@@ -186,15 +186,21 @@ function get_target(e, tag) {
|
||||
/*
|
||||
* Send a simple AJAX request.
|
||||
*/
|
||||
function simple_ajax_request(e) {
|
||||
function simple_ajax_request(e, uoptions) {
|
||||
var $this = $(this);
|
||||
e.preventDefault();
|
||||
var defaults = {};
|
||||
var options = $.extend({}, defaults, uoptions);
|
||||
|
||||
if (e != undefined) e.preventDefault();
|
||||
$.ajax({
|
||||
url: $this.attr("href"),
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
if (data.status == "ok") {
|
||||
$("body").notify("success", data.respmsg, 2000);
|
||||
if (options.ok_cb) options.ok_cb(data);
|
||||
if (options.respmsg) {
|
||||
$("body").notify("success", data.respmsg, 2000);
|
||||
}
|
||||
} else {
|
||||
$("body").notify("error", data.respmsg);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
{% extends "common/generic_modal.html" %}{% load i18n libextras admin_extras %}
|
||||
{% block modalbody %}
|
||||
<ul class="nav nav-pills">
|
||||
<li class="active"><a href="#general" data-toggle="tab">{% trans "General" %}</a></li>
|
||||
<li><a href="#admins" data-toggle="tab">{% trans "Administrators" %}</a></li>
|
||||
<li><a href="#misc" data-toggle="tab">{% trans "Miscellaneous" %}</a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active" id="general">
|
||||
{% if error %}<div class="alert alert-error">{{ error }}</div>{% endif %}
|
||||
<form class="form-horizontal" action="{{ action }}" method="POST" id="{{ formid }}" name="{{ formid }}">
|
||||
{% render_field form.name %}
|
||||
{% render_field form.quota %}
|
||||
{% render_fields_group form "aliases" %}
|
||||
{% render_field form.enabled %}
|
||||
</form>
|
||||
</div>
|
||||
<div class="tab-pane" id="admins">{% if domadmins %}
|
||||
<table id="domadmins" class="table table-condensed">
|
||||
<tr><th>{% trans "Username" %}</th><th>{% trans "Name" %}</th><th></th></tr>
|
||||
{% for da in domadmins %}<tr>
|
||||
<td>{{ da.username }}</td><td>{{ da.fullname }}</td><td name="actions">{% domadmin_actions da.id domain.id %}</td>
|
||||
</tr>{% endfor %}
|
||||
</table>{% else %}<div class="alert alert-info">{% trans "No domain administrator defined" %}</div>{% endif %}
|
||||
</div>
|
||||
<div class="tab-pane" id="misc">
|
||||
<div class="row"><span class="title">{% trans "Creation date" %}</span><span>{{ domain.creation }}</<span></div>
|
||||
<div class="row"><span class="title">{% trans "Last modification date" %}</span><span>{{ domain.last_modification }}</<span></div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -1,6 +1,4 @@
|
||||
{% extends "common/generic_modal_form.html" %}
|
||||
{% load libextras %}
|
||||
{% block formbody %}
|
||||
{% extends "common/generic_modal_form.html" %}{% load libextras %}{% block formbody %}
|
||||
{% render_field form.name %}
|
||||
{% render_field form.quota %}
|
||||
{% render_fields_group form "aliases" %}
|
||||
@@ -1,6 +1,6 @@
|
||||
{% load i18n %}
|
||||
<form id="searchform" class="form-search">
|
||||
<input class="input-medium search-query" type="text"
|
||||
<form id="searchform" class="form-horizontal">
|
||||
<input class="search" type="text"
|
||||
value={% if squery %}"{{ squery }}"{% else %}"{% trans 'Search' %}"{% endif %}
|
||||
id="searchquery" name="searchquery" />
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user