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