]>
Commit | Line | Data |
---|---|---|
a10c81d9 DM |
1 | Ext.define('PMG.SubscriptionKeyEdit', { |
2 | extend: 'Proxmox.window.Edit', | |
22b6f5db | 3 | |
a10c81d9 DM |
4 | title: gettext('Upload Subscription Key'), |
5 | width: 300, | |
6 | autoLoad: true, | |
7 | ||
54fd9bd8 DM |
8 | onlineHelp: 'getting_help', |
9 | ||
a10c81d9 DM |
10 | items: { |
11 | xtype: 'textfield', | |
12 | name: 'key', | |
13 | value: '', | |
c87d46fb TL |
14 | fieldLabel: gettext('Subscription Key'), |
15 | }, | |
a10c81d9 DM |
16 | }); |
17 | ||
18 | Ext.define('PMG.Subscription', { | |
19 | extend: 'Proxmox.grid.ObjectGrid', | |
20 | xtype: 'pmgSubscription', | |
21 | ||
ad02dfe7 DC |
22 | title: gettext('Subscription'), |
23 | ||
a151c079 DC |
24 | border: false, |
25 | ||
28580cc2 | 26 | onlineHelp: 'getting_help', |
a10c81d9 | 27 | |
562d589c | 28 | viewConfig: { |
c87d46fb | 29 | enableTextSelection: true, |
562d589c | 30 | }, |
a10c81d9 | 31 | |
35241008 | 32 | showReport: function() { |
28eb60c0 | 33 | let me = this; |
35241008 | 34 | |
28eb60c0 TL |
35 | const getReportFileName = function() { |
36 | let now = Ext.Date.format(new Date(), 'D-d-F-Y-G-i'); | |
c87d46fb | 37 | return Proxmox.NodeName + '-report-' + now + '.txt'; |
35241008 DC |
38 | }; |
39 | ||
28eb60c0 | 40 | let view = Ext.createWidget('component', { |
35241008 DC |
41 | itemId: 'system-report-view', |
42 | scrollable: true, | |
43 | style: { | |
44 | 'background-color': 'white', | |
45 | 'white-space': 'pre', | |
46 | 'font-family': 'monospace', | |
c87d46fb TL |
47 | padding: '5px', |
48 | }, | |
35241008 DC |
49 | }); |
50 | ||
28eb60c0 | 51 | let reportWindow = Ext.create('Ext.window.Window', { |
35241008 DC |
52 | title: gettext('System Report'), |
53 | width: 1024, | |
54 | height: 600, | |
55 | layout: 'fit', | |
56 | modal: true, | |
57 | buttons: [ | |
22b6f5db TL |
58 | '->', |
59 | { | |
60 | text: gettext('Download'), | |
61 | handler: function() { | |
28eb60c0 TL |
62 | let fileContent = Ext.String.htmlDecode(reportWindow.getComponent('system-report-view').html); |
63 | let fileName = getReportFileName(); | |
35241008 | 64 | |
22b6f5db TL |
65 | // Internet Explorer |
66 | if (window.navigator.msSaveOrOpenBlob) { | |
67 | navigator.msSaveOrOpenBlob(new Blob([fileContent]), fileName); | |
68 | } else { | |
28eb60c0 | 69 | let element = document.createElement('a'); |
22b6f5db TL |
70 | element.setAttribute('href', 'data:text/plain;charset=utf-8,' |
71 | + encodeURIComponent(fileContent)); | |
72 | element.setAttribute('download', fileName); | |
73 | element.style.display = 'none'; | |
74 | document.body.appendChild(element); | |
75 | element.click(); | |
76 | document.body.removeChild(element); | |
35241008 | 77 | } |
c87d46fb TL |
78 | }, |
79 | }, | |
22b6f5db | 80 | ], |
c87d46fb | 81 | items: view, |
35241008 DC |
82 | }); |
83 | ||
84 | Proxmox.Utils.API2Request({ | |
85 | url: '/api2/extjs/nodes/' + Proxmox.NodeName + '/report', | |
86 | method: 'GET', | |
87 | waitMsgTarget: me, | |
88 | failure: function(response) { | |
89 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
90 | }, | |
91 | success: function(response) { | |
28eb60c0 | 92 | let report = Ext.htmlEncode(response.result.data); |
35241008 DC |
93 | reportWindow.show(); |
94 | view.update(report); | |
c87d46fb | 95 | }, |
35241008 DC |
96 | }); |
97 | }, | |
98 | ||
c87d46fb | 99 | initComponent: function() { |
28eb60c0 | 100 | let me = this; |
a10c81d9 | 101 | |
28eb60c0 | 102 | const reload = function() { |
a10c81d9 DM |
103 | me.rstore.load(); |
104 | }; | |
105 | ||
28eb60c0 | 106 | let baseurl = `/nodes/${Proxmox.NodeName}/subscription`; |
a10c81d9 | 107 | |
28eb60c0 TL |
108 | let render_status = function(value) { |
109 | let message = me.getObjectValue('message'); | |
a10c81d9 DM |
110 | if (message) { |
111 | return value + ": " + message; | |
112 | } | |
113 | return value; | |
114 | }; | |
115 | ||
28eb60c0 | 116 | let rows = { |
a10c81d9 | 117 | productname: { |
c87d46fb | 118 | header: gettext('Type'), |
a10c81d9 DM |
119 | }, |
120 | key: { | |
c87d46fb | 121 | header: gettext('Subscription Key'), |
a10c81d9 DM |
122 | }, |
123 | status: { | |
124 | header: gettext('Status'), | |
c87d46fb | 125 | renderer: render_status, |
a10c81d9 DM |
126 | }, |
127 | message: { | |
c87d46fb | 128 | visible: false, |
a10c81d9 DM |
129 | }, |
130 | serverid: { | |
c87d46fb | 131 | header: gettext('Server ID'), |
a10c81d9 DM |
132 | }, |
133 | sockets: { | |
c87d46fb | 134 | header: gettext('Sockets'), |
a10c81d9 DM |
135 | }, |
136 | checktime: { | |
137 | header: gettext('Last checked'), | |
c87d46fb | 138 | renderer: Proxmox.Utils.render_timestamp, |
a10c81d9 DM |
139 | }, |
140 | nextduedate: { | |
c87d46fb TL |
141 | header: gettext('Next due date'), |
142 | }, | |
a10c81d9 DM |
143 | }; |
144 | ||
145 | Ext.apply(me, { | |
146 | url: '/api2/json' + baseurl, | |
147 | cwidth1: 170, | |
c87d46fb | 148 | tbar: [ |
a10c81d9 DM |
149 | { |
150 | text: gettext('Upload Subscription Key'), | |
151 | handler: function() { | |
28eb60c0 | 152 | let win = Ext.create('PMG.SubscriptionKeyEdit', { |
c87d46fb | 153 | url: '/api2/extjs/' + baseurl, |
28eb60c0 | 154 | autoShow: true, |
a10c81d9 | 155 | }); |
a10c81d9 | 156 | win.on('destroy', reload); |
c87d46fb | 157 | }, |
a10c81d9 | 158 | }, |
a5db7653 MA |
159 | { |
160 | text: gettext('Remove Subscription'), | |
161 | xtype: 'proxmoxStdRemoveButton', | |
162 | confirmMsg: gettext('Are you sure to remove the subscription key?'), | |
163 | baseurl: baseurl, | |
164 | dangerous: true, | |
165 | selModel: false, | |
166 | callback: reload, | |
167 | }, | |
a10c81d9 DM |
168 | { |
169 | text: gettext('Check'), | |
170 | handler: function() { | |
171 | Proxmox.Utils.API2Request({ | |
172 | params: { force: 1 }, | |
173 | url: baseurl, | |
174 | method: 'POST', | |
175 | waitMsgTarget: me, | |
176 | failure: function(response, opts) { | |
177 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
178 | }, | |
c87d46fb | 179 | callback: reload, |
a10c81d9 | 180 | }); |
c87d46fb | 181 | }, |
35241008 | 182 | }, |
51ef4bbe | 183 | '-', |
35241008 DC |
184 | { |
185 | text: gettext('System Report'), | |
186 | handler: function() { | |
c87d46fb TL |
187 | Proxmox.Utils.checked_command(function() { me.showReport(); }); |
188 | }, | |
189 | }, | |
a10c81d9 | 190 | ], |
c87d46fb | 191 | rows: rows, |
a10c81d9 DM |
192 | }); |
193 | ||
194 | me.callParent(); | |
195 | ||
196 | reload(); | |
c87d46fb | 197 | }, |
a10c81d9 | 198 | }); |