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