summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
Diffstat (limited to 'program')
-rw-r--r--program/js/app.js64
-rw-r--r--program/steps/mail/func.inc67
2 files changed, 91 insertions, 40 deletions
diff --git a/program/js/app.js b/program/js/app.js
index f98cf5f80..83162a983 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -3914,8 +3914,12 @@ function rcube_webmail()
// replace content of quota display
this.set_quota = function(content)
{
- if (content && this.gui_objects.quotadisplay)
- $(this.gui_objects.quotadisplay).html(content);
+ if (content && this.gui_objects.quotadisplay) {
+ if (typeof(content) == 'object')
+ this.percent_indicator(this.gui_objects.quotadisplay, content);
+ else
+ $(this.gui_objects.quotadisplay).html(content);
+ }
};
// update the mailboxlist
@@ -4044,6 +4048,61 @@ function rcube_webmail()
elem.onclick = function() { rcmail.load_headers(elem); }
}
+ // percent (quota) indicator
+ this.percent_indicator = function(obj, data)
+ {
+ if (!data || !obj)
+ return false;
+
+ var limit_high = 80;
+ var limit_mid = 55;
+ var width = data.width ? data.width : this.env.indicator_width ? this.env.indicator_width : 100;
+ var height = data.height ? data.height : this.env.indicator_height ? this.env.indicator_height : 24;
+ var quota = data.percent ? Math.abs(parseInt(data.percent)) : 0;
+ var quota_width = parseInt(quota / 100 * width);
+ var pos = $(obj).position();
+
+ this.env.indicator_width = width;
+ this.env.indicator_height = height;
+
+ // overlimit
+ if (quota_width > width) {
+ quota_width = width;
+ quota = 100;
+ }
+
+ // main div
+ var main = $('<div>');
+ main.css({position: 'absolute', top: pos.top, left: pos.left,
+ width: width + 'px', height: height + 'px', zIndex: 100, lineHeight: height + 'px'})
+ .attr('title', data.title).addClass('quota_text').html(quota + '%');
+ // used bar
+ var bar1 = $('<div>');
+ bar1.css({position: 'absolute', top: pos.top + 1, left: pos.left + 1,
+ width: quota_width + 'px', height: height + 'px', zIndex: 99});
+ // background
+ var bar2 = $('<div>');
+ bar2.css({position: 'absolute', top: pos.top + 1, left: pos.left + 1,
+ width: width + 'px', height: height + 'px', zIndex: 98})
+ .addClass('quota_bg');
+
+ if (quota >= limit_high) {
+ main.addClass(' quota_text_high');
+ bar1.addClass('quota_high');
+ }
+ else if(quota >= limit_mid) {
+ main.addClass(' quota_text_mid');
+ bar1.addClass('quota_mid');
+ }
+ else {
+ main.addClass(' quota_text_normal');
+ bar1.addClass('quota_low');
+ }
+
+ // replace quota image
+ obj.innerHTML = '';
+ $(obj).append(bar1).append(bar2).append(main);
+ }
/********************************************************/
/********* html to text conversion functions *********/
@@ -4326,4 +4385,3 @@ function rcube_webmail()
rcube_webmail.prototype.addEventListener = rcube_event_engine.prototype.addEventListener;
rcube_webmail.prototype.removeEventListener = rcube_event_engine.prototype.removeEventListener;
rcube_webmail.prototype.triggerEvent = rcube_event_engine.prototype.triggerEvent;
-
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 445b89d94..b13796745 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -517,8 +517,16 @@ function rcmail_quota_display($attrib)
$_SESSION['quota_display'] = $attrib['display'];
$OUTPUT->add_gui_object('quotadisplay', $attrib['id']);
-
- return html::span($attrib, rcmail_quota_content(NULL, $attrib));
+
+ $quota = rcmail_quota_content(NULL, $attrib);
+
+ if (is_array($quota)) {
+ $OUTPUT->add_script('$(document).ready(function(){
+ rcmail.set_quota('.json_serialize($quota).')});', 'foot');
+ $quota = '';
+ }
+
+ return html::span($attrib, $quota);
}
@@ -528,49 +536,34 @@ function rcmail_quota_content($quota=NULL, $attrib=NULL)
$display = isset($_SESSION['quota_display']) ? $_SESSION['quota_display'] : '';
- if (is_array($quota) && !empty($quota['used']) && !empty($quota['total']))
- {
- if (!isset($quota['percent']))
- $quota['percent'] = $quota['used'] / $quota['total'];
+ if (empty($quota)) {
+ if (!$IMAP->get_capability('QUOTA'))
+ return rcube_label('unknown');
+ else
+ $quota = $IMAP->get_quota();
}
- elseif (!$IMAP->get_capability('QUOTA'))
- return rcube_label('unknown');
- else
- $quota = $IMAP->get_quota();
if ($quota && !($quota['total']==0 && $RCMAIL->config->get('quota_zero_as_unlimited')))
{
- $quota_text = sprintf('%s / %s (%.0f%%)',
- show_bytes($quota['used'] * 1024),
- show_bytes($quota['total'] * 1024),
- $quota['percent']);
-
- // show quota as image (by Brett Patterson)
- if ($display == 'image' && function_exists('imagegif'))
- {
- if (!$attrib['width'])
- $attrib['width'] = isset($_SESSION['quota_width']) ? $_SESSION['quota_width'] : 100;
- else
- $_SESSION['quota_width'] = $attrib['width'];
-
- if (!$attrib['height'])
- $attrib['height'] = isset($_SESSION['quota_height']) ? $_SESSION['quota_height'] : 14;
- else
- $_SESSION['quota_height'] = $attrib['height'];
-
- $quota_text = sprintf('<img src="./bin/quotaimg.php?u=%s&amp;q=%d&amp;w=%d&amp;h=%d" width="%d" height="%d" alt="%s" title="%s / %s" />',
- $quota['used'], $quota['total'],
- $attrib['width'], $attrib['height'],
- $attrib['width'], $attrib['height'],
- $quota_text,
- show_bytes($quota['used'] * 1024),
- show_bytes($quota['total'] * 1024));
+ $quota_result = sprintf('%s / %s (%.0f%%)',
+ show_bytes($quota['used'] * 1024), show_bytes($quota['total'] * 1024),
+ $quota['percent']);
+
+ if ($display == 'image') {
+ $quota_result = array(
+ 'percent' => $quota['percent'],
+ 'title' => $quota_result,
+ );
+ if ($attrib['width'])
+ $quota_result['width'] = $attrib['width'];
+ if ($attrib['height'])
+ $quota_result['height'] = $attrib['height'];
}
}
else
- $quota_text = rcube_label('unlimited');
+ return rcube_label('unlimited');
- return $quota_text;
+ return $quota_result;
}