]> git.proxmox.com Git - proxmox-backup.git/blob - www/Subscription.js
0780c4d411742bc1b3810d6f8f291dfbc5e5cd5e
[proxmox-backup.git] / www / Subscription.js
1 Ext.define('PBS.SubscriptionKeyEdit', {
2 extend: 'Proxmox.window.Edit',
3
4 title: gettext('Upload Subscription Key'),
5 width: 320,
6 autoLoad: true,
7
8 onlineHelp: 'get_help',
9
10 items: {
11 xtype: 'proxmoxtextfield',
12 trimValue: true,
13 labelWidth: 120,
14 name: 'key',
15 value: '',
16 fieldLabel: gettext('Subscription Key'),
17 },
18 });
19
20 Ext.define('PBS.Subscription', {
21 extend: 'Proxmox.grid.ObjectGrid',
22 xtype: 'pbsSubscription',
23
24 title: gettext('Subscription'),
25 border: true,
26
27 onlineHelp: 'get_help',
28 tools: [PBS.Utils.get_help_tool("get_help")],
29
30 viewConfig: {
31 enableTextSelection: true,
32 },
33
34 showReport: function() {
35 var me = this;
36
37 var getReportFileName = function() {
38 var now = Ext.Date.format(new Date(), 'D-d-F-Y-G-i');
39 return `${me.nodename}-pbs-report-${now}.txt`;
40 };
41
42 var view = Ext.createWidget('component', {
43 itemId: 'system-report-view',
44 scrollable: true,
45 style: {
46 'white-space': 'pre',
47 'font-family': 'monospace',
48 padding: '5px',
49 },
50 });
51
52 let reportWindow;
53 reportWindow = Ext.create('Ext.window.Window', {
54 title: gettext('System Report'),
55 width: 1024,
56 height: 600,
57 layout: 'fit',
58 modal: true,
59 buttons: [
60 '->',
61 {
62 text: gettext('Download'),
63 handler: function() {
64 let fileContent = Ext.htmlDecode(reportWindow.getComponent('system-report-view').html);
65 let fileName = getReportFileName();
66
67 let dataUrl = `data:text/plain;charset=utf-8,${encodeURIComponent(fileContent)}`;
68
69 Proxmox.Utils.downloadAsFile(dataUrl, fileName);
70 },
71 },
72 ],
73 items: view,
74 });
75
76 Proxmox.Utils.API2Request({
77 url: '/api2/extjs/nodes/' + me.nodename + '/report',
78 method: 'GET',
79 waitMsgTarget: me,
80 success: function(response) {
81 var report = Ext.htmlEncode(response.result.data);
82 reportWindow.show();
83 view.update(report);
84 },
85 });
86 },
87
88 initComponent: function() {
89 let me = this;
90
91 let reload = () => me.rstore.load();
92 let baseurl = '/nodes/localhost/subscription';
93
94 let rows = {
95 productname: {
96 header: gettext('Type'),
97 },
98 key: {
99 header: gettext('Subscription Key'),
100 },
101 status: {
102 header: gettext('Status'),
103 renderer: (value) => {
104 value = Ext.String.capitalize(value);
105 let message = me.getObjectValue('message');
106 if (message) {
107 return value + ": " + message;
108 }
109 return value;
110 },
111 },
112 message: {
113 visible: false,
114 },
115 serverid: {
116 header: gettext('Server ID'),
117 },
118 checktime: {
119 header: gettext('Last checked'),
120 renderer: Proxmox.Utils.render_timestamp,
121 },
122 nextduedate: {
123 header: gettext('Next due date'),
124 },
125 signature: {
126 header: gettext('Signed/Offline'),
127 renderer: (value) => {
128 if (value) {
129 return gettext('Yes');
130 } else {
131 return gettext('No');
132 }
133 },
134 },
135 };
136
137 Ext.apply(me, {
138 url: `/api2/json${baseurl}`,
139 cwidth1: 170,
140 tbar: [
141 {
142 text: gettext('Upload Subscription Key'),
143 iconCls: 'fa fa-ticket',
144 handler: function() {
145 Ext.create('PBS.SubscriptionKeyEdit', {
146 url: '/api2/extjs/' + baseurl,
147 autoShow: true,
148 listeners: {
149 destroy: () => reload(),
150 },
151 });
152 },
153 },
154 {
155 text: gettext('Check'),
156 iconCls: 'fa fa-check-square-o',
157 handler: function() {
158 Proxmox.Utils.API2Request({
159 params: { force: 1 },
160 url: baseurl,
161 method: 'POST',
162 waitMsgTarget: me,
163 callback: reload,
164 });
165 },
166 },
167 {
168 text: gettext('Remove Subscription'),
169 xtype: 'proxmoxStdRemoveButton',
170 confirmMsg: gettext('Are you sure you want to remove the subscription key?'),
171 baseurl: baseurl,
172 dangerous: true,
173 selModel: false,
174 callback: reload,
175 iconCls: 'fa fa-trash-o',
176 },
177 '-',
178 {
179 text: gettext('System Report'),
180 iconCls: 'fa fa-stethoscope',
181 handler: function() {
182 Proxmox.Utils.checked_command(function() { me.showReport(); });
183 },
184 },
185 ],
186 rows: rows,
187 });
188
189 me.callParent();
190
191 reload();
192 },
193 });