]>
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: 'proxmoxtextfield', | |
12 | trimValue: true, | |
13 | name: 'key', | |
14 | value: '', | |
15 | fieldLabel: gettext('Subscription Key'), | |
16 | }, | |
17 | }); | |
18 | ||
19 | Ext.define('PMG.Subscription', { | |
20 | extend: 'Proxmox.grid.ObjectGrid', | |
21 | xtype: 'pmgSubscription', | |
22 | ||
23 | title: gettext('Subscription'), | |
24 | ||
25 | border: false, | |
26 | ||
27 | onlineHelp: 'getting_help', | |
28 | ||
29 | viewConfig: { | |
30 | enableTextSelection: true, | |
31 | }, | |
32 | ||
33 | showReport: function() { | |
34 | let me = this; | |
35 | ||
36 | const getReportFileName = function() { | |
37 | let now = Ext.Date.format(new Date(), 'D-d-F-Y-G-i'); | |
38 | return Proxmox.NodeName + '-report-' + now + '.txt'; | |
39 | }; | |
40 | ||
41 | let view = Ext.createWidget('component', { | |
42 | itemId: 'system-report-view', | |
43 | scrollable: true, | |
44 | style: { | |
45 | 'white-space': 'pre', | |
46 | 'font-family': 'monospace', | |
47 | padding: '5px', | |
48 | }, | |
49 | }); | |
50 | ||
51 | let reportWindow = Ext.create('Ext.window.Window', { | |
52 | title: gettext('System Report'), | |
53 | width: 1024, | |
54 | height: 600, | |
55 | layout: 'fit', | |
56 | modal: true, | |
57 | buttons: [ | |
58 | '->', | |
59 | { | |
60 | text: gettext('Download'), | |
61 | handler: function() { | |
62 | let fileContent = Ext.String.htmlDecode(reportWindow.getComponent('system-report-view').html); | |
63 | let fileName = getReportFileName(); | |
64 | ||
65 | // Internet Explorer | |
66 | if (window.navigator.msSaveOrOpenBlob) { | |
67 | navigator.msSaveOrOpenBlob(new Blob([fileContent]), fileName); | |
68 | } else { | |
69 | let element = document.createElement('a'); | |
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); | |
77 | } | |
78 | }, | |
79 | }, | |
80 | ], | |
81 | items: view, | |
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) { | |
92 | let report = Ext.htmlEncode(response.result.data); | |
93 | reportWindow.show(); | |
94 | view.update(report); | |
95 | }, | |
96 | }); | |
97 | }, | |
98 | ||
99 | initComponent: function() { | |
100 | let me = this; | |
101 | ||
102 | const reload = function() { | |
103 | me.rstore.load(); | |
104 | }; | |
105 | ||
106 | let baseurl = `/nodes/${Proxmox.NodeName}/subscription`; | |
107 | ||
108 | let render_status = function(value) { | |
109 | let message = me.getObjectValue('message'); | |
110 | if (message) { | |
111 | return value + ": " + message; | |
112 | } | |
113 | return value; | |
114 | }; | |
115 | ||
116 | let rows = { | |
117 | productname: { | |
118 | header: gettext('Type'), | |
119 | }, | |
120 | key: { | |
121 | header: gettext('Subscription Key'), | |
122 | }, | |
123 | status: { | |
124 | header: gettext('Status'), | |
125 | renderer: render_status, | |
126 | }, | |
127 | message: { | |
128 | visible: false, | |
129 | }, | |
130 | serverid: { | |
131 | header: gettext('Server ID'), | |
132 | }, | |
133 | sockets: { | |
134 | header: gettext('Sockets'), | |
135 | }, | |
136 | checktime: { | |
137 | header: gettext('Last checked'), | |
138 | renderer: Proxmox.Utils.render_timestamp, | |
139 | }, | |
140 | nextduedate: { | |
141 | header: gettext('Next due date'), | |
142 | }, | |
143 | }; | |
144 | ||
145 | Ext.apply(me, { | |
146 | url: '/api2/json' + baseurl, | |
147 | cwidth1: 170, | |
148 | tbar: [ | |
149 | { | |
150 | text: gettext('Upload Subscription Key'), | |
151 | handler: function() { | |
152 | let win = Ext.create('PMG.SubscriptionKeyEdit', { | |
153 | url: '/api2/extjs/' + baseurl, | |
154 | autoShow: true, | |
155 | }); | |
156 | win.on('destroy', reload); | |
157 | }, | |
158 | }, | |
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 | }, | |
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 | }, | |
179 | callback: reload, | |
180 | }); | |
181 | }, | |
182 | }, | |
183 | '-', | |
184 | { | |
185 | text: gettext('System Report'), | |
186 | handler: function() { | |
187 | Proxmox.Utils.checked_command(function() { me.showReport(); }); | |
188 | }, | |
189 | }, | |
190 | ], | |
191 | rows: rows, | |
192 | }); | |
193 | ||
194 | me.callParent(); | |
195 | ||
196 | reload(); | |
197 | }, | |
198 | }); |