]> git.proxmox.com Git - proxmox-backup.git/blob - www/tape/DriveConfig.js
ui: use butten for 'Label Media' (instead of action icon)
[proxmox-backup.git] / www / tape / DriveConfig.js
1 Ext.define('pbs-model-drives', {
2 extend: 'Ext.data.Model',
3 fields: ['path', 'model', 'name', 'serial', 'vendor', 'changer', 'changer-slot'],
4 idProperty: 'name',
5 });
6
7 Ext.define('PBS.TapeManagement.DrivePanel', {
8 extend: 'Ext.grid.Panel',
9 alias: 'widget.pbsTapeDrivePanel',
10
11 controller: {
12 xclass: 'Ext.app.ViewController',
13
14 onAdd: function() {
15 let me = this;
16 Ext.create('PBS.TapeManagement.DriveEditWindow', {
17 listeners: {
18 destroy: function() {
19 me.reload();
20 },
21 },
22 }).show();
23 },
24
25 onEdit: function() {
26 let me = this;
27 let view = me.getView();
28 let selection = view.getSelection();
29 if (!selection || selection.length < 1) {
30 return;
31 }
32 Ext.create('PBS.TapeManagement.DriveEditWindow', {
33 driveid: selection[0].data.name,
34 autoLoad: true,
35 listeners: {
36 destroy: () => me.reload(),
37 },
38 }).show();
39 },
40
41 status: function(view, rI, cI, button, el, record) {
42 let me = this;
43 let drive = record.data.name;
44 me.driveCommand(drive, 'status', function(response) {
45 let lines = [];
46 for (const [key, val] of Object.entries(response.result.data)) {
47 lines.push(`${key}: ${val}`);
48 }
49
50 let txt = lines.join('<br>');
51
52 Ext.Msg.show({
53 title: gettext('Label Information'),
54 message: txt,
55 icon: undefined,
56 });
57 });
58 },
59
60 catalog: function(view, rI, cI, button, el, record) {
61 let me = this;
62 let drive = record.data.name;
63 me.driveCommand(drive, 'catalog', function(response) {
64 Ext.create('Proxmox.window.TaskViewer', {
65 upid: response.result.data,
66 }).show();
67 }, {}, 'POST');
68 },
69
70 readLabel: function(view, rI, cI, button, el, record) {
71 let me = this;
72 let drive = record.data.name;
73 me.driveCommand(drive, 'read-label', function(response) {
74 let lines = [];
75 for (const [key, val] of Object.entries(response.result.data)) {
76 lines.push(`${key}: ${val}`);
77 }
78
79 let txt = lines.join('<br>');
80
81 Ext.Msg.show({
82 title: gettext('Label Information'),
83 message: txt,
84 icon: undefined,
85 });
86 });
87 },
88
89 volumeStatistics: function(view, rI, cI, button, el, record) {
90 let me = this;
91 let drive = record.data.name;
92 me.driveCommand(drive, 'volume-statistics', function(response) {
93 Ext.create('Ext.window.Window', {
94 title: gettext('Volume Statistics'),
95 modal: true,
96 width: 600,
97 height: 450,
98 layout: 'fit',
99 scrollable: true,
100 items: [
101 {
102 xtype: 'grid',
103 store: {
104 data: response.result.data,
105 },
106 columns: [
107 {
108 text: gettext('ID'),
109 dataIndex: 'id',
110 width: 60,
111 },
112 {
113 text: gettext('Name'),
114 dataIndex: 'name',
115 flex: 2,
116 },
117 {
118 text: gettext('Value'),
119 dataIndex: 'value',
120 flex: 1,
121 },
122 ],
123 },
124 ],
125 }).show();
126 });
127 },
128
129 cartridgeMemory: function(view, rI, cI, button, el, record) {
130 let me = this;
131 let drive = record.data.name;
132 me.driveCommand(drive, 'cartridge-memory', function(response) {
133 Ext.create('Ext.window.Window', {
134 title: gettext('Cartridge Memory'),
135 modal: true,
136 width: 600,
137 height: 450,
138 layout: 'fit',
139 scrollable: true,
140 items: [
141 {
142 xtype: 'grid',
143 store: {
144 data: response.result.data,
145 },
146 columns: [
147 {
148 text: gettext('ID'),
149 dataIndex: 'id',
150 width: 60,
151 },
152 {
153 text: gettext('Name'),
154 dataIndex: 'name',
155 flex: 2,
156 },
157 {
158 text: gettext('Value'),
159 dataIndex: 'value',
160 flex: 1,
161 },
162 ],
163 },
164 ],
165 }).show();
166 });
167 },
168
169 driveCommand: function(driveid, command, callback, params, method) {
170 let me = this;
171 let view = me.getView();
172 params = params || {};
173 method = method || 'GET';
174 Proxmox.Utils.API2Request({
175 url: `/api2/extjs/tape/drive/${driveid}/${command}`,
176 method,
177 waitMsgTarget: view,
178 params,
179 success: function(response) {
180 callback(response);
181 },
182 failure: function(response) {
183 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
184 },
185 });
186 },
187
188 labelMedia: function(button, event, record) {
189 let me = this;
190 let driveid = record.data.name;
191
192 Ext.create('PBS.TapeManagement.LabelMediaWindow', {
193 driveid,
194 }).show();
195 },
196
197 reload: function() {
198 this.getView().getStore().rstore.load();
199 },
200
201 stopStore: function() {
202 this.getView().getStore().rstore.stopUpdate();
203 },
204
205 startStore: function() {
206 this.getView().getStore().rstore.startUpdate();
207 },
208 },
209
210 listeners: {
211 beforedestroy: 'stopStore',
212 deactivate: 'stopStore',
213 activate: 'startStore',
214 itemdblclick: 'onEdit',
215 },
216
217 store: {
218 type: 'diff',
219 rstore: {
220 type: 'update',
221 storeid: 'proxmox-tape-drives',
222 model: 'pbs-model-drives',
223 proxy: {
224 type: 'proxmox',
225 url: "/api2/json/tape/drive",
226 },
227 },
228 sorters: 'name',
229 },
230
231 tbar: [
232 {
233 text: gettext('Add'),
234 xtype: 'proxmoxButton',
235 handler: 'onAdd',
236 selModel: false,
237 },
238 '-',
239 {
240 text: gettext('Edit'),
241 xtype: 'proxmoxButton',
242 handler: 'onEdit',
243 disabled: true,
244 },
245 {
246 xtype: 'proxmoxStdRemoveButton',
247 baseurl: '/api2/extjs/config/drive',
248 callback: 'reload',
249 },
250 '-',
251 {
252 text: gettext('Label Media'),
253 xtype: 'proxmoxButton',
254 handler: 'labelMedia',
255 iconCls: 'fa fa-barcode',
256 disabled: true,
257 },
258 ],
259 columns: [
260 {
261 text: gettext('Name'),
262 dataIndex: 'name',
263 flex: 1,
264 },
265 {
266 text: gettext('Path'),
267 dataIndex: 'path',
268 flex: 2,
269 },
270 {
271 text: gettext('Vendor'),
272 dataIndex: 'vendor',
273 flex: 1,
274 },
275 {
276 text: gettext('Model'),
277 dataIndex: 'model',
278 flex: 1,
279 },
280 {
281 text: gettext('Serial'),
282 dataIndex: 'serial',
283 flex: 1,
284 },
285 {
286 text: gettext('Changer'),
287 flex: 1,
288 dataIndex: 'changer',
289 renderer: function(value, mD, record) {
290 if (!value) {
291 return "";
292 }
293 let drive_num = record.data['changer-drivenum'] || 0;
294 let drive_text = gettext("Drive {0}");
295 return `${value} (${Ext.String.format(drive_text, drive_num)})`;
296 },
297 sorter: function(a, b) {
298 let ch_a = a.data.changer || "";
299 let ch_b = b.data.changer || "";
300 let num_a = a.data['changer-drivenum'] || 0;
301 let num_b = b.data['changer-drivenum'] || 0;
302 return ch_a > ch_b ? -1 : ch_a < ch_b ? 1 : num_b - num_a;
303 },
304 },
305 {
306 text: gettext('Actions'),
307 width: 140,
308 xtype: 'actioncolumn',
309 items: [
310 {
311 iconCls: 'fa fa-hdd-o',
312 handler: 'cartridgeMemory',
313 tooltip: gettext('Cartridge Memory'),
314 },
315 {
316 iconCls: 'fa fa-line-chart',
317 handler: 'volumeStatistics',
318 tooltip: gettext('Volume Statistics'),
319 },
320 {
321 iconCls: 'fa fa-tag',
322 handler: 'readLabel',
323 tooltip: gettext('Read Label'),
324 },
325 {
326 iconCls: 'fa fa-book',
327 handler: 'catalog',
328 tooltip: gettext('Catalog'),
329 },
330 {
331 iconCls: 'fa fa-info-circle',
332 handler: 'status',
333 tooltip: gettext('Status'),
334 },
335 ],
336 },
337 ],
338 });
339