mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
New search field. Gives the possibility to display stats for a specific domain.
Not finished yet! see #333
This commit is contained in:
@@ -6,7 +6,7 @@ Stats.prototype = {
|
||||
constructor: Stats,
|
||||
|
||||
defaults: {
|
||||
deflocation: "graphs/?view=global"
|
||||
deflocation: "graphs/"
|
||||
},
|
||||
|
||||
initialize: function(options) {
|
||||
@@ -16,18 +16,21 @@ Stats.prototype = {
|
||||
var navobj = new History(this.options);
|
||||
this.navobj = navobj;
|
||||
|
||||
if (navobj.params.view != undefined) {
|
||||
$("#searchquery").attr("value", navobj.params.view);
|
||||
if (navobj.params.searchquery != undefined) {
|
||||
$("#searchquery").attr("value", navobj.params.searchquery);
|
||||
}
|
||||
$("#searchquery").focus(function() {
|
||||
$(this).attr("value", "");
|
||||
var $this = $(this);
|
||||
$this.data("oldvalue", $this.attr("value"));
|
||||
$this.attr("value", "");
|
||||
}).blur(function() {
|
||||
var $this = $(this);
|
||||
if ($this.attr("value") == "") {
|
||||
if (navobj.params["view"] == "global") {
|
||||
$this.attr("value", gettext("Search a domain"));
|
||||
if ($this.data("oldvalue")) {
|
||||
$this.attr("value", $this.data('oldvalue'));
|
||||
$this.data("oldvalue", null);
|
||||
} else {
|
||||
$this.attr("value", navobj.params.view);
|
||||
$this.attr("value", gettext("Search a domain"));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -40,13 +43,16 @@ Stats.prototype = {
|
||||
$("#custom-period input").datepicker({
|
||||
format: 'yyyy-mm-dd'
|
||||
});
|
||||
$("#searchquery").autocompleter({
|
||||
choices: get_domains_list,
|
||||
choice_selected: $.proxy(this.search_domain, this)
|
||||
});
|
||||
|
||||
this.register_nav_callbacks();
|
||||
this.listen();
|
||||
},
|
||||
|
||||
listen: function() {
|
||||
$("#searchform").on("keypress", $.proxy(this.search_domain, this));
|
||||
$(".period_selector").click($.proxy(this.change_period, this));
|
||||
$("#customsend").on("click", $.proxy(this.customgraphs, this));
|
||||
},
|
||||
@@ -69,19 +75,13 @@ Stats.prototype = {
|
||||
$("body").notify("error", data.respmsg);
|
||||
return;
|
||||
}
|
||||
$(".tab-pane.active").html(data.content);
|
||||
if (data.content) {
|
||||
$(".tab-pane.active").html(data.content);
|
||||
}
|
||||
},
|
||||
|
||||
search_domain: function(e) {
|
||||
var $input = $(e.target);
|
||||
|
||||
switch (e.which) {
|
||||
case 13:
|
||||
e.preventDefault();
|
||||
var domain = ($input.attr("value") == "") ? "global" : $input.attr("value");
|
||||
this.navobj.setparam("view", domain).update();
|
||||
break;
|
||||
}
|
||||
search_domain: function(value) {
|
||||
this.navobj.setparam("searchquery", value).update();
|
||||
},
|
||||
|
||||
customgraphs: function(e) {
|
||||
|
||||
@@ -3,8 +3,15 @@
|
||||
{% block html_head %}
|
||||
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}stats/css/stats.css" />
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/history.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}js/autocompleter.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}stats/js/stats.js"></script>
|
||||
<script type="text/javascript">
|
||||
function get_domains_list(container) {
|
||||
$.getJSON("{% url modoboa.admin.views.domains_list %}", function(data) {
|
||||
container.value = data;
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
var stats = new Stats({
|
||||
graphurl: "{% url modoboa.extensions.stats.views.graphs %}",
|
||||
@@ -16,6 +23,13 @@ $(document).ready(function() {
|
||||
{% block leftcol %}
|
||||
<div id="periods" class="well sidebar-nav">
|
||||
<ul class="nav nav-list">
|
||||
<li class="nav-header">
|
||||
{% trans "Filter" %}
|
||||
</li>
|
||||
<div class="input-prepend input-append">
|
||||
<span class="add-on"><i class="icon-search"></i></span>
|
||||
<input class="input-medium" id="searchquery" type="text" value="{% trans 'Search a domain' %}">
|
||||
</div>
|
||||
<li class="nav-header">
|
||||
{% trans "Predefined time ranges" %}
|
||||
</li>
|
||||
|
||||
@@ -20,12 +20,10 @@ def index(request):
|
||||
"""
|
||||
FIXME: how to select a default graph set ?
|
||||
"""
|
||||
deflocation = "graphs/?gset=mailtraffic&"
|
||||
if request.user.is_superuser:
|
||||
deflocation += "view=global"
|
||||
else:
|
||||
deflocation = "graphs/?gset=mailtraffic"
|
||||
if not request.user.is_superuser:
|
||||
if len(request.user.get_domains()):
|
||||
deflocation += "view=%s" % request.user.get_domains()[0].name
|
||||
deflocation += "&searchquery=%s" % request.user.get_domains()[0].name
|
||||
else:
|
||||
raise ModoboaException(_("No statistics available"))
|
||||
|
||||
@@ -42,27 +40,24 @@ def index(request):
|
||||
@login_required
|
||||
@user_passes_test(lambda u: u.group != "SimpleUsers")
|
||||
def graphs(request):
|
||||
view = request.GET.get("view", None)
|
||||
gset = request.GET.get("gset", None)
|
||||
gsets = events.raiseDictEvent("GetGraphSets")
|
||||
if not gset in gsets:
|
||||
raise ModoboaException(_("Unknown graphic sets"))
|
||||
if not view:
|
||||
raise ModoboaException(_("Invalid request"))
|
||||
searchq = request.GET.get("searchquery", None)
|
||||
period = request.GET.get("period", "day")
|
||||
tplvars = dict(graphs=[], period=period)
|
||||
if view == "global":
|
||||
if searchq in [None, "global"]:
|
||||
if not request.user.is_superuser:
|
||||
raise PermDeniedException
|
||||
tplvars.update(domain=view)
|
||||
tplvars.update(domain="global")
|
||||
else:
|
||||
try:
|
||||
domain = Domain.objects.get(name=view)
|
||||
except Domain.DoesNotExist:
|
||||
raise ModoboaException(_("Domain not found. Please enter a full name"))
|
||||
if not request.user.can_access(domain):
|
||||
domain = Domain.objects.filter(name__contains=searchq)
|
||||
if len(domain) != 1:
|
||||
return ajax_simple_response({"status" : "ok"})
|
||||
if not request.user.can_access(domain[0]):
|
||||
raise PermDeniedException
|
||||
tplvars.update(domain=domain.name)
|
||||
tplvars.update(domain=domain[0].name)
|
||||
|
||||
if period == "custom":
|
||||
if not request.GET.has_key("start") or not request.GET.has_key("end"):
|
||||
@@ -82,5 +77,6 @@ def graphs(request):
|
||||
tplvars['graphs'] = gsets[gset].get_graph_names()
|
||||
|
||||
return ajax_simple_response(dict(
|
||||
status="ok", content=_render_to_string(request, "stats/graphs.html", tplvars)
|
||||
status="ok",
|
||||
content=_render_to_string(request, "stats/graphs.html", tplvars)
|
||||
))
|
||||
|
||||
@@ -95,6 +95,9 @@
|
||||
0, curvalue.indexOf(this.options.from_character) + 1
|
||||
) + $link.attr("name"));
|
||||
this.hide_menu();
|
||||
if (this.options.choice_selected) {
|
||||
this.options.choice_selected(this.$element.attr('value'));
|
||||
}
|
||||
},
|
||||
|
||||
activate_next: function() {
|
||||
@@ -176,6 +179,8 @@
|
||||
});
|
||||
};
|
||||
|
||||
$.fn.autocompleter.defaults = {};
|
||||
$.fn.autocompleter.defaults = {
|
||||
'choice_selected': null
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
Reference in New Issue
Block a user