From b70987e78210137623c169988d0c940e1da22282 Mon Sep 17 00:00:00 2001 From: tonio Date: Fri, 16 Jul 2010 18:06:17 +0200 Subject: [PATCH] wip: #69, per-user quota display Added ProgressBar mootools plugin bu David Walsh (http://davidwalsh.name/progress-bar-animated-mootools). --- extensions/webmail/lib.py | 19 ++++++++++++++++ extensions/webmail/static/css/webmail.css | 27 +++++++++++++++++++++++ extensions/webmail/templates/index.html | 12 ++++++++++ extensions/webmail/views.py | 2 ++ lib/email_listing.py | 5 ++--- static/js/ProgressBar.js | 19 ++++++++++++++++ templates/common/email_listing.html | 6 ++++- 7 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 static/js/ProgressBar.js diff --git a/extensions/webmail/lib.py b/extensions/webmail/lib.py index 8e366d911..6d1555730 100644 --- a/extensions/webmail/lib.py +++ b/extensions/webmail/lib.py @@ -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) diff --git a/extensions/webmail/static/css/webmail.css b/extensions/webmail/static/css/webmail.css index 45e7ca0c3..d42bf35dd 100644 --- a/extensions/webmail/static/css/webmail.css +++ b/extensions/webmail/static/css/webmail.css @@ -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; +} \ No newline at end of file diff --git a/extensions/webmail/templates/index.html b/extensions/webmail/templates/index.html index cea42b009..9783109ed 100644 --- a/extensions/webmail/templates/index.html +++ b/extensions/webmail/templates/index.html @@ -4,11 +4,23 @@ {% 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); diff --git a/extensions/webmail/views.py b/extensions/webmail/views.py index f905a4588..5aba3a4cd 100644 --- a/extensions/webmail/views.py +++ b/extensions/webmail/views.py @@ -62,6 +62,8 @@ def folder(request, name, updatenav=True): dico["listing"] = "
%s
" \ % _("This folder contains no messages") dico["navbar"] = "" + dico["quota"] = lst.getquota() + ctx = getctx("ok", **dico) return HttpResponse(simplejson.dumps(ctx), mimetype="application/json") diff --git a/lib/email_listing.py b/lib/email_listing.py index a17ef3774..dc2c3f33d 100644 --- a/lib/email_listing.py +++ b/lib/email_listing.py @@ -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, diff --git a/static/js/ProgressBar.js b/static/js/ProgressBar.js new file mode 100644 index 000000000..9ba418f21 --- /dev/null +++ b/static/js/ProgressBar.js @@ -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);}}); \ No newline at end of file diff --git a/templates/common/email_listing.html b/templates/common/email_listing.html index 505a9b236..2c1ef4717 100644 --- a/templates/common/email_listing.html +++ b/templates/common/email_listing.html @@ -3,6 +3,7 @@ {% load libextras %} {% block html_head %} + {% block css %}{% endblock %}