]>
Commit | Line | Data |
---|---|---|
8b349e01 TL |
1 | Ext.define('PMG.PBSConfig', { |
2 | extend: 'Ext.panel.Panel', | |
3 | xtype: 'pmgPBSConfig', | |
4 | ||
5 | controller: { | |
6 | xclass: 'Ext.app.ViewController', | |
7 | ||
8 | callRestore: function(grid, record) { | |
9 | let remote = this.getViewModel().get('remote'); | |
10 | Ext.create('PMG.RestoreWindow', { | |
11 | remote: remote, | |
12 | backup_id: record.data['backup-id'], | |
13 | backup_time: record.data['backup-time'], | |
14 | }).show(); | |
15 | }, | |
16 | ||
17 | restoreSnapshot: function(button) { | |
18 | let me = this; | |
19 | let view = me.lookup('pbsremotegrid'); | |
20 | let record = view.getSelection()[0]; | |
21 | me.callRestore(view, record); | |
22 | }, | |
23 | ||
24 | runBackup: function(button) { | |
25 | let me = this; | |
26 | let view = me.lookup('pbsremotegrid'); | |
27 | let remote = me.getViewModel().get('remote'); | |
28 | Proxmox.Utils.API2Request({ | |
29 | url: `/nodes/${Proxmox.NodeName}/pbs/${remote}/snapshot`, | |
30 | method: 'POST', | |
31 | waitMsgTarget: view, | |
32 | failure: function(response, opts) { | |
33 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
34 | }, | |
35 | success: function(response, opts) { | |
36 | let upid = response.result.data; | |
37 | ||
38 | let win = Ext.create('Proxmox.window.TaskViewer', { | |
39 | upid: upid, | |
40 | }); | |
41 | win.show(); | |
42 | me.mon(win, 'close', function() { view.getStore().load(); }); | |
43 | }, | |
44 | }); | |
45 | }, | |
46 | ||
47 | reload: function(grid) { | |
48 | let me = this; | |
49 | let selection = grid.getSelection(); | |
50 | me.showInfo(grid, selection); | |
51 | }, | |
52 | ||
53 | showInfo: function(grid, selected) { | |
54 | let me = this; | |
55 | let viewModel = me.getViewModel(); | |
56 | if (selected[0]) { | |
57 | let remote = selected[0].data.remote; | |
58 | viewModel.set('selected', true); | |
59 | viewModel.set('remote', remote); | |
60 | ||
61 | // set grid stores and load them | |
62 | let remstore = me.lookup('pbsremotegrid').getStore(); | |
63 | remstore.getProxy().setUrl(`/api2/json/nodes/${Proxmox.NodeName}/pbs/${remote}/snapshot`); | |
64 | remstore.load(); | |
65 | } else { | |
66 | viewModel.set('selected', false); | |
67 | } | |
68 | }, | |
69 | reloadSnapshots: function() { | |
70 | let me = this; | |
71 | let grid = me.lookup('grid'); | |
72 | let selection = grid.getSelection(); | |
73 | me.showInfo(grid, selection); | |
74 | }, | |
75 | init: function(view) { | |
76 | let me = this; | |
77 | me.lookup('grid').relayEvents(view, ['activate']); | |
78 | let pbsremotegrid = me.lookup('pbsremotegrid'); | |
79 | ||
80 | Proxmox.Utils.monStoreErrors(pbsremotegrid, pbsremotegrid.getStore(), true); | |
81 | }, | |
82 | ||
83 | control: { | |
84 | 'grid[reference=grid]': { | |
85 | selectionchange: 'showInfo', | |
86 | load: 'reload', | |
87 | }, | |
88 | 'grid[reference=pbsremotegrid]': { | |
89 | itemdblclick: 'restoreSnapshot', | |
90 | }, | |
91 | }, | |
92 | }, | |
93 | ||
94 | viewModel: { | |
95 | data: { | |
96 | remote: '', | |
97 | selected: false, | |
98 | }, | |
99 | }, | |
100 | ||
101 | layout: 'border', | |
102 | ||
103 | items: [ | |
104 | { | |
105 | region: 'center', | |
106 | reference: 'grid', | |
107 | xtype: 'pmgPBSConfigGrid', | |
108 | border: false, | |
109 | }, | |
110 | { | |
111 | xtype: 'grid', | |
112 | region: 'south', | |
113 | reference: 'pbsremotegrid', | |
114 | hidden: true, | |
115 | height: '70%', | |
116 | border: false, | |
117 | split: true, | |
118 | emptyText: gettext('No backups on remote'), | |
119 | tbar: [ | |
120 | { | |
121 | xtype: 'proxmoxButton', | |
122 | text: gettext('Backup'), | |
123 | handler: 'runBackup', | |
124 | selModel: false, | |
125 | }, | |
126 | { | |
127 | xtype: 'proxmoxButton', | |
128 | text: gettext('Restore'), | |
129 | handler: 'restoreSnapshot', | |
130 | disabled: true, | |
131 | }, | |
132 | { | |
133 | xtype: 'proxmoxStdRemoveButton', | |
134 | text: gettext('Forget Snapshot'), | |
135 | disabled: true, | |
136 | getUrl: function(rec) { | |
137 | let me = this; | |
138 | let remote = me.lookupViewModel().get('remote'); | |
139 | let snapshot = `${rec.data['backup-id']}/${rec.data['backup-time']}`; | |
140 | return `/nodes/${Proxmox.NodeName}/pbs/${remote}/snapshot/${snapshot}`; | |
141 | }, | |
142 | confirmMsg: function(rec) { | |
143 | let me = this; | |
144 | let snapshot = `${rec.data['backup-id']}/${rec.data['backup-time']}`; | |
145 | return Ext.String.format( | |
146 | gettext('Are you sure you want to forget snapshot {0}'), | |
147 | `'${snapshot}'`, | |
148 | ); | |
149 | }, | |
150 | callback: 'reloadSnapshots', | |
151 | }, | |
152 | ], | |
153 | store: { | |
154 | fields: ['time', 'size', 'ctime', 'encrypted'], | |
155 | proxy: { type: 'proxmox' }, | |
156 | sorters: [ | |
157 | { | |
158 | property: 'time', | |
159 | direction: 'DESC', | |
160 | }, | |
161 | ], | |
162 | }, | |
163 | bind: { | |
164 | title: Ext.String.format(gettext("Backup snapshots on '{0}'"), '{remote}'), | |
165 | hidden: '{!selected}', | |
166 | }, | |
167 | columns: [ | |
168 | { | |
169 | text: 'Group ID', | |
170 | dataIndex: 'backup-id', | |
171 | flex: 1, | |
172 | }, | |
173 | { | |
174 | text: 'Time', | |
175 | dataIndex: 'backup-time', | |
176 | width: 180, | |
177 | }, | |
178 | { | |
179 | text: 'Size', | |
180 | dataIndex: 'size', | |
181 | renderer: Proxmox.Utils.format_size, | |
182 | flex: 1, | |
183 | }, | |
184 | { | |
185 | text: 'Encrypted', | |
186 | dataIndex: 'encrypted', | |
187 | hidden: true, // FIXME: actually return from API | |
188 | renderer: Proxmox.Utils.format_boolean, | |
189 | flex: 1, | |
190 | }, | |
191 | ], | |
192 | }, | |
193 | ], | |
194 | ||
195 | }); |