diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index be17fe8b31..7b25693b13 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -2232,6 +2232,15 @@ class mail_ui $content['mail_id']=$rowID; $content['mailDisplayContainerClass']=(count($attachments)?"mailDisplayContainer mailDisplayContainerFixedHeight":"mailDisplayContainer mailDisplayContainerFullHeight"); $content['mailDisplayAttachmentsClass']=(count($attachments)?"mailDisplayAttachments":"mail_DisplayNone"); + + // DRAG attachments actions + $etpl->setElementAttribute('mail_displayattachments', 'actions', array( + 'file_drag' => array( + 'dragType' => 'file', + 'type' => 'drag', + 'onExecute' => 'javaScript:app.mail.drag_attachment' + ) + )); //_debug_array($content); $readonlys = $preserv = $content; $etpl->exec('mail.mail_ui.displayMessage',$content,$sel_options,$readonlys,$preserv,2); @@ -2272,7 +2281,7 @@ class mail_ui $attachmentHTML[$key]['partID']=$value['partID']; $attachmentHTML[$key]['winmailFlag']=$value['is_winmail']; $attachmentHTML[$key]['classSaveAllPossiblyDisabled'] = "mail_DisplayNone"; - + switch(strtoupper($value['mimeType'])) { case 'MESSAGE/RFC822': diff --git a/mail/js/app.js b/mail/js/app.js index 55f8dfe705..f75a4e49ae 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -140,6 +140,12 @@ app.classes.mail = AppJS.extend( } } window.resizeTo((w_h[0]?w_h[0]:870),(w_h[1]?w_h[1]:(screen.availHeight>egw_getWindowOuterHeight()?screen.availHeight:egw_getWindowOuterHeight()))); + + // Register attachments for drag + this.register_for_drag( + this.et2.getArrayMgr("content").getEntry('mail_id'), + this.et2.getArrayMgr("content").getEntry('mail_displayattachments') + ); break; case 'mail.compose': var that = this; @@ -912,6 +918,67 @@ app.classes.mail = AppJS.extend( { egw.jsonq('mail.mail_ui.ajax_refreshVacationNotice',[_server]); }, + /** + * Make sure attachments have all needed data, so they can be found for + * HTML5 native dragging + * + * @param {string} mail_id Mail UID + * @param {array} attachments Attachment information. + */ + register_for_drag: function(mail_id, attachments) + { + // Put required info in global store + var data = {}; + for (var i = 0; i < attachments.length; i++) + { + var data = attachments[i] || {}; + if(!data.filename || !data.type) continue; + + // Add required info + data.mime = data.type; + data.download_url = egw.link('/index.php', { + menuaction: 'mail.mail_ui.getAttachment', + id: mail_id, + part: data.partID, + is_winmail: data.winmailFlag + }); + data.name = data.filename; + } + }, + + /** + * Display helper for dragging attachments + * + * @param {egwAction} _action + * @param {egwActionElement[]} _elems + * @returns {DOMNode} + */ + drag_attachment: function(_action, _elems) + { + var div = $j(document.createElement("div")) + .css({ + position: 'absolute', + top: '0px', + left: '0px', + width: '300px' + }); + + var data = _elems[0].data || {}; + + var text = $j(document.createElement('div')).css({left: '30px', position: 'absolute'}); + // add filename or number of files for multiple files + text.text(_elems.length > 1 ? _elems.length+' '+this.egw.lang('files') : data.name || ''); + div.append(text); + + // Add notice of Ctrl key, if supported + if(window.FileReader && 'draggable' in document.createElement('span') && + navigator && navigator.userAgent.indexOf('Chrome') >= 0) + { + var key = ["Mac68K","MacPPC","MacIntel"].indexOf(window.navigator.platform) < 0 ? 'Ctrl' : 'Command'; + text.append('
' + this.egw.lang('Hold %1 to drag files to your computer',key)); + } + return div; + }, /** * mail_refreshVacationNotice, function to call with appropriate data to refresh the vacationnotice for the active server