summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2011-07-04 11:40:02 +0000
committeralecpl <alec@alec.pl>2011-07-04 11:40:02 +0000
commit4171c59bd79a54c1fd65128f7100247a4dec8720 (patch)
tree3261b05d91324840570c8ebe6b1084e26793701d
parent5b3ac324154b0d29e6e14db2b06fbc3636a3e708 (diff)
- Add optional textual upload progress indicator (#1486039)
-rw-r--r--CHANGELOG1
-rw-r--r--config/main.inc.php.dist5
-rw-r--r--program/include/main.inc42
-rw-r--r--program/js/app.js41
-rw-r--r--program/localization/en_US/labels.inc1
-rw-r--r--program/steps/mail/attachments.inc4
-rw-r--r--program/steps/mail/compose.inc5
7 files changed, 96 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index f3c995ca4..d9c7d9c06 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
CHANGELOG Roundcube Webmail
===========================
+- Add optional textual upload progress indicator (#1486039)
- Fix parsing URLs containing commas (#1487970)
- Added vertical splitter for books/groups list in addressbook (#1487923)
- Improved namespace roots handling in folder manager
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 3994a9480..56e5a793e 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -437,6 +437,11 @@ $rcmail_config['max_pagesize'] = 200;
// Must be less than 'session_lifetime'
$rcmail_config['min_keep_alive'] = 60;
+// Enables files upload indicator. Requires APC installed and enabled apc.rfc1867 option.
+// By default refresh time is set to 1 second. You can set this value to true
+// or any integer value indicating number of seconds.
+$rcmail_config['upload_progress'] = false;
+
// ----------------------------------
// ADDRESSBOOK SETTINGS
// ----------------------------------
diff --git a/program/include/main.inc b/program/include/main.inc
index 7e2875ae9..2a5a66020 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -2080,3 +2080,45 @@ function rcube_log_bug($arg_arr)
}
}
+function rcube_upload_progress()
+{
+ global $RCMAIL;
+
+ $prefix = ini_get('apc.rfc1867_prefix');
+ $params = array(
+ 'action' => $RCMAIL->action,
+ 'name' => get_input_value('_progress', RCUBE_INPUT_GET),
+ );
+
+ if (function_exists('apc_fetch')) {
+ $status = apc_fetch($prefix . $params['name']);
+
+ if (!empty($status)) {
+ $status['percent'] = $status['current']/$status['total']*100;
+ $params = array_merge($status, $params);
+ }
+ }
+
+ if (isset($params['percent']))
+ $params['text'] = rcube_label(array('name' => 'uploadprogress', 'vars' => array(
+ 'percent' => $params['percent'] . '%',
+ 'current' => show_bytes($params['current']),
+ 'total' => show_bytes($params['total'])
+ )));
+console($params);
+ $RCMAIL->output->command('upload_progress_update', $params);
+ $RCMAIL->output->send();
+}
+
+function rcube_upload_progress_init()
+{
+ global $RCMAIL;
+
+ // Enable upload progress bar
+ if (($seconds = $RCMAIL->config->get('upload_progress')) && ini_get('apc.rfc1867')) {
+ if ($field_name = ini_get('apc.rfc1867_name')) {
+ $RCMAIL->output->set_env('upload_progress_name', $field_name);
+ $RCMAIL->output->set_env('upload_progress_time', (int) $seconds);
+ }
+ }
+}
diff --git a/program/js/app.js b/program/js/app.js
index 53ae463b2..f3298cfac 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -3264,14 +3264,19 @@ function rcube_webmail()
});
// display upload indicator and cancel button
- var content = this.get_label('uploading' + (files > 1 ? 'many' : '')),
+ var content = '<span>' + this.get_label('uploading' + (files > 1 ? 'many' : '')) + '</span>',
ts = frame_name.replace(/^rcmupload/, '');
- if (this.env.loadingicon)
+ if (!this.env.upload_progress_time && this.env.loadingicon)
content = '<img src="'+this.env.loadingicon+'" alt="" />'+content;
if (this.env.cancelicon)
content = '<a title="'+this.get_label('cancel')+'" onclick="return rcmail.cancel_attachment_upload(\''+ts+'\', \''+frame_name+'\');" href="#cancelupload"><img src="'+this.env.cancelicon+'" alt="" /></a>'+content;
this.add2attachment_list(ts, { name:'', html:content, complete:false });
+
+ // upload progress support
+ if (this.env.upload_progress_time) {
+ this.upload_progress_start('upload', ts);
+ }
}
// set reference to the form object
@@ -3336,6 +3341,25 @@ function rcube_webmail()
return false;
};
+ this.upload_progress_start = function(action, name)
+ {
+ window.setTimeout(function() { rcmail.http_request(action, {_progress: name}); },
+ this.env.upload_progress_time * 1000);
+ };
+
+ this.upload_progress_update = function(param)
+ {
+ var elem = $('#'+param.name + '> span');
+
+ if (!elem.length || !param.text)
+ return;
+
+ elem.text(param.text);
+
+ if (!param.done)
+ this.upload_progress_start(param.action, param.name);
+ };
+
// send remote request to add a new contact
this.add_contact = function(value)
{
@@ -5602,6 +5626,19 @@ function rcube_webmail()
var ts = new Date().getTime(),
frame_name = 'rcmupload'+ts;
+ // upload progress support
+ if (this.env.upload_progress_name) {
+ var fname = this.env.upload_progress_name,
+ field = $('input[name='+fname+']', form);
+
+ if (!field.length) {
+ field = $('<input>').attr({type: 'hidden', name: fname});
+ field.appendTo(form);
+ }
+
+ field.val(ts);
+ }
+
// have to do it this way for IE
// otherwise the form will be posted to a new window
if (document.all) {
diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc
index 401bc1e2e..b2f136b71 100644
--- a/program/localization/en_US/labels.inc
+++ b/program/localization/en_US/labels.inc
@@ -210,6 +210,7 @@ $labels['revertto'] = 'Revert to';
$labels['attachments'] = 'Attachments';
$labels['upload'] = 'Upload';
+$labels['uploadprogress'] = '$percent ($current from $total)';
$labels['close'] = 'Close';
$labels['messageoptions'] = 'Message options...';
diff --git a/program/steps/mail/attachments.inc b/program/steps/mail/attachments.inc
index 14712c628..4674034a1 100644
--- a/program/steps/mail/attachments.inc
+++ b/program/steps/mail/attachments.inc
@@ -19,6 +19,10 @@
*/
+// Upload progress update
+if (!empty($_GET['_progress'])) {
+ rcube_upload_progress();
+}
$COMPOSE_ID = get_input_value('_id', RCUBE_INPUT_GPC);
$_SESSION['compose'] = $_SESSION['compose_data'][$COMPOSE_ID];
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 943c800b5..458441fda 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -1199,12 +1199,15 @@ function rcmail_compose_attachment_list($attrib)
function rcmail_compose_attachment_form($attrib)
{
- global $OUTPUT;
+ global $RCMAIL, $OUTPUT;
// add ID if not given
if (!$attrib['id'])
$attrib['id'] = 'rcmUploadbox';
+ // Enable upload progress bar
+ rcube_upload_progress_init();
+
// find max filesize value
$max_filesize = parse_bytes(ini_get('upload_max_filesize'));
$max_postsize = parse_bytes(ini_get('post_max_size'));