mirror of
https://git.proxmox.com/git/pmg-gui
synced 2025-08-16 01:37:27 +00:00
SpamQuarantine: simplify download button by binding its href config
This avoids all the strange click event hack. We already have a
button where the users needs to click on, so just use that.
A viewModel with a downloadMailURL formula to assemble the href
allows us to just bind the "href" config from the Download button,
and be done with it..
refactors commit 7ad0de10d6
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
8b1d19f3a1
commit
41a290e3f0
@ -48,6 +48,15 @@ Ext.define('PMG.SpamQuarantine', {
|
||||
// from mail link
|
||||
cselect: undefined,
|
||||
|
||||
viewModel: {
|
||||
parent: null,
|
||||
data: {
|
||||
mailid: '',
|
||||
},
|
||||
formulas: {
|
||||
downloadMailURL: get => '/api2/json/quarantine/download?mailid=' + encodeURIComponent(get('mailid')),
|
||||
},
|
||||
},
|
||||
controller: {
|
||||
|
||||
xclass: 'Ext.app.ViewController',
|
||||
@ -147,6 +156,7 @@ Ext.define('PMG.SpamQuarantine', {
|
||||
}
|
||||
var rec = list.selModel.getSelection()[0];
|
||||
|
||||
me.getViewModel().set('mailid', rec.data.id);
|
||||
me.updatePreview(me.raw || false, rec);
|
||||
me.lookupReference('spaminfo').setID(rec);
|
||||
},
|
||||
@ -156,32 +166,6 @@ Ext.define('PMG.SpamQuarantine', {
|
||||
grid.setVisible(!grid.isVisible());
|
||||
},
|
||||
|
||||
downloadEmail: function(btn) {
|
||||
var me = this;
|
||||
var list = this.lookupReference('list');
|
||||
var selection = list.selModel.getSelection();
|
||||
if (selection.length != 1) {
|
||||
return; // multi download is not implemented
|
||||
}
|
||||
var rec = selection[0];
|
||||
var url = "/api2/json/quarantine/download?mailid=" +
|
||||
encodeURIComponent(rec.data.id);
|
||||
var link = Ext.DomHelper.append(document.body, {
|
||||
tag: 'a',
|
||||
href: url,
|
||||
css: 'display:none;visibility:hidden;height: 0px;',
|
||||
download: rec.data.id + '.eml'
|
||||
});
|
||||
|
||||
if (link.fireEvent) {
|
||||
link.fireEvent('onclick');
|
||||
} else {
|
||||
var evt = document.createEvent("MouseEvents");
|
||||
evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
|
||||
link.dispatchEvent(evt);
|
||||
}
|
||||
},
|
||||
|
||||
openContextMenu: function(table, record, tr, index, event) {
|
||||
event.stopEvent();
|
||||
var me = this;
|
||||
@ -235,9 +219,6 @@ Ext.define('PMG.SpamQuarantine', {
|
||||
'button[reference=spam]': {
|
||||
click: 'toggleSpamInfo'
|
||||
},
|
||||
'button[reference=download]': {
|
||||
click: 'downloadEmail'
|
||||
},
|
||||
'pmgQuarantineList': {
|
||||
selectionChange: 'onSelectMail',
|
||||
itemkeypress: 'keyPress',
|
||||
@ -331,6 +312,7 @@ Ext.define('PMG.SpamQuarantine', {
|
||||
xtype: 'button',
|
||||
reference: 'download',
|
||||
text: gettext('Download'),
|
||||
bind: { href: '{downloadMailURL}' },
|
||||
iconCls: 'fa fa-download'
|
||||
},
|
||||
'-',
|
||||
|
Loading…
Reference in New Issue
Block a user