]>
Commit | Line | Data |
---|---|---|
7f261b55 DM |
1 | Ext.define('pmg-backup-list', { |
2 | extend: 'Ext.data.Model', | |
3 | fields: [ | |
4 | 'filename', | |
0b33a628 | 5 | { type: 'integer', name: 'size' }, |
c87d46fb | 6 | { type: 'date', dateFormat: 'timestamp', name: 'timestamp' }, |
0b33a628 | 7 | |
7f261b55 DM |
8 | ], |
9 | proxy: { | |
10 | type: 'proxmox', | |
c87d46fb | 11 | url: "/api2/json/nodes/" + Proxmox.NodeName + "/backup", |
7f261b55 | 12 | }, |
c87d46fb | 13 | idProperty: 'filename', |
7f261b55 DM |
14 | }); |
15 | ||
db13d7e3 DC |
16 | Ext.define('PMG.RestoreWindow', { |
17 | extend: 'Proxmox.window.Edit', | |
18 | xtype: 'pmgRestoreWindow', | |
573a6e8b | 19 | onlineHelp: 'chapter_pmgbackup', |
db13d7e3 DC |
20 | |
21 | showProgress: true, | |
22 | title: gettext('Restore'), | |
23 | isCreate: true, | |
24 | method: 'POST', | |
25 | submitText: gettext('Restore'), | |
26 | fieldDefaults: { | |
c87d46fb | 27 | labelWidth: 150, |
db13d7e3 | 28 | }, |
db13d7e3 DC |
29 | |
30 | initComponent: function() { | |
28eb60c0 | 31 | let me = this; |
db13d7e3 | 32 | |
7bcc34db SI |
33 | me.items = [ |
34 | { | |
35 | xtype: 'proxmoxcheckbox', | |
36 | name: 'config', | |
37 | fieldLabel: gettext('System Configuration'), | |
38 | }, | |
39 | { | |
40 | xtype: 'proxmoxcheckbox', | |
41 | name: 'database', | |
42 | value: 1, | |
43 | uncheckedValue: 0, | |
44 | fieldLabel: gettext('Rule Database'), | |
45 | listeners: { | |
46 | change: function(field, value) { | |
47 | field.nextSibling('field[name=statistic]').setDisabled(!value); | |
48 | }, | |
49 | }, | |
50 | }, | |
51 | { | |
52 | xtype: 'proxmoxcheckbox', | |
53 | name: 'statistic', | |
54 | fieldLabel: gettext('Statistic'), | |
55 | }, | |
56 | ]; | |
db13d7e3 | 57 | |
ad925481 | 58 | let restorePath; |
7bcc34db | 59 | if (me.filename) { |
ad925481 | 60 | restorePath = `backup/${encodeURIComponent(me.filename)}`; |
d944805a | 61 | } else if (me.backup_time) { |
ad925481 | 62 | restorePath = `pbs/${me.remote}/snapshot/${me.backup_id}/${me.backup_time}`; |
7bcc34db SI |
63 | } else { |
64 | throw "neither filename nor snapshot given"; | |
65 | } | |
ad925481 | 66 | me.url = `/nodes/${Proxmox.NodeName}/${restorePath}`; |
db13d7e3 DC |
67 | |
68 | me.callParent(); | |
c87d46fb | 69 | }, |
db13d7e3 DC |
70 | }); |
71 | ||
7f261b55 DM |
72 | Ext.define('PMG.BackupRestore', { |
73 | extend: 'Ext.grid.GridPanel', | |
74 | xtype: 'pmgBackupRestore', | |
75 | ||
76 | title: gettext('Backup') + '/' + gettext('Restore'), | |
77 | ||
78 | controller: { | |
79 | xclass: 'Ext.app.ViewController', | |
80 | ||
81 | createBackup: function() { | |
28eb60c0 | 82 | let view = this.getView(); |
7f261b55 DM |
83 | Proxmox.Utils.API2Request({ |
84 | url: "/nodes/" + Proxmox.NodeName + "/backup", | |
85 | method: 'POST', | |
28eb60c0 | 86 | waitMsgTarget: view, |
c87d46fb | 87 | failure: function(response, opts) { |
7f261b55 DM |
88 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); |
89 | }, | |
90 | success: function(response, opts) { | |
28eb60c0 | 91 | let upid = response.result.data; |
7f261b55 | 92 | |
28eb60c0 | 93 | let win = Ext.create('Proxmox.window.TaskViewer', { |
c87d46fb | 94 | upid: upid, |
28eb60c0 | 95 | autoShow: true, |
7f261b55 | 96 | }); |
28eb60c0 | 97 | view.mon(win, 'close', () => view.store.load()); |
c87d46fb | 98 | }, |
7f261b55 DM |
99 | }); |
100 | }, | |
101 | ||
7cd5155c | 102 | onRestore: function() { |
28eb60c0 TL |
103 | let view = this.getView(); |
104 | let rec = view.getSelection()[0]; | |
7cd5155c | 105 | |
467b217d DC |
106 | if (!(rec && rec.data && rec.data.filename)) { |
107 | return; | |
108 | } | |
7cd5155c | 109 | |
db13d7e3 | 110 | Ext.create('PMG.RestoreWindow', { |
c87d46fb | 111 | filename: rec.data.filename, |
db13d7e3 | 112 | }).show(); |
7cd5155c DM |
113 | }, |
114 | ||
7f261b55 | 115 | onAfterRemove: function(btn, res) { |
28eb60c0 TL |
116 | let view = this.getView(); |
117 | view.store.load(); | |
c87d46fb | 118 | }, |
7f261b55 DM |
119 | }, |
120 | ||
121 | tbar: [ | |
122 | { | |
22988ae4 | 123 | text: gettext('Backup Now'), |
c87d46fb | 124 | handler: 'createBackup', |
7f261b55 | 125 | }, |
dd79f43a | 126 | '-', |
7cd5155c DM |
127 | { |
128 | xtype: 'proxmoxButton', | |
129 | text: gettext('Restore'), | |
130 | handler: 'onRestore', | |
c87d46fb | 131 | disabled: true, |
7cd5155c | 132 | }, |
7f261b55 DM |
133 | { |
134 | xtype: 'proxmoxStdRemoveButton', | |
135 | baseurl: '/nodes/' + Proxmox.NodeName + '/backup', | |
136 | reference: 'removeBtn', | |
137 | callback: 'onAfterRemove', | |
c87d46fb TL |
138 | waitMsgTarget: true, |
139 | }, | |
7f261b55 DM |
140 | ], |
141 | ||
142 | store: { | |
143 | autoLoad: true, | |
0b33a628 DM |
144 | model: 'pmg-backup-list', |
145 | sorters: [ | |
146 | { | |
147 | property: 'timestamp', | |
c87d46fb TL |
148 | direction: 'DESC', |
149 | }, | |
150 | ], | |
7f261b55 DM |
151 | }, |
152 | ||
153 | columns: [ | |
154 | { | |
155 | header: gettext('Filename'), | |
156 | width: 300, | |
157 | sortable: true, | |
bedf67ee | 158 | renderer: Ext.htmlEncode, |
c87d46fb | 159 | dataIndex: 'filename', |
7f261b55 | 160 | }, |
0b33a628 DM |
161 | { |
162 | xtype: 'datecolumn', | |
163 | header: gettext('Time'), | |
164 | width: 150, | |
165 | format: 'Y-m-d H:i', | |
166 | sortable: true, | |
c87d46fb | 167 | dataIndex: 'timestamp', |
0b33a628 | 168 | }, |
7f261b55 DM |
169 | { |
170 | header: gettext('Size'), | |
171 | width: 100, | |
172 | sortable: true, | |
75a55308 | 173 | renderer: Proxmox.Utils.format_size, |
c87d46fb | 174 | dataIndex: 'size', |
bedf67ee DC |
175 | }, |
176 | { | |
177 | header: gettext('Download'), | |
178 | renderer: function(filename) { | |
179 | return "<a class='download' href='" + | |
180 | "/api2/json/nodes/" + Proxmox.NodeName + "/backup/" + encodeURIComponent(filename) + | |
181 | "'><i class='fa fa-fw fa-download'</i></a>"; | |
182 | }, | |
c87d46fb TL |
183 | dataIndex: 'filename', |
184 | }, | |
185 | ], | |
7f261b55 | 186 | }); |