Implement new mail attachments block actions

This commit is contained in:
Hadi Nategh 2022-07-27 14:21:21 +02:00
parent 0ad3cf9832
commit 7c053d9dad
5 changed files with 98 additions and 25 deletions

View File

@ -785,4 +785,38 @@ class mail_hooks
] ]
]; ];
} }
/**
* options for attachments block actions
* @return string[][]
*/
public static function attachmentsBlockActions()
{
return [
'downloadOneAsFile' => [
'id' => 'downloadOneAsFile',
'label' => 'Download',
'icon' => 'fileexport',
'value' => 'downloadOneAsFile'
],
'saveOneToVfs' => [
'id' => 'saveOneToVfs',
'label' => 'Save in Filemanager',
'icon' => 'filemanager/navbar.svg',
'value' => 'saveOneToVfs'
],
'saveAllToVfs' => [
'id' => 'saveAllToVfs',
'label' => 'Save all to Filemanager',
'icon' => 'mail/save_all',
'value' => 'saveAllToVfs'
],
'downloadAllToZip' => [
'id' => 'downloadAllToZip',
'label' => 'Save as ZIP',
'icon' => 'mail/save_zip',
'value' => 'downloadAllToZip'
]
];
}
} }

View File

@ -2305,6 +2305,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
{ {
$content['mail_displayattachments'] = $attachmentHTMLBlock; $content['mail_displayattachments'] = $attachmentHTMLBlock;
$content['attachmentsBlockTitle'] = count($attachmentHTMLBlock).' '.Lang('attachments'); $content['attachmentsBlockTitle'] = count($attachmentHTMLBlock).' '.Lang('attachments');
$sel_options['mail_displayattachments']['actions'] = mail_hooks::attachmentsBlockActions();
} }
$content['mail_id']=$rowID; $content['mail_id']=$rowID;
@ -2468,8 +2469,10 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
$attachmentHTML[$key]['partID']=$value['partID']; $attachmentHTML[$key]['partID']=$value['partID'];
$attachmentHTML[$key]['mail_id'] = $rowID; $attachmentHTML[$key]['mail_id'] = $rowID;
$attachmentHTML[$key]['winmailFlag']=$value['is_winmail']; $attachmentHTML[$key]['winmailFlag']=$value['is_winmail'];
$attachmentHTML[$key]['classSaveAllPossiblyDisabled'] = "mail_DisplayNone";
$attachmentHTML[$key]['smime_type'] = $value['smime_type']; $attachmentHTML[$key]['smime_type'] = $value['smime_type'];
$attachmentHTML[$key]['actions'] = 'downloadOneAsFile';
$attachmentHTML[$key]['actionsDefaultLabel'] = 'Download';
// reset mode array as it should be considered differently for // reset mode array as it should be considered differently for
// each attachment // each attachment
$mode = array(); $mode = array();
@ -2579,12 +2582,7 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
'smime_type' => $value['smime_type'] 'smime_type' => $value['smime_type']
); );
$attachmentHTML[$key]['link_save'] ="<a href='".Egw::link('/index.php',$linkData)."' title='".$attachmentHTML[$key]['filename']."'>".Api\Html::image('mail','fileexport')."</a>"; $attachmentHTML[$key]['link_save'] ="<a href='".Egw::link('/index.php',$linkData)."' title='".$attachmentHTML[$key]['filename']."'>".Api\Html::image('mail','fileexport')."</a>";
// add save-all and download zip icon for first attachment only
// if more than one attachments.
if ($key == 0 && count($attachments) > 1)
{
$attachmentHTML[$key]['classSaveAllPossiblyDisabled'] = "";
}
if (!$GLOBALS['egw_info']['user']['apps']['filemanager']) $attachmentHTML[$key]['no_vfs'] = true; if (!$GLOBALS['egw_info']['user']['apps']['filemanager']) $attachmentHTML[$key]['no_vfs'] = true;
} }
$attachmentHTMLBlock="<table width='100%'>"; $attachmentHTMLBlock="<table width='100%'>";

View File

