mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-19 05:58:34 +02:00
wip: #69, per-user quota display
Added ProgressBar mootools plugin bu David Walsh (http://davidwalsh.name/progress-bar-animated-mootools).
This commit is contained in:
@@ -225,6 +225,7 @@ class IMAPconnector(object):
|
||||
(status, data) = self.m.sort("(%s)" % criterion, "UTF-8", "(NOT DELETED)",
|
||||
*self.criterions)
|
||||
self.messages = data[0].split()
|
||||
self.getquota(folder)
|
||||
return len(self.messages)
|
||||
|
||||
def unseen_messages(self, folder):
|
||||
@@ -302,6 +303,17 @@ class IMAPconnector(object):
|
||||
self.m.select(self._encodefolder(folder))
|
||||
self.m.expunge()
|
||||
|
||||
def getquota(self, folder):
|
||||
status, data = self.m.getquotaroot(self._encodefolder(folder))
|
||||
if status == "OK":
|
||||
quotadef = data[1][0]
|
||||
m = re.match("[^\s]+ \(STORAGE (\d+) (\d+)\)", quotadef)
|
||||
if not m:
|
||||
print "Problem while parsing quota def"
|
||||
return
|
||||
self.quota_limit = int(m.group(2))
|
||||
self.quota_actual = int(m.group(1))
|
||||
|
||||
def fetch(self, start=None, stop=None, folder=None, all=False):
|
||||
if not start and not stop:
|
||||
return []
|
||||
@@ -404,6 +416,13 @@ class ImapListing(EmailListing):
|
||||
unicode(or_criterion(criterions, '%s "%s"' % (key, pattern)))
|
||||
self.mbc.criterions = [unicode("(%s)" % criterions)]
|
||||
|
||||
def getquota(self):
|
||||
try:
|
||||
return int(float(self.mbc.quota_actual) \
|
||||
/ float(self.mbc.quota_limit) * 100)
|
||||
except AttributeError:
|
||||
return -1
|
||||
|
||||
class ImapEmail(Email):
|
||||
def __init__(self, msg, addrfull=False, *args, **kwargs):
|
||||
Email.__init__(self, msg, *args, **kwargs)
|
||||
|
||||
@@ -173,3 +173,30 @@ textarea:hover {
|
||||
#mailheader {
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
/* Progress bar */
|
||||
#quotabox {
|
||||
float: left;
|
||||
margin: 5px;
|
||||
width: 250px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#box {
|
||||
border: 1px solid #ccc;
|
||||
width: 200px;
|
||||
height: 15px;
|
||||
}
|
||||
|
||||
#perc {
|
||||
background: green;
|
||||
height: 15px;
|
||||
}
|
||||
|
||||
#quotatext {
|
||||
font-family:tahoma, arial, sans-serif;
|
||||
font-size:11px;
|
||||
color:#000;
|
||||
|
||||
padding: 3px 0 0 10px;
|
||||
}
|
||||
@@ -4,11 +4,23 @@
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/webmail.css" />
|
||||
{% endblock %}
|
||||
{% block js %}
|
||||
quota_pb = new ProgressBar({
|
||||
container: $("quotabox"),
|
||||
startPercentage: 0,
|
||||
boxID: "box",
|
||||
percentageID: "perc",
|
||||
displayText: true,
|
||||
displayID: "quotatext"
|
||||
});
|
||||
|
||||
wm_updatelisting = function(resp) {
|
||||
updatelisting(resp);
|
||||
if ($defined(resp.folders)) {
|
||||
$("folders").set("html", resp.folders);
|
||||
}
|
||||
if ($defined(resp.quota) && resp.quota != "-1") {
|
||||
quota_pb.set(resp.quota);
|
||||
}
|
||||
$$("a[name=loadfolder]").addEvent("click", foldercallback);
|
||||
$$("a[name=compose]").addEvent("click", loadCompose);
|
||||
$$("a[name=empty]").addEvent("click", empty);
|
||||
|
||||
@@ -62,6 +62,8 @@ def folder(request, name, updatenav=True):
|
||||
dico["listing"] = "<div class='info'>%s</div>" \
|
||||
% _("This folder contains no messages")
|
||||
dico["navbar"] = ""
|
||||
dico["quota"] = lst.getquota()
|
||||
|
||||
ctx = getctx("ok", **dico)
|
||||
return HttpResponse(simplejson.dumps(ctx), mimetype="application/json")
|
||||
|
||||
|
||||
@@ -103,9 +103,8 @@ class EmailListing:
|
||||
def render_navbar(self, page):
|
||||
if page is None:
|
||||
return ""
|
||||
return render_to_string("common/navbar.html", {
|
||||
"page" : page
|
||||
})
|
||||
context = {"page" : page}
|
||||
return render_to_string("common/navbar.html", context)
|
||||
|
||||
def fetch(self, request, id_start, id_stop):
|
||||
table = self.tbltype(self.mbc.fetch(start=id_start, stop=id_stop,
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
---
|
||||
description: ProgressBar
|
||||
|
||||
authors:
|
||||
- David Walsh (http://davidwalsh.name)
|
||||
|
||||
license:
|
||||
- MIT-style license
|
||||
|
||||
requires:
|
||||
core/1.2.1: '*'
|
||||
more/1.2.1: 'Fx.*'
|
||||
|
||||
provides:
|
||||
- ProgressBar
|
||||
...
|
||||
*/
|
||||
var ProgressBar=new Class({Implements:[Events,Options],options:{container:document.body,boxID:"progress-bar-box-id",percentageID:"progress-bar-percentage-id",displayID:"progress-bar-display-id",startPercentage:0,displayText:false,speed:10,step:1,allowMore:false,onComplete:$empty,onChange:$empty},initialize:function(a){this.setOptions(a);this.options.container=document.id(this.options.container);this.createElements();},createElements:function(){var b=new Element("div",{id:this.options.boxID});var a=new Element("div",{id:this.options.percentageID,style:"width:0px;"});a.inject(b);b.inject(this.options.container);if(this.options.displayText){var c=new Element("div",{id:this.options.displayID});c.inject(this.options.container);}this.set(this.options.startPercentage);},calculate:function(a){return(document.id(this.options.boxID).getStyle("width").replace("px","")*(a/100)).toInt();},animate:function(b){var c=false;var a=this;if(!a.options.allowMore&&b>100){b=100;}a.to=b.toInt();document.id(a.options.percentageID).set("morph",{duration:this.options.speed,link:"cancel",onComplete:function(){a.fireEvent("change",[a.to]);if(b>=100){a.fireEvent("complete",[a.to]);}}}).morph({width:a.calculate(b)});if(a.options.displayText){document.id(a.options.displayID).set("text",a.to+"%");}},set:function(a){this.animate(a);},step:function(){this.set(this.to+this.options.step);}});
|
||||
@@ -3,6 +3,7 @@
|
||||
{% load libextras %}
|
||||
{% block html_head %}
|
||||
<link rel="stylesheet" type="text/css" href="/static/css/searchbar.css" />
|
||||
<script type="text/javascript" src="/static/js/ProgressBar.js"></script>
|
||||
{% block css %}{% endblock %}
|
||||
<style type="text/css">
|
||||
#navbar {
|
||||
@@ -72,5 +73,8 @@ window.addEvent("domready", function() {
|
||||
<div id="listing">{{ listing }}</div>
|
||||
<div class="spacer"></div>
|
||||
{% endblock %}
|
||||
{% block footer %}<div id="navbar">{{ navbar }}</div>{% endblock %}
|
||||
{% block footer %}
|
||||
<div id="quotabox"></div>
|
||||
<div id="navbar">{{ navbar }}</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user