From 9d3d600a2557608824cacfdbf4055bca9985f026 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 23 May 2018 09:49:31 +0200 Subject: [PATCH] Display a dialog for mail import with supported format description and upload size hint --- CHANGELOG | 1 + program/js/app.js | 8 +- program/localization/en_US/labels.inc | 4 +- program/steps/mail/func.inc | 15 +++- .../elastic/templates/includes/mail-menu.html | 7 +- skins/elastic/templates/mail.html | 2 - skins/elastic/ui.js | 24 +++++- skins/larry/templates/mail.html | 4 +- skins/larry/ui.js | 74 ++++--------------- 9 files changed, 66 insertions(+), 73 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7c8a6e042..1f96ad79d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -57,6 +57,7 @@ CHANGELOG Roundcube Webmail - Reset onerror on images if placeholder does not exist to prevent from requests storm - Unified and simplified code for loading content frame for responses and identities - Display contact import and advanced search in popup dialogs +- Display a dialog for mail import with supported format description and upload size hint - Make possible to set (some) config options from a skin - Added optional checkbox selection for the list widget - Make 'compose' command always enabled diff --git a/program/js/app.js b/program/js/app.js index 69f9bbcf3..f96c1bec4 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -1430,7 +1430,13 @@ function rcube_webmail() ret = false; this.triggerEvent('actionafter', { props:props, action:command, aborted:aborted, ret:ret, originalEvent:event}); - return ret === false ? false : obj ? false : true; + if (ret === false) + return false; + + if (obj || aborted === true) + return false; + + return true; }; // set command(s) enabled or disabled diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc index 3638b5332..7238b7dcf 100644 --- a/program/localization/en_US/labels.inc +++ b/program/localization/en_US/labels.inc @@ -223,6 +223,8 @@ $labels['folderactions'] = 'Folder actions...'; $labels['compact'] = 'Compact'; $labels['empty'] = 'Empty'; $labels['importmessages'] = 'Import messages'; +$labels['mailimportdesc'] = 'You can upload mail using files in MIME or Mbox format.'; +$labels['mailimportzip'] = 'Multiple files can be compressed into zip archives.'; $labels['quota'] = 'Disk usage'; $labels['unknown'] = 'unknown'; @@ -479,7 +481,7 @@ $labels['importreplace'] = 'Replace the entire address book'; $labels['importgroups'] = 'Import group assignments'; $labels['importgroupsall'] = 'All (create groups if necessary)'; $labels['importgroupsexisting'] = 'Only for existing groups'; -$labels['importdesc'] = 'You can upload contacts from an existing address book.
We currently support importing addresses from the vCard or CSV (comma-separated) data format.'; +$labels['importdesc'] = 'You can upload contacts from an existing address book.
We currently support importing addresses from the vCard or CSV (comma-separated) data format.'; $labels['done'] = 'Done'; // settings diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 36b3ec218..0ab2dba0f 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -1687,16 +1687,23 @@ function rcmail_message_import_form($attrib = array()) { global $RCMAIL; - $RCMAIL->output->add_label('selectimportfile','importwait'); + $RCMAIL->output->add_label('selectimportfile', 'importwait', 'importmessages'); - $input_attr = array( + $description = $RCMAIL->gettext('mailimportdesc'); + $input_attr = array( 'multiple' => true, 'name' => '_file[]', - 'accept' => ".eml, .mbox, message/rfc822, text/*", + 'accept' => '.eml, .mbox, .msg, message/rfc822, text/*', ); + if (class_exists('ZipArchive', false)) { + $input_attr['accept'] .= '.zip, application/zip, application/x-zip'; + $description .= ' ' . $RCMAIL->gettext('mailimportzip'); + } + $attrib['prefix'] = html::tag('input', array('type' => 'hidden', 'name' => '_unlock', 'value' => '')) - . html::tag('input', array('type' => 'hidden', 'name' => '_framed', 'value' => '1')); + . html::tag('input', array('type' => 'hidden', 'name' => '_framed', 'value' => '1')) + . html::p(null, $description); return $RCMAIL->upload_form($attrib, 'importform', 'import-messages', $input_attr); } diff --git a/skins/elastic/templates/includes/mail-menu.html b/skins/elastic/templates/includes/mail-menu.html index 302f4e734..f6eb35562 100644 --- a/skins/elastic/templates/includes/mail-menu.html +++ b/skins/elastic/templates/includes/mail-menu.html @@ -61,7 +61,8 @@ + + + + diff --git a/skins/elastic/templates/mail.html b/skins/elastic/templates/mail.html index 99ad32d7c..3ffcc1124 100644 --- a/skins/elastic/templates/mail.html +++ b/skins/elastic/templates/mail.html @@ -184,6 +184,4 @@ - - diff --git a/skins/elastic/ui.js b/skins/elastic/ui.js index e38735334..a89bb54aa 100644 --- a/skins/elastic/ui.js +++ b/skins/elastic/ui.js @@ -59,6 +59,7 @@ function rcube_elastic_ui() this.popup_init = popup_init; this.about_dialog = about_dialog; this.headers_dialog = headers_dialog; + this.import_dialog = import_dialog; this.headers_show = headers_show; this.spellmenu = spellmenu; this.searchmenu = searchmenu; @@ -2238,8 +2239,7 @@ function rcube_elastic_ui() dialog = rcmail.simple_dialog(dialog, rcmail.gettext('listoptionstitle'), save_func, { closeOnEscape: true, - minWidth: 400, - width: width + minWidth: 400 }); }; @@ -2261,7 +2261,6 @@ function rcube_elastic_ui() button: support_button, button_class: 'help', cancel_button: 'close', - width: 600, height: 400 }); }; @@ -2285,11 +2284,28 @@ function rcube_elastic_ui() rcmail.simple_dialog(dialog, rcmail.gettext('arialabelmessageheaders'), null, { cancel_button: 'close', - width: 600, height: 400 }); }; + /** + * Mail import dialog + */ + function import_dialog() + { + var content = $('#uploadform'), + dialog = content.clone(); + + var save_func = function(e) { + return rcmail.command('import-messages', $(dialog.find('form')[0])); + }; + + rcmail.simple_dialog(dialog, rcmail.gettext('importmessages'), save_func, { + closeOnEscape: true, + minWidth: 400 + }); + }; + /** * Search options menu popup */ diff --git a/skins/larry/templates/mail.html b/skins/larry/templates/mail.html index 1c853fe88..72c28697c 100644 --- a/skins/larry/templates/mail.html +++ b/skins/larry/templates/mail.html @@ -171,7 +171,7 @@ - + @@ -262,7 +262,7 @@ - + diff --git a/skins/larry/ui.js b/skins/larry/ui.js index 10b03c078..a5f9c9083 100644 --- a/skins/larry/ui.js +++ b/skins/larry/ui.js @@ -40,9 +40,9 @@ function rcube_mail_ui() this.show_popup = show_popup; this.toggle_popup = toggle_popup; this.add_popup = add_popup; + this.import_dialog = import_dialog; this.set_searchmod = set_searchmod; this.set_searchscope = set_searchscope; - this.show_uploadform = show_uploadform; this.show_header_row = show_header_row; this.hide_header_row = hide_header_row; this.update_quota = update_quota; @@ -181,8 +181,7 @@ function rcube_mail_ui() } } else if (rcmail.env.action == 'compose') { - rcmail.addEventListener('aftersend-attachment', show_uploadform) - .addEventListener('fileappended', function(e) { if (e.attachment.complete) attachmentmenu_append(e.item); }) + rcmail.addEventListener('fileappended', function(e) { if (e.attachment.complete) attachmentmenu_append(e.item); }) .addEventListener('aftertoggle-editor', function(e) { window.setTimeout(function() { layout_composeview() }, 200); if (e && e.mode) @@ -235,8 +234,7 @@ function rcube_mail_ui() rcmail.init_pagejumper('#pagejumper'); rcmail.addEventListener('setquota', update_quota) - .addEventListener('layout-change', mail_layout) - .addEventListener('afterimport-messages', show_uploadform); + .addEventListener('layout-change', mail_layout); } else if (rcmail.env.action == 'get') { new rcube_splitter({ id:'mailpartsplitterv', p1:'#messagepartheader', p2:'#messagepartcontainer', @@ -300,8 +298,7 @@ function rcube_mail_ui() } /*** addressbook task ***/ else if (rcmail.env.task == 'addressbook') { - rcmail.addEventListener('afterupload-photo', show_uploadform) - .addEventListener('beforepushgroup', push_contactgroup) + rcmail.addEventListener('beforepushgroup', push_contactgroup) .addEventListener('beforepopgroup', pop_contactgroup) .addEventListener('menu-open', menu_toggle) .addEventListener('menu-close', menu_toggle); @@ -1078,63 +1075,24 @@ function rcube_mail_ui() }); } - function show_uploadform(e) + /** + * Mail import dialog + */ + function import_dialog() { - var $dialog = $('#upload-dialog'); + var content = $('#uploadform'), + dialog = content.clone().removeClass('popupdialog'); - // close the dialog - if ($dialog.is(':visible')) { - $dialog.dialog('close'); - return; - } + var save_func = function(e) { + return rcmail.command('import-messages', $(dialog.find('form')[0])); + }; - // do nothing if mailvelope editor is active - if (rcmail.mailvelope_editor) - return; - - // add icons to clone file input field - if (rcmail.env.action == 'compose' && !$dialog.data('extended')) { - $('') - .addClass('iconlink add') - .attr('href', '#add') - .html('Add') - .appendTo($('input[type="file"]', $dialog).parent()) - .click(add_uploadfile); - $dialog.data('extended', true); - } - - $dialog.dialog({ - modal: true, - resizable: false, + rcmail.simple_dialog(dialog, rcmail.gettext('importmessages'), save_func, { closeOnEscape: true, - title: $dialog.attr('title'), - open: function(e) { - if (!document.all) - $('input[type=file]', $dialog).first().click(); - }, - close: function() { - try { $('#upload-dialog form').get(0).reset(); } - catch(e){ } // ignore errors - - $dialog.dialog('destroy').hide(); - $('div.addline', $dialog).remove(); - }, - width: 480 - }).show(); - } - - function add_uploadfile(e) - { - var div = $(this).parent(); - var clone = div.clone().addClass('addline').insertAfter(div); - clone.children('.iconlink').click(add_uploadfile); - clone.children('input').val(''); - - if (!document.all) - $('input[type=file]', clone).click(); + minWidth: 400 + }); } - /** * */