BackupView.js 4.35 KB
Newer Older
1
Ext.define('PVE.grid.BackupView', {
2 3
    extend: 'Ext.grid.GridPanel',

4
    alias: ['widget.pveBackupView'],
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19


    initComponent : function() {
	var me = this;

	var nodename = me.pveSelNode.data.node;
	if (!nodename) {
	    throw "no node name specified";
	}

	var vmid = me.pveSelNode.data.vmid;
	if (!vmid) {
	    throw "no VM ID specified";
	}

20 21 22 23 24
	var vmtype = me.pveSelNode.data.type;
	if (!vmtype) {
	    throw "no VM type specified";
	}

25 26 27 28 29 30 31 32 33 34 35 36 37
	var filterFn;
	if (vmtype === 'openvz') {
	    filterFn = function(item) {
		return item.data.volid.match(':backup/vzdump-openvz-');
	    };
	} else if (vmtype === 'qemu') {
	    filterFn = function(item) {
		return item.data.volid.match(':backup/vzdump-qemu-');
	    };
	} else {
	    throw "unsupported VM type '" + vmtype + "'";
	}

38 39 40 41 42
	me.store = Ext.create('Ext.data.Store', {
	    model: 'pve-storage-content',
	    sorters: { 
		property: 'volid', 
		order: 'DESC' 
43 44
	    },
	    filters: { filterFn: filterFn }
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
	});

	var reload = Ext.Function.createBuffered(function() {
	    if (me.store.proxy.url) {
		me.store.load();
	    }
	}, 100);

	var setStorage = function(storage) {
	    var url = '/api2/json/nodes/' + nodename + '/storage/' + storage + '/content';
	    url += '?content=backup';

	    me.store.setProxy({
		type: 'pve',
		url: url
	    });

	    reload();
	};

	var storagesel = Ext.create('PVE.form.StorageSelector', {
	    nodename: nodename,
67
	    fieldLabel: gettext('Storage'),
68 69 70 71 72 73 74 75 76 77
	    labelAlign: 'right',
	    storageContent: 'backup',
	    allowBlank: false,
	    listeners: {
		change: function(f, value) {
		    setStorage(value);
		}
	    }
	});

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
	var storagefilter = Ext.create('Ext.form.field.Text', {
	    fieldLabel: gettext('Search'),
	    labelWidth: 50,
	    labelAlign: 'right',
	    enableKeyEvents: true,
	    listeners: {
		buffer: 500,
		keyup: function(field) {
		    me.store.clearFilter(true);
		    me.store.filter([
			{
			    property: 'volid',
			    value: field.getValue(),
			    anyMatch: true,
			    caseSensitive: false
			}
		    ]);
		}
	    }
	});

Dietmar Maurer's avatar
Dietmar Maurer committed
99 100 101
	var sm = Ext.create('Ext.selection.RowModel', {});

	var backup_btn = Ext.create('Ext.button.Button', {
102
	    text: gettext('Backup now'),
103
	    handler: function() {
104
		var win = Ext.create('PVE.window.Backup', { 
105 106
		    nodename: nodename,
		    vmid: vmid,
107
		    vmtype: vmtype,
108
		    storage: storagesel.getValue()
109
		});
110
		win.show();
111 112 113
	    }
	});

Dietmar Maurer's avatar
Dietmar Maurer committed
114
	var restore_btn = Ext.create('PVE.button.Button', {
115
	    text: gettext('Restore'),
116
	    disabled: true,
Dietmar Maurer's avatar
Dietmar Maurer committed
117 118 119 120 121 122
	    selModel: sm,
	    enableFn: function(rec) {
		return !!rec;
	    },
	    handler: function(b, e, rec) {
		var volid = rec.data.volid;
123

124 125 126 127 128 129 130 131 132
		var win = Ext.create('PVE.window.Restore', {
		    nodename: nodename,
		    vmid: vmid,
		    volid: rec.data.volid,
		    volidText: PVE.Utils.render_storage_content(rec.data.volid, {}, rec),
		    vmtype: vmtype
		});
		win.show();
		win.on('destroy', reload);
133 134 135
	    }
	});

Dietmar Maurer's avatar
Dietmar Maurer committed
136
	var delete_btn = Ext.create('PVE.button.Button', {
137
	    text: gettext('Remove'),
138
	    disabled: true,
Dietmar Maurer's avatar
Dietmar Maurer committed
139
	    selModel: sm,
140
	    dangerous: true,	    
Dietmar Maurer's avatar
Dietmar Maurer committed
141
	    confirmMsg: function(rec) {
142 143 144 145 146
		var msg = Ext.String.format(gettext('Are you sure you want to remove entry {0}'),
					    "'" + rec.data.volid + "'");
		msg += " " + gettext('This will permanently erase all image data.');

		return msg;
Dietmar Maurer's avatar
Dietmar Maurer committed
147 148 149 150 151
	    },
	    enableFn: function(rec) {
		return !!rec;
	    },
	    handler: function(b, e, rec){
152 153 154 155 156 157
		var storage = storagesel.getValue();
		if (!storage) {
		    return;
		}

		var volid = rec.data.volid;
Dietmar Maurer's avatar
Dietmar Maurer committed
158 159 160 161 162 163 164 165 166
		PVE.Utils.API2Request({
		    url: "/nodes/" + nodename + "/storage/" + storage + "/content/" + volid,
		    method: 'DELETE',
		    waitMsgTarget: me,
		    failure: function(response, opts) {
			Ext.Msg.alert('Error', response.htmlStatus);
		    },
		    success: function(response, options) {
			reload();
167 168 169 170 171
		    }
		});
	    }
	});

172 173
	Ext.apply(me, {
	    stateful: false,
Dietmar Maurer's avatar
Dietmar Maurer committed
174
	    selModel: sm,
175
	    tbar: [ backup_btn, restore_btn, delete_btn, '->', storagesel, storagefilter ],
176 177
	    columns: [
		{
178
		    header: gettext('Name'),
179 180 181 182 183 184
		    flex: 1,
		    sortable: true,
		    renderer: PVE.Utils.render_storage_content,
		    dataIndex: 'volid'
		},
		{
185
		    header: gettext('Format'),
186 187 188 189
		    width: 100,
		    dataIndex: 'format'
		},
		{
190
		    header: gettext('Size'),
191 192 193 194 195 196
		    width: 100,
		    renderer: PVE.Utils.format_size,
		    dataIndex: 'size'
		}
	    ],
	    listeners: {
Dietmar Maurer's avatar
Dietmar Maurer committed
197
		show: reload
198 199 200 201 202 203
	    }
	});

	me.callParent();
    }
});