]> git.proxmox.com Git - pmg-gui.git/blob - js/SpamInfoGrid.js
spam info grid: use monospace font for score and level names
[pmg-gui.git] / js / SpamInfoGrid.js
1 Ext.define('PMG.grid.SpamInfoGrid', {
2 extend: 'Ext.grid.GridPanel',
3 xtype: 'pmgSpamInfoGrid',
4
5 store: {
6 autoDestroy: true,
7 fields: ['desc', 'name', { type: 'number', name: 'score' }],
8 proxy: {
9 type: 'proxmox',
10 root: 'data.spaminfo',
11 },
12 sorters: 'score',
13 },
14
15 setID: function(rec) {
16 var me = this;
17 if (!rec || !rec.data || !rec.data.id) {
18 me.getStore().removeAll();
19 return;
20 }
21 var url = '/api2/json/quarantine/content?id=' + rec.data.id;
22 me.store.proxy.setUrl(url);
23 me.store.load();
24 },
25
26 emptyText: gettext('No Spam Info'),
27 hidden: true,
28
29 features: [{
30 ftype: 'summary',
31 }],
32
33 columns: [
34 {
35 text: gettext('Test Name'),
36 dataIndex: 'name',
37 flex: 2,
38 summaryType: 'count',
39 summaryRenderer: function(value, summaryData, dataIndex, metaData) {
40 return gettext('Spamscore');
41 },
42 tdCls: 'txt-monospace',
43 },
44 {
45 text: gettext('Score'),
46 dataIndex: 'score',
47 align: 'right',
48 tdCls: 'txt-monospace',
49 renderer: function(score, metaData) {
50 if (score === 0) {
51 return score;
52 }
53 let absScore = Math.abs(score);
54 let fontWeight = '400', background = score < 0 ? '#d7e9f6' : '#f3d6d7';
55 if (absScore >= 3) {
56 fontWeight = '900';
57 background = score < 0 ? '#ACD1EC' : '#E8B0B2';
58 } else if (absScore >= 1.5) {
59 fontWeight = '600';
60 } else if (absScore <= 0.1) {
61 fontWeight = '200';
62 background = score < 0 ? '#EEF6FB' : '#FAEFF0';
63 }
64 metaData.tdStyle = `font-weight: ${fontWeight};background-color: ${background};`;
65 return score;
66 },
67 summaryType: 'sum',
68 summaryRenderer: function(value, summaryData, dataIndex, metaData) {
69 return Ext.util.Format.round(value, 5);
70 },
71 },
72 {
73 text: gettext('Description'),
74 dataIndex: 'desc',
75 flex: 3,
76 },
77 ],
78 });