@ -1016,6 +1016,19 @@ app.classes.mail = AppJS.extend(
} }
}, },
/**
* Handle actions from attachments block
* @param _e
* @param _widget
*/
attachmentsBlockActions: function(_e, _widget)
{
const id = _widget.id.replace('[actions]','');
const action = _widget.value;
_widget.label = _widget.select_options.filter(_item=>{return _item.value == _widget.value})[0].label;
this.saveAttachmentHandler(_widget,action, id);
},
/** /**
* mail_preview - implementation of the preview action * mail_preview - implementation of the preview action
* *
@ -1025,6 +1038,7 @@ app.classes.mail = AppJS.extend(
mail_preview: function(selected, nextmatch) { mail_preview: function(selected, nextmatch) {
let data = {}; let data = {};
let rowId = ''; let rowId = '';
let sel_options = {}
let attachmentsBlock = this.et2.getWidgetById('attachmentsBlock'); let attachmentsBlock = this.et2.getWidgetById('attachmentsBlock');
let mailPreview = this.et2.getWidgetById('mailPreview'); let mailPreview = this.et2.getWidgetById('mailPreview');
if(typeof selected != 'undefined' && selected.length == 1) if(typeof selected != 'undefined' && selected.length == 1)
@ -1069,8 +1083,46 @@ app.classes.mail = AppJS.extend(
}); });
} }
if (data.attachmentsBlock) data.attachmentsBlockTitle = `${data.attachmentsBlock.length} attachments`; if (data.attachmentsBlock)
mailPreview.set_value({content:data}); {
const actions = [
{
id: 'downloadOneAsFile',
label:'Download',
icon:'fileexport',
value:'downloadOneAsFile'
},
{
id: 'saveOneToVfs',
label: 'Save in Filemanager',
icon: 'filemanager/navbar.svg',
value: 'saveOneToVfs'
},
{
id: 'saveAllToVfs',
label: 'Save all to Filemanager',
icon: 'mail/save_all',
value: 'saveAllToVfs'
},
{
id: 'downloadAllToZip',
label: 'Save as ZIP',
icon: 'mail/save_zip',
value: 'downloadAllToZip'
}
];
data.attachmentsBlockTitle = `${data.attachmentsBlock.length} attachments`;
data.attachmentsBlock.forEach(_item => {
_item.actions='downloadOneAsFile';
// for some reason label needs to be set explicitly for the dropdown button. It needs more investigation.
_item.actionsDefaultLabel='Download';
});
sel_options.attachmentsBlock = {actions:actions};
}
mailPreview.set_value({content:data, sel_options:sel_options});
if (selected && selected.length>1) if (selected && selected.length>1)
{ {

View File

@ -98,9 +98,7 @@
<column disabled="!@showtempname"/> <column disabled="!@showtempname"/>
<column width="70%" /> <column width="70%" />
<column width="11%" /> <column width="11%" />
<column width="3%"/> <column width="10%"/>
<column width="3%"/>
<column width="3%"/>
<column /> <column />
</columns> </columns>
<rows> <rows>
@ -111,10 +109,7 @@
<description id="${row}[winmailFlag]" /> <description id="${row}[winmailFlag]" />
<description class="et2_link useEllipsis" id="${row}[filename]" no_lang="1" expose_view="true" mime="$row_cont[type]" mime_data="$row_cont[mime_data]" href="$row_cont[mime_url]"/> <description class="et2_link useEllipsis" id="${row}[filename]" no_lang="1" expose_view="true" mime="$row_cont[type]" mime_data="$row_cont[mime_data]" href="$row_cont[mime_url]"/>
<description align="right" id="${row}[size]"/> <description align="right" id="${row}[size]"/>
<buttononly id="${row}[save]" image="fileexport" readonly="false" onclick="app.mail.saveAttachmentHandler(widget,'downloadOneAsFile', ${row})"/> <et2-dropdown-button id="${row}[actions]" label="$row_cont[actionsDefaultLabel]" readonly="false" onchange="app.mail.attachmentsBlockActions" onclick="app.mail.attachmentsBlockActions"/>
<buttononly id="${row}[saveAsVFS]" image="filemanager/navbar" readonly="false" onclick="app.mail.saveAttachmentHandler(widget,'saveOneToVfs', ${row})"/>
<buttononly class="$row_cont[classSaveAllPossiblyDisabled]" readonly="false" id="${row}[save_all]" image="mail/save_all" onclick="app.mail.saveAttachmentHandler(widget,'saveAllToVfs', ${row})"/>
<buttononly class="$row_cont[classSaveAllPossiblyDisabled]" readonly="false" id="${row}[save_zip]" image="mail/save_zip" onclick="app.mail.saveAttachmentHandler(widget,'downloadAllToZip', ${row})" label="Save as Zip"/>
</row> </row>
</rows> </rows>
</grid> </grid>

View File

@ -90,23 +90,17 @@
<column disabled="!@showtempname"/> <column disabled="!@showtempname"/>
<column width="70%" /> <column width="70%" />
<column width="11%" /> <column width="11%" />
<column width="3%"/> <column width="10%"/>
<column width="3%"/>
<column width="3%"/>
<column />
</columns> </columns>
<rows> <rows>
<row class="row attachmentRow"> <row class="row attachmentRow" id="${row}">
<description id="${row}[attachment_number]" /> <description id="${row}[attachment_number]" />
<description id="${row}[partID]" /> <description id="${row}[partID]" />
<description id="${row}[type]" /> <description id="${row}[type]" />
<description id="${row}[winmailFlag]" /> <description id="${row}[winmailFlag]" />
<description class="et2_link useEllipsis" id="${row}[filename]" no_lang="1" expose_view="true" mime="$row_cont[type]" mime_data="$row_cont[mime_data]" href="$row_cont[mime_url]"/> <description class="et2_link useEllipsis" id="${row}[filename]" no_lang="1" expose_view="true" mime="$row_cont[type]" mime_data="$row_cont[mime_data]" href="$row_cont[mime_url]"/>
<description align="right" id="${row}[size]"/> <description align="right" id="${row}[size]"/>
<buttononly id="${row}[save]" image="fileexport" readonly="false" onclick="app.mail.saveAttachmentHandler(widget,'downloadOneAsFile', ${row})" statustext="Download as file"/> <et2-dropdown-button id="${row}[actions]" label="$row_cont[actionsDefaultLabel]" onchange="app.mail.attachmentsBlockActions" onclick="app.mail.attachmentsBlockActions"/>
<buttononly id="${row}[saveAsVFS]" image="filemanager/navbar" readonly="false" onclick="app.mail.saveAttachmentHandler(widget,'saveOneToVfs', ${row})" statustext="Save to Filemanager"/>
<buttononly class="$row_cont[classSaveAllPossiblyDisabled]" readonly="false" id="${row}[save_all]" image="mail/save_all" onclick="app.mail.saveAttachmentHandler(widget,'saveAllToVfs', ${row})" statustext="Save all"/>
<buttononly class="$row_cont[classSaveAllPossiblyDisabled]" readonly="false" id="${row}[save_zip]" image="mail/save_zip" onclick="app.mail.saveAttachmentHandler(widget,'downloadAllToZip', ${row})" statustext="Save as Zip"/>
</row> </row>
</rows> </rows>
</grid> </grid>