Add possibility to rename attachments in mail compose (#4996)

... and fix some small issues related to the new compose attachment menu feature
pull/5284/head^2
Aleksander Machniak 10 years ago
parent a576ca2664
commit ebc2f5dc7d

@ -3,6 +3,7 @@ CHANGELOG Roundcube Webmail
- Require PHP >= 5.4
- Add possibility to preview and download attachments in mail compose (#5053)
- Add possibility to rename attachments in mail compose (#4996)
- Remove backward compatibility "layer" of bc.php (#4902)
- Support WEBP images in mail messages (#5362)
- Support MathML in HTML message preview (#5182)

@ -2255,7 +2255,7 @@ class rcmail extends rcube
$size = $this->show_bytes($size);
}
if (!$this->exact_size) {
if (!$part->exact_size) {
$size = '~' . $size;
}

@ -297,7 +297,7 @@ function rcube_webmail()
this.env.compose_commands = ['send-attachment', 'remove-attachment', 'send', 'cancel',
'toggle-editor', 'list-addresses', 'pushgroup', 'search', 'reset-search', 'extwin',
'insert-response', 'save-response', 'menu-open', 'menu-close', 'load-attachment',
'download-attachment', 'open-attachment'];
'download-attachment', 'open-attachment', 'rename-attachment'];
if (this.env.drafts_mailbox)
this.env.compose_commands.push('savedraft')
@ -4930,6 +4930,59 @@ function rcube_webmail()
this.upload_progress_start(param.action, param.name);
};
// rename uploaded attachment (in compose)
this.rename_attachment = function(id)
{
var attachment = this.env.attachments ? this.env.attachments[id] : null;
if (!attachment)
return;
var input = $('<input>').attr('type', 'text').val(attachment.name),
content = $('<label>').text(this.get_label('namex')).append(input);
this.show_popup_dialog(content, this.get_label('attachmentrename'),
[{
text: this.get_label('save'),
'class': 'mainaction',
click: function() {
var name;
if ((name = input.val()) && name != attachment.name) {
ref.http_post('rename-attachment', {_id: ref.env.compose_id, _file: id, _name: name},
ref.set_busy(true, 'loading'));
}
$(this).dialog('close');
}
}],
{open: function() { input.select(); }}
);
};
// update attachments list with the new name
this.rename_attachment_handler = function(id, name)
{
var attachment = this.env.attachments ? this.env.attachments[id] : null,
item = $('#' + id + ' > a.filename'),
link = $('<a>');
if (!attachment || !name)
return;
attachment.name = name;
// update attachments list
if (item.length == 1) {
// create a new element with new attachment name and cloned size
link.text(name).append($('span', item).clone());
// update attachment name element
item.html(link.html());
// reset parent's title which may contain the old name
item.parent().attr('title', '');
}
};
// send remote request to add a new contact
this.add_contact = function(value)
{
@ -9074,7 +9127,7 @@ rcube_webmail.long_subject_title_ex = function(elem)
rcube_webmail.subject_text = function(elem)
{
var t = $(elem).clone();
t.find('.skip-on-drag,.voice').remove();
t.find('.skip-on-drag,.skip-content,.voice').remove();
return t.text();
};

@ -290,6 +290,7 @@ $labels['uploadprogress'] = '$percent ($current of $total)';
$labels['close'] = 'Close';
$labels['messageoptions'] = 'Message options...';
$labels['togglecomposeoptions'] = 'Toggle composition options';
$labels['attachmentrename'] = 'Rename attachment';
$labels['low'] = 'Low';
$labels['lowest'] = 'Lowest';

@ -36,23 +36,19 @@ if (!$COMPOSE) {
die("Invalid session var!");
}
$file_id = rcube_utils::get_input_value('_file', rcube_utils::INPUT_GPC);
$file_id = preg_replace('/^rcmfile/', '', $file_id) ?: 'unknown';
// remove an attachment
if ($RCMAIL->action == 'remove-attachment') {
$id = 'undefined';
if (preg_match('/^rcmfile(\w+)$/', $_POST['_file'], $regs)) {
$id = $regs[1];
}
if ($attachment = $COMPOSE['attachments'][$id]) {
if ($attachment = $COMPOSE['attachments'][$file_id]) {
$attachment = $RCMAIL->plugins->exec_hook('attachment_delete', $attachment);
}
if ($attachment['status']) {
if (is_array($COMPOSE['attachments'][$id])) {
$RCMAIL->session->remove($SESSION_KEY.'.attachments.'.$id);
$OUTPUT->command('remove_from_attachment_list', "rcmfile$id");
if (is_array($COMPOSE['attachments'][$file_id])) {
$RCMAIL->session->remove($SESSION_KEY . '.attachments.' . $file_id);
$OUTPUT->command('remove_from_attachment_list', "rcmfile$file_id");
}
}
@ -60,14 +56,27 @@ if ($RCMAIL->action == 'remove-attachment') {
exit;
}
if ($RCMAIL->action == 'display-attachment') {
$id = 'undefined';
// rename an attachment
if ($RCMAIL->action == 'rename-attachment') {
$filename = rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST);
$filename = trim($filename);
if (preg_match('/^rcmfile(\w+)$/', $_GET['_file'], $regs)) {
$id = $regs[1];
if (strlen($filename)
&& ($attachment = $COMPOSE['attachments'][$file_id])
&& is_array($attachment)
) {
$attachment['name'] = $filename;
$RCMAIL->session->remove($SESSION_KEY . '.attachments. ' . $file_id);
$RCMAIL->session->append($SESSION_KEY . '.attachments', $attachment['id'], $attachment);
$OUTPUT->command('rename_attachment_handler', "rcmfile$file_id", $filename);
}
$RCMAIL->display_uploaded_file($COMPOSE['attachments'][$id]);
$OUTPUT->send();
exit;
}
if ($RCMAIL->action == 'display-attachment') {
$RCMAIL->display_uploaded_file($COMPOSE['attachments'][$file_id]);
exit;
}
@ -195,11 +204,12 @@ function rcmail_attachment_success($attachment, $uploadid)
$button = '';
}
$link_content = sprintf('%s <span class="attachment-size">(%s)</span>',
$link_content = sprintf('%s <span class="attachment-size"> (%s)</span>',
rcube::Q($attachment['name']), $RCMAIL->show_bytes($attachment['size']));
$content_link = html::a(array(
'href' => "#load",
'class' => 'filename',
'onclick' => sprintf("return %s.command('load-attachment','rcmfile%s', this, event)", rcmail_output::JS_OBJECT_NAME, $id),
), $link_content);

@ -88,7 +88,7 @@ $OUTPUT->add_label('nosubject', 'nosenderwarning', 'norecipientwarning', 'nosubj
'selectimportfile', 'messageissent', 'loadingdata', 'nopubkeyfor', 'nopubkeyforsender',
'encryptnoattachments','encryptedsendialog','searchpubkeyservers', 'importpubkeys',
'encryptpubkeysfound', 'search', 'close', 'import', 'keyid', 'keylength', 'keyexpired',
'keyrevoked', 'keyimportsuccess', 'keyservererror', 'attaching');
'keyrevoked', 'keyimportsuccess', 'keyservererror', 'attaching', 'namex', 'attachmentrename');
$OUTPUT->set_pagetitle($RCMAIL->gettext('compose'));
@ -1569,11 +1569,12 @@ function rcmail_compose_attachment_list($attrib)
continue;
}
$link_content = sprintf('%s <span class="attachment-size">(%s)</span>',
$link_content = sprintf('%s <span class="attachment-size"> (%s)</span>',
rcube::Q($a_prop['name']), $RCMAIL->show_bytes($a_prop['size']));
$content_link = html::a(array(
'href' => "#load",
'class' => 'filename',
'onclick' => sprintf("return %s.command('load-attachment','rcmfile%s', this, event)", rcmail_output::JS_OBJECT_NAME, $id),
), $link_content);

@ -141,6 +141,7 @@ $RCMAIL->register_action_map(array(
'expunge' => 'folders.inc',
'purge' => 'folders.inc',
'remove-attachment' => 'attachments.inc',
'rename-attachment' => 'attachments.inc',
'display-attachment' => 'attachments.inc',
'upload' => 'attachments.inc',
'group-expand' => 'autocomplete.inc',

@ -401,12 +401,11 @@ show_attachmentmenu: function(elem, event)
{
var id = elem.parentNode.id.replace(/^attach/, '');
$('#attachmenuopen').off('click').attr('onclick', '').click(function(e) {
return rcmail.command('open-attachment', id, this);
});
$('#attachmenudownload').off('click').attr('onclick', '').click(function() {
rcmail.command('download-attachment', id, this);
$.each(['open', 'download', 'rename'], function() {
var action = this;
$('#attachmenu' + action).off('click').attr('onclick', '').click(function(e) {
return rcmail.command(action + '-attachment', id, this);
});
});
this.popups.attachmentmenu.link = elem;

@ -218,6 +218,11 @@
background-position: 7px -17px;
}
#attachmentmenu li a.renamelink
{
background-position: 6px -69px;
}
#messagemenu li a.sourcelink
{
background-position: 7px -34px;

@ -220,6 +220,7 @@
<ul class="toolbarmenu">
<li><roundcube:button command="open-attachment" id="attachmenuopen" type="link" label="open" class="openlink" classAct="openlink active" innerclass="openlink" /></li>
<li><roundcube:button command="download-attachment" id="attachmenudownload" type="link" label="download" class="downloadlink" classAct="downloadlink active" innerclass="downloadlink" /></li>
<li><roundcube:button command="rename-attachment" id="attachmenurename" type="link" label="rename" class="renamelink" classAct="renamelink active" innerclass="renamelink" /></li>
<roundcube:container name="attachmentmenu" id="attachmentmenu" />
</ul>
</div>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

@ -2482,6 +2482,10 @@ ul.toolbarmenu li span.download {
background-position: 0 -1412px;
}
ul.toolbarmenu li span.rename {
background-position: 0 -2295px;
}
ul.toolbarmenu li span.edit {
background-position: 0 -1388px;
}

@ -224,6 +224,7 @@
<ul class="toolbarmenu" id="attachmentoptionsmenu" role="menu">
<roundcube:button command="open-attachment" id="attachmenuopen" type="link-menuitem" label="open" class="icon" classAct="icon active" innerclass="icon extwin" />
<roundcube:button command="download-attachment" id="attachmenudownload" type="link-menuitem" label="download" class="icon" classAct="icon active" innerclass="icon download" />
<roundcube:button command="rename-attachment" id="attachmenurename" type="link-menuitem" label="rename" class="icon" classAct="icon active" innerclass="icon rename" />
<roundcube:container name="attachmentmenu" id="attachmentoptionsmenu" />
</ul>
</div>

@ -827,12 +827,11 @@ function rcube_mail_ui()
{
var id = elem.parentNode.id.replace(/^attach/, '');
$('#attachmenuopen').off('click').attr('onclick', '').click(function(e) {
return rcmail.command('open-attachment', id, this);
});
$('#attachmenudownload').off('click').attr('onclick', '').click(function() {
rcmail.command('download-attachment', id, this);
$.each(['open', 'download', 'rename'], function() {
var action = this;
$('#attachmenu' + action).off('click').attr('onclick', '').click(function(e) {
return rcmail.command(action + '-attachment', id, this);
});
});
popupconfig.attachmentmenu.link = elem;
@ -883,7 +882,7 @@ function rcube_mail_ui()
item = $(item);
if (!item.children('.drop').length)
item.append($('<a class="drop" tabindex="0" aria-haspopup="true">Show options</a>')
item.append($('<a class="drop skip-content" tabindex="0" aria-haspopup="true">Show options</a>')
.on('click keypress', function(e) {
if (e.type != 'keypress' || rcube_event.get_keycode(e) == 13) {
attachmentmenu(this, e);

Loading…
Cancel
Save