]> git.proxmox.com Git - proxmox-backup.git/blob - www/tape/TapeInventory.js
25dea1ba030168af7a96f4a11f9d1e6b6e8a3cc3
[proxmox-backup.git] / www / tape / TapeInventory.js
1 Ext.define('pbs-model-tapes', {
2 extend: 'Ext.data.Model',
3 fields: [
4 'catalog',
5 'ctime',
6 'expired',
7 'label-text',
8 'location',
9 'media-set-ctime',
10 'media-set-name',
11 'media-set-uuid',
12 'pool',
13 'seq-nr',
14 'status',
15 'uuid',
16 ],
17 idProperty: 'label-text',
18 proxy: {
19 type: 'proxmox',
20 url: '/api2/json/tape/media/list',
21 timeout: 5*60*1000,
22 },
23 });
24
25 Ext.define('PBS.TapeManagement.TapeInventory', {
26 extend: 'Ext.grid.Panel',
27 alias: 'widget.pbsTapeInventory',
28
29 controller: {
30 xclass: 'Ext.app.ViewController',
31
32 addTape: function() {
33 Ext.create('PBS.TapeManagement.LabelMediaWindow').show();
34 },
35
36 moveToVault: function() {
37 let me = this;
38 let view = me.getView();
39 let selection = view.getSelection();
40 if (!selection || selection.length < 1) {
41 return;
42 }
43 let label = selection[0].data['label-text'];
44 let inVault = selection[0].data.location.startsWith('vault-');
45 let vault = "";
46 if (inVault) {
47 vault = selection[0].data.location.slice("vault-".length);
48 }
49 Ext.create('Proxmox.window.Edit', {
50 title: gettext('Set Tape Location'),
51 url: `/api2/extjs/tape/media/move`,
52 method: 'POST',
53 items: [
54 {
55 xtype: 'displayfield',
56 name: 'label-text',
57 value: label,
58 submitValue: true,
59 fieldLabel: gettext('Media'),
60 },
61 {
62 xtype: 'proxmoxtextfield',
63 fieldLabel: gettext('Vault'),
64 name: 'vault-name',
65 value: vault,
66 emptyText: gettext('On-site'),
67 skipEmpty: true,
68 },
69 ],
70 listeners: {
71 destroy: function() {
72 me.reload();
73 },
74 },
75 }).show();
76 },
77
78 reload: function() {
79 this.getView().getStore().load();
80 },
81 },
82
83 listeners: {
84 activate: 'reload',
85 },
86
87 store: {
88 storeid: 'proxmox-tape-tapes',
89 model: 'pbs-model-tapes',
90 sorters: 'label-text',
91 },
92
93 tbar: [
94 {
95 text: gettext('Reload'),
96 handler: 'reload',
97 },
98 '-',
99 {
100 text: gettext('Add Tape'),
101 handler: 'addTape',
102 },
103 {
104 xtype: 'proxmoxButton',
105 text: gettext('Set Tape Location'),
106 disabled: true,
107 handler: 'moveToVault',
108 enableFn: (rec) => !rec.data.location.startsWith('online-'),
109 },
110 ],
111
112 columns: [
113 {
114 text: gettext('Label'),
115 dataIndex: 'label-text',
116 flex: 1,
117 },
118 {
119 text: gettext('Pool'),
120 dataIndex: 'pool',
121 sorter: (a, b) => (a.data.pool || "").localeCompare(b.data.pool || ""),
122 flex: 1,
123 },
124 {
125 text: gettext('Media Set'),
126 dataIndex: 'media-set-name',
127 flex: 2,
128 sorter: function(a, b) {
129 return (a.data['media-set-ctime'] || 0) - (b.data['media-set-ctime'] || 0);
130 },
131 },
132 {
133 text: gettext('Location'),
134 dataIndex: 'location',
135 flex: 1,
136 renderer: function(value) {
137 if (value === 'offline') {
138 return `<i class="fa fa-circle-o"></i> ${gettext("Offline")} (${gettext('On-site')})`;
139 } else if (value.startsWith('online-')) {
140 let location = value.substring(value.indexOf('-') + 1);
141 return `<i class="fa fa-dot-circle-o"></i> ${gettext("Online")} - ${location}`;
142 } else if (value.startsWith('vault-')) {
143 let location = value.substring(value.indexOf('-') + 1);
144 return `<i class="fa fa-archive"></i> ${gettext("Vault")} - ${location}`;
145 } else {
146 return value;
147 }
148 },
149 },
150 {
151 text: gettext('Status'),
152 dataIndex: 'status',
153 renderer: function(value, mD, record) {
154 return record.data.expired ? 'expired' : value;
155 },
156 flex: 1,
157 },
158 ],
159 });