Skip to content

Commit

Permalink
Implement "one click" attachment upload (#5024)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Aug 20, 2016
1 parent c65bb12 commit 43f3c5f
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CHANGELOG Roundcube Webmail
===========================

- Implement "one click" attachment upload (#5024)
- Squirrelmail_usercopy: Add option to define character set of data files
- Removed useless 'created' column from 'session' table (#5389)
- Dropped legacy browsers support (#5167)
Expand Down
4 changes: 3 additions & 1 deletion program/include/rcmail_output_html.php
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,9 @@ protected function login_form($attrib)
// Disable autocapitalization on iPad/iPhone (#1488609)
$attrib['autocapitalize'] = 'off';

$form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
unset($attrib['form']);

// set atocomplete attribute
$user_attrib = $autocomplete > 0 ? array() : array('autocomplete' => 'off');
$host_attrib = $autocomplete > 0 ? array() : array('autocomplete' => 'off');
Expand Down Expand Up @@ -1859,7 +1862,6 @@ protected function login_form($attrib)
+ $attrib + $host_attrib);
}

$form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
$this->add_gui_object('loginform', $form_name);

// create HTML table with two cols
Expand Down
13 changes: 8 additions & 5 deletions program/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4756,13 +4756,16 @@ function rcube_webmail()
// count files and size on capable browser
var size = 0, numfiles = 0;

$('input[type=file]', form).each(function(i, field) {
var files = field.files ? field.files.length : (field.value ? 1 : 0);
$.each($(form).get(0).elements || [], function() {
if (this.type != 'file')
return;

var i, files = this.files ? this.files.length : (this.value ? 1 : 0);

// check file size
if (field.files) {
for (var i=0; i < files; i++)
size += field.files[i].size;
if (this.files) {
for (i=0; i < files; i++)
size += this.files[i].size;
}

numfiles += files;
Expand Down
5 changes: 3 additions & 2 deletions program/lib/Roundcube/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ public static function label($attr, $cont)
$attr = array('for' => $attr);
}

return self::tag('label', $attr, $cont, array_merge(self::$common_attrib, array('for')));
return self::tag('label', $attr, $cont, array_merge(self::$common_attrib,
array('for','onkeypress')));
}

/**
Expand Down Expand Up @@ -395,7 +396,7 @@ class html_inputfield extends html
'type','name','value','size','tabindex','autocapitalize','required',
'autocomplete','checked','onchange','onclick','disabled','readonly',
'spellcheck','results','maxlength','src','multiple','accept',
'placeholder','autofocus','pattern'
'placeholder','autofocus','pattern','form',
);

/**
Expand Down
54 changes: 39 additions & 15 deletions program/steps/mail/compose.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1629,36 +1629,60 @@ function rcmail_compose_attachment_list($attrib)

function rcmail_compose_attachment_form($attrib)
{
global $OUTPUT, $RCMAIL;
global $RCMAIL;

// set defaults
$attrib += array('id' => 'rcmUploadbox', 'buttons' => 'yes');

// Get filesize, enable upload progress bar
$max_filesize = $RCMAIL->upload_init();

$hint = html::div('hint', $RCMAIL->gettext(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize))));
$event = rcmail_output::JS_OBJECT_NAME . ".command('send-attachment', this.form)";
$form_id = $attrib['id'] . 'Frm';
$form_attr = array(
'id' => $form_id,
'name' => 'uploadform',
'method' => 'post',
'enctype' => 'multipart/form-data'
);

$RCMAIL->output->add_gui_object('uploadform', $form_id);

if (rcube_utils::get_boolean($attrib['smart-button'])) {
$form = $RCMAIL->output->form_tag($form_attr);
$RCMAIL->output->add_footer($form);

$input_attrs = $attrib + array(
// Note: Chrome sometimes executes onchange event on Cancel, make sure a file was selected
'onchange' => "if ((this.files && this.files.length) || (!this.files && this.value)) $event",
'form' => $form_id,
'class' => 'smart-upload',
'tabindex' => '-1',
);

$label_attrs = array(
'for' => $attrib['id'],
'id' => $attrib['id'] . 'btn',
'tabindex' => $attrib['tabindex'],
'onkeypress' => 'if (event.keyCode == 13) this.click()',
);

return $hint . rcmail_compose_attachment_field($input_attrs)
. html::label($label_attrs, $RCMAIL->gettext('addattachment'));
}

$button = new html_inputfield(array('type' => 'button'));
$content = html::div(null, rcmail_compose_attachment_field())
. html::div('hint', $RCMAIL->gettext(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize))));
$content = html::div(null, rcmail_compose_attachment_field()) . $hint;

if (rcube_utils::get_boolean($attrib['buttons'])) {
$content .= html::div('buttons',
$button->show($RCMAIL->gettext('close'), array('class' => 'button', 'onclick' => "$('#$attrib[id]').hide()")) . ' ' .
$button->show($RCMAIL->gettext('upload'), array('class' => 'button mainaction', 'onclick' => rcmail_output::JS_OBJECT_NAME . ".command('send-attachment', this.form)"))
$button->show($RCMAIL->gettext('upload'), array('class' => 'button mainaction', 'onclick' => $event))
);
}

$out = html::div($attrib, $OUTPUT->form_tag(array(
'id' => $attrib['id'] . 'Frm',
'name' => 'uploadform',
'method' => 'post',
'enctype' => 'multipart/form-data'
), $content
));

$OUTPUT->add_gui_object('uploadform', $attrib['id'] . 'Frm');

return $out;
return html::div($attrib, $RCMAIL->output->form_tag($form_attr, $content));
}


Expand Down
5 changes: 5 additions & 0 deletions skins/larry/mail.css
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,11 @@ div.message-partheaders .headers-table td.header {
color: #888;
}

#compose-attachments .hint {
color: #666;
margin: 0 0 8px;
}

#composeview-bottom .formbuttons.floating {
position: absolute;
width: auto;
Expand Down
14 changes: 14 additions & 0 deletions skins/larry/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,20 @@ input.mainaction {
font-weight: bold;
}

input.smart-upload {
visibility: hidden;
width: 1px;
height: 1px;
opacity: 0;
}

/** link buttons **/

input.smart-upload + label {
cursor: pointer;
}

input.smart-upload + label,
a.button,
.buttongroup {
display: inline-block;
Expand All @@ -206,6 +218,8 @@ a.button,
white-space: nowrap;
}

input.smart-upload:focus + label,
input.smart-upload + label:focus,
a.button:focus,
input.button:focus {
border-color: #4fadd5;
Expand Down
15 changes: 3 additions & 12 deletions skins/larry/templates/compose.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h2 id="aria-label-toolbar" class="voice"><roundcube:label name="arialabeltoolba
<a href="#languages" class="dropbuttontip" id="spellmenulink" onclick="UI.toggle_popup('spellmenu',event);return false" aria-haspopup="true" aria-expanded="false" tabindex="2">Select Spell Language</a>
</span>
<roundcube:endif />
<roundcube:button name="addattachment" type="link" class="button attach" label="attach" title="addattachment" onclick="UI.show_uploadform(event);return false" aria-haspopup="true" aria-expanded="false"tabindex="2" />
<roundcube:button name="addattachment" type="link" class="button attach" label="attach" title="addattachment" onclick="$('#uploadformbtn').click(); return false" aria-haspopup="true" aria-expanded="false" tabindex="2" />
<roundcube:button command="insert-sig" type="link" class="button insertsig disabled" classAct="button insertsig" label="signature" title="insertsignature" tabindex="2" />
<a href="#responses" class="button responses" label="responses" title="<roundcube:label name='insertresponse' />" id="responsesmenulink" unselectable="on" onmousedown="return false" onclick="UI.toggle_popup('responsesmenu',event);return false" tabindex="2" aria-haspopup="true" aria-expanded="false" aria-owns="textresponsesmenu"><roundcube:label name="responses" /></a>
<roundcube:button command="compose-encrypted" type="link" class="button encrypt disabled" classAct="button encrypt" classSel="button encrypt selected" label="encrypt" title="encryptmessagemailvelope" tabindex="2" style="display:none" />
Expand Down Expand Up @@ -175,8 +175,8 @@ <h2 id="aria-label-composeoptions" class="voice"><roundcube:label name="arialabe
</div>
<div id="compose-attachments" class="rightcol" role="region" aria-labelledby="aria-label-composeattachments">
<h2 id="aria-label-composeattachments" class="voice"><roundcube:label name="attachments" /></h2>
<div style="text-align:center; margin-bottom:20px">
<roundcube:button name="addattachment" type="input" class="button" classSel="button pressed" label="addattachment" onclick="UI.show_uploadform(event);return false" tabindex="1" />
<div style="text-align:center; margin-bottom:10px">
<roundcube:object name="composeAttachmentForm" id="uploadform" smart-button="yes" tabindex="1" />
</div>
<roundcube:object name="composeAttachmentList" id="attachment-list" class="attachmentslist" tabindex="1" />
<roundcube:object name="fileDropArea" id="compose-attachments" />
Expand All @@ -198,15 +198,6 @@ <h2 id="aria-label-composeattachments" class="voice"><roundcube:label name="atta

</div><!-- end mainscreen -->

<div id="upload-dialog" class="propform popupdialog" title="<roundcube:label name='addattachment' />" aria-hidden="true">
<h2 id="aria-label-uploaddialog" class="voice"><roundcube:label name="arialabelattachmentuploadform" /></h2>
<roundcube:object name="composeAttachmentForm" id="uploadform" buttons="no" />
<div class="formbuttons">
<roundcube:button command="send-attachment" type="input" class="button mainaction" label="upload" />
<roundcube:button name="close" type="input" class="button" label="cancel" onclick="UI.show_uploadform()" />
</div>
</div>

<div id="spellmenu" class="popupmenu" aria-hidden="true"></div>

<div id="responsesmenu" class="popupmenu" aria-hidden="true">
Expand Down

0 comments on commit 43f3c5f

Please sign in to comment.