]>
Commit | Line | Data |
---|---|---|
b0ee976f DM |
1 | Ext.define('PBS.SubscriptionKeyEdit', { |
2 | extend: 'Proxmox.window.Edit', | |
2e75b6d8 | 3 | |
b0ee976f | 4 | title: gettext('Upload Subscription Key'), |
c3a1b34e | 5 | width: 320, |
b0ee976f DM |
6 | autoLoad: true, |
7 | ||
bb26843c | 8 | onlineHelp: 'get_help', |
b0ee976f DM |
9 | |
10 | items: { | |
11 | xtype: 'textfield', | |
c3a1b34e | 12 | labelWidth: 120, |
b0ee976f DM |
13 | name: 'key', |
14 | value: '', | |
6ab77df3 TL |
15 | fieldLabel: gettext('Subscription Key'), |
16 | }, | |
b0ee976f DM |
17 | }); |
18 | ||
19 | Ext.define('PBS.Subscription', { | |
20 | extend: 'Proxmox.grid.ObjectGrid', | |
21 | xtype: 'pbsSubscription', | |
22 | ||
23 | title: gettext('Subscription'), | |
63bd6a9f | 24 | border: true, |
b0ee976f | 25 | |
bb26843c | 26 | onlineHelp: 'get_help', |
f4f9a503 | 27 | tools: [PBS.Utils.get_help_tool("get_help")], |
b0ee976f DM |
28 | |
29 | viewConfig: { | |
6ab77df3 | 30 | enableTextSelection: true, |
b0ee976f DM |
31 | }, |
32 | ||
46dce62b HL |
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'); | |
38 | return `${me.nodename}-pbs-report-${now}.txt`; | |
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', | |
48 | padding: '5px', | |
49 | }, | |
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: [ | |
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(); | |
65 | ||
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); | |
78 | } | |
79 | }, | |
80 | }, | |
81 | ], | |
82 | items: view, | |
83 | }); | |
84 | ||
85 | Proxmox.Utils.API2Request({ | |
86 | url: '/api2/extjs/nodes/' + me.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); | |
96 | }, | |
97 | }); | |
98 | }, | |
99 | ||
6ab77df3 | 100 | initComponent: function() { |
d28e6886 | 101 | let me = this; |
b0ee976f | 102 | |
d28e6886 TL |
103 | let reload = () => me.rstore.load(); |
104 | let baseurl = '/nodes/localhost/subscription'; | |
b0ee976f | 105 | |
d28e6886 | 106 | let rows = { |
b0ee976f | 107 | productname: { |
6ab77df3 | 108 | header: gettext('Type'), |
b0ee976f DM |
109 | }, |
110 | key: { | |
6ab77df3 | 111 | header: gettext('Subscription Key'), |
b0ee976f DM |
112 | }, |
113 | status: { | |
114 | header: gettext('Status'), | |
d28e6886 TL |
115 | renderer: (value) => { |
116 | value = Ext.String.capitalize(value); | |
117 | let message = me.getObjectValue('message'); | |
118 | if (message) { | |
119 | return value + ": " + message; | |
120 | } | |
121 | return value; | |
122 | }, | |
b0ee976f DM |
123 | }, |
124 | message: { | |
6ab77df3 | 125 | visible: false, |
b0ee976f DM |
126 | }, |
127 | serverid: { | |
6ab77df3 | 128 | header: gettext('Server ID'), |
b0ee976f | 129 | }, |
b0ee976f DM |
130 | checktime: { |
131 | header: gettext('Last checked'), | |
6ab77df3 | 132 | renderer: Proxmox.Utils.render_timestamp, |
b0ee976f DM |
133 | }, |
134 | nextduedate: { | |
6ab77df3 TL |
135 | header: gettext('Next due date'), |
136 | }, | |
b0ee976f DM |
137 | }; |
138 | ||
139 | Ext.apply(me, { | |
d28e6886 | 140 | url: `/api2/json${baseurl}`, |
b0ee976f | 141 | cwidth1: 170, |
2e75b6d8 | 142 | tbar: [ |
b0ee976f DM |
143 | { |
144 | text: gettext('Upload Subscription Key'), | |
c3a1b34e | 145 | iconCls: 'fa fa-ticket', |
b0ee976f | 146 | handler: function() { |
d28e6886 | 147 | let win = Ext.create('PBS.SubscriptionKeyEdit', { |
6ab77df3 | 148 | url: '/api2/extjs/' + baseurl, |
c3a1b34e | 149 | autoShow: true, |
b0ee976f | 150 | }); |
b0ee976f | 151 | win.on('destroy', reload); |
6ab77df3 | 152 | }, |
b0ee976f DM |
153 | }, |
154 | { | |
155 | text: gettext('Check'), | |
c3a1b34e | 156 | iconCls: 'fa fa-check-square-o', |
b0ee976f DM |
157 | handler: function() { |
158 | Proxmox.Utils.API2Request({ | |
159 | params: { force: 1 }, | |
160 | url: baseurl, | |
161 | method: 'POST', | |
162 | waitMsgTarget: me, | |
163 | failure: function(response, opts) { | |
164 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
165 | }, | |
6ab77df3 | 166 | callback: reload, |
b0ee976f | 167 | }); |
6ab77df3 TL |
168 | }, |
169 | }, | |
d3444c08 TL |
170 | { |
171 | text: gettext('Remove Subscription'), | |
172 | xtype: 'proxmoxStdRemoveButton', | |
173 | confirmMsg: gettext('Are you sure you want to remove the subscription key?'), | |
174 | baseurl: baseurl, | |
175 | dangerous: true, | |
176 | selModel: false, | |
177 | callback: reload, | |
c3a1b34e | 178 | iconCls: 'fa fa-trash-o', |
d3444c08 | 179 | }, |
46dce62b HL |
180 | '-', |
181 | { | |
182 | text: gettext('System Report'), | |
c3a1b34e | 183 | iconCls: 'fa fa-stethoscope', |
46dce62b HL |
184 | handler: function() { |
185 | Proxmox.Utils.checked_command(function() { me.showReport(); }); | |
186 | }, | |
187 | }, | |
b0ee976f | 188 | ], |
6ab77df3 | 189 | rows: rows, |
b0ee976f DM |
190 | }); |
191 | ||
192 | me.callParent(); | |
193 | ||
194 | reload(); | |
6ab77df3 | 195 | }, |
b0ee976f | 196 | }); |