HDMove.js 3.57 KB
Newer Older
Alexandre Derumier's avatar
Alexandre Derumier committed
1 2 3 4 5 6
Ext.define('PVE.window.HDMove', {
    extend: 'Ext.window.Window',

    resizable: false,


7
    move_disk: function(disk, storage, format, delete_disk) {
Alexandre Derumier's avatar
Alexandre Derumier committed
8 9
	var me = this;

Dietmar Maurer's avatar
Dietmar Maurer committed
10
        var params =  { disk: disk, storage: storage };
Alexandre Derumier's avatar
Alexandre Derumier committed
11 12 13 14

        if (format) {
            params.format = format;
        }
15 16 17
	
	if (delete_disk) {
	    params['delete'] = 1;
Dietmar Maurer's avatar
Dietmar Maurer committed
18
	}
Alexandre Derumier's avatar
Alexandre Derumier committed
19 20 21

	PVE.Utils.API2Request({
	    params: params,
22
	    url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/move_disk',
Alexandre Derumier's avatar
Alexandre Derumier committed
23
	    waitMsgTarget: me,
24
	    method: 'POST',
Alexandre Derumier's avatar
Alexandre Derumier committed
25 26 27 28
	    failure: function(response, opts) {
		Ext.Msg.alert('Error', response.htmlStatus);
	    },
	    success: function(response, options) {
29 30 31
		var upid = response.result.data;
		var win = Ext.create('PVE.window.TaskViewer', { upid: upid });
		win.show();
Alexandre Derumier's avatar
Alexandre Derumier committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
		me.close();
	    }
	});

    },

    initComponent : function() {
	var me = this;

	var diskarray = [];

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

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

        var items = [
            {
                xtype: 'displayfield',
                name: 'disk',
                value: me.disk,
                fieldLabel: 'Disk',
                vtype: 'StorageId',
                allowBlank: false
Dietmar Maurer's avatar
Dietmar Maurer committed
59
            }
Alexandre Derumier's avatar
Alexandre Derumier committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
        ];

        me.hdstoragesel = Ext.create('PVE.form.StorageSelector', {
                name: 'hdstorage',
                nodename: me.nodename,
                fieldLabel: 'Target Storage',
                storageContent: 'images',
                autoSelect: me.insideWizard,
                allowBlank: true,
                disabled: false,
                hidden: false,
                listeners: {
                    change: function(f, value) {
                        var rec = f.store.getById(value);
			if (rec.data.type === 'iscsi') {
                            me.formatsel.setValue('raw');
                            me.formatsel.setDisabled(true);
                        } else if (rec.data.type === 'lvm' ||
                                   rec.data.type === 'rbd' ||
                                   rec.data.type === 'sheepdog' ||
                                   rec.data.type === 'nexenta'
                        ) {
                            me.formatsel.setValue('raw');
                            me.formatsel.setDisabled(true);
                        } else {
                            me.formatsel.setDisabled(false);
                        }

                    }
                }

	});

	me.formatsel = Ext.create('PVE.form.DiskFormatSelector', {
		name: 'diskformat',
		fieldLabel: gettext('Format'),
		value: 'raw',
                disabled: true,
                hidden: false,
		allowBlank: false
	});


103
   
Alexandre Derumier's avatar
Alexandre Derumier committed
104 105 106
	items.push(me.hdstoragesel);
	items.push(me.formatsel);

107 108 109 110 111 112 113 114
	items.push({
	    xtype: 'pvecheckbox',
	    fieldLabel: gettext('Delete source'),
	    name: 'deleteDisk',
	    uncheckedValue: 0,
	    checked: false
	});

Alexandre Derumier's avatar
Alexandre Derumier committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128
	me.formPanel = Ext.create('Ext.form.Panel', {
	    bodyPadding: 10,
	    border: false,
	    fieldDefaults: {
		labelWidth: 100,
		anchor: '100%'
	    },
	    items: items
	});

	var form = me.formPanel.getForm();

	var submitBtn;

129
	me.title =  gettext("Move disk");
Alexandre Derumier's avatar
Alexandre Derumier committed
130
	submitBtn = Ext.create('Ext.Button', {
131
	    text: gettext('Move disk'),
Alexandre Derumier's avatar
Alexandre Derumier committed
132 133 134
	    handler: function() {
		if (form.isValid()) {
		    var values = form.getValues();
135 136
		    me.move_disk(me.disk, values.hdstorage, values.diskformat,
				 values.deleteDisk);
Alexandre Derumier's avatar
Alexandre Derumier committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
		}
	    }
	});

	Ext.apply(me, {
	    modal: true,
	    width: 350,
	    border: false,
	    layout: 'fit',
	    buttons: [ submitBtn ],
	    items: [ me.formPanel ]
	});


	me.callParent();


    }
});