]> git.proxmox.com Git - pmg-gui.git/blob - js/VirusQuarantine.js
drop jslint hint for Proxmox global
[pmg-gui.git] / js / VirusQuarantine.js
1 /*jslint confusion: true*/
2 /*format is a string and a function*/
3 Ext.define('pmg-virus-list', {
4 extend: 'Ext.data.Model',
5 fields: ['id', 'envelope_sender', 'from', 'sender', 'receiver', 'subject',
6 { type: 'integer', name: 'bytes' },
7 { type: 'string', name: 'virusname' },
8 { type: 'date', dateFormat: 'timestamp', name: 'time' },
9 {
10 type: 'string',
11 name: 'day',
12 convert: function(v, rec) {
13 return Ext.Date.format(rec.get('time'), 'Y-m-d');
14 }, depends: ['time'],
15 },
16 ],
17 proxy: {
18 type: 'proxmox',
19 url: "/api2/json/quarantine/virus",
20 },
21 idProperty: 'id',
22 });
23
24 Ext.define('PMG.VirusQuarantine', {
25 extend: 'Ext.container.Container',
26 xtype: 'pmgVirusQuarantine',
27
28 border: false,
29 layout: { type: 'border' },
30
31 defaults: { border: false },
32
33 controller: {
34
35 xclass: 'Ext.app.ViewController',
36
37 updatePreview: function(raw) {
38 var list = this.lookupReference('list');
39 var rec = list.selModel.getSelection()[0];
40 var preview = this.lookupReference('preview');
41
42 if (!rec || !rec.data || !rec.data.id) {
43 preview.update('');
44 preview.setDisabled(true);
45 return;
46 }
47
48 var url = '/api2/htmlmail/quarantine/content?id=' + rec.data.id + (raw?'&raw=1':'');
49 preview.setDisabled(false);
50 preview.update("<iframe frameborder=0 width=100% height=100% sandbox='allow-same-origin' src='" + url +"'></iframe>");
51 },
52
53 toggleRaw: function(button) {
54 var me = this;
55 me.lookup('mailinfo').setVisible(me.raw);
56 me.raw = !me.raw;
57 me.updatePreview(me.raw);
58 },
59
60 btnHandler: function(button, e) {
61 var list = this.lookupReference('list');
62 var selected = list.getSelection();
63 if (!selected.length) {
64 return;
65 }
66
67 var action = button.reference;
68
69 PMG.Utils.doQuarantineAction(action, selected[0].data.id, function() {
70 list.getController().load();
71 });
72 },
73
74 onSelectMail: function() {
75 var me = this;
76 me.updatePreview(me.raw || false);
77 let mailinfo = me.lookup('mailinfo');
78 let list = me.lookup('list');
79 let selection = list.getSelection();
80 if (selection.length < 1) {
81 mailinfo.setVisible(false);
82 return;
83 }
84 mailinfo.setVisible(!me.raw);
85 mailinfo.update(selection[0].data);
86 },
87
88 control: {
89 'button[reference=raw]': {
90 click: 'toggleRaw',
91 },
92 'pmgQuarantineList': {
93 selectionChange: 'onSelectMail',
94 },
95 },
96
97 },
98
99 items: [
100 {
101 title: gettext('Virus Quarantine'),
102 xtype: 'pmgQuarantineList',
103 emptyText: gettext('No data in database'),
104 emailSelection: false,
105 reference: 'list',
106 region: 'west',
107 width: 500,
108 split: true,
109 collapsible: false,
110 store: {
111 model: 'pmg-virus-list',
112 groupField: 'day',
113 groupDir: 'DESC',
114 sorters: [{
115 property: 'time',
116 direction: 'DESC',
117 }],
118 },
119
120 columns: [
121 {
122 header: gettext('Sender/Subject'),
123 dataIndex: 'subject',
124 renderer: PMG.Utils.sender_renderer,
125 flex: 1,
126 },
127 {
128 header: gettext('Virus'),
129 dataIndex: 'virusname',
130 align: 'right',
131 width: 70,
132 },
133 {
134 header: gettext('Size') + ' (KB)',
135 renderer: function(v) { return Ext.Number.toFixed(v/1024, 0); },
136 dataIndex: 'bytes',
137 align: 'right',
138 width: 90,
139 },
140 {
141 header: gettext('Date'),
142 dataIndex: 'day',
143 hidden: true,
144 },
145 {
146 xtype: 'datecolumn',
147 header: gettext('Time'),
148 dataIndex: 'time',
149 format: 'H:m:s',
150 },
151 ],
152 },
153 {
154 title: gettext('Selected Mail'),
155 border: false,
156 region: 'center',
157 split: true,
158 reference: 'preview',
159 disabled: true,
160 dockedItems: [
161 {
162 xtype: 'toolbar',
163 dock: 'top',
164 items: [
165 {
166 xtype: 'button',
167 reference: 'raw',
168 text: gettext('Toggle Raw'),
169 enableToggle: true,
170 iconCls: 'fa fa-file-code-o',
171 },
172 '->',
173 {
174 reference: 'deliver',
175 text: gettext('Deliver'),
176 iconCls: 'fa fa-paper-plane-o',
177 handler: 'btnHandler',
178 },
179 {
180 reference: 'delete',
181 text: gettext('Delete'),
182 iconCls: 'fa fa-trash-o',
183 handler: 'btnHandler',
184 },
185 ],
186 },
187 {
188 xtype: 'pmgMailInfo',
189 hidden: true,
190 reference: 'mailinfo',
191 },
192 ],
193 },
194 ],
195 });