StorageView.js 5.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Ext.define('PVE.dc.StorageView', {
    extend: 'Ext.grid.GridPanel',

    alias: ['widget.pveStorageView'],

    initComponent : function() {
	var me = this;

	var store = new Ext.data.Store({
	    model: 'pve-storage',
	    proxy: {
                type: 'pve',
		url: "/api2/json/storage"
	    },
	    sorters: { 
		property: 'storage', 
		order: 'DESC' 
	    }
	});

	var reload = function() {
	    store.load();
	};

25 26
	var sm = Ext.create('Ext.selection.RowModel', {});

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
	var run_editor = function() {
	    var rec = sm.getSelection()[0];
	    if (!rec) {
		return;
	    }
	    var type = rec.data.type;
	    
	    var editor;
	    if (type === 'dir') {
		editor = 'PVE.storage.DirEdit';
	    } else if (type === 'nfs') {
		editor = 'PVE.storage.NFSEdit';
	    } else if (type === 'lvm') {
		editor = 'PVE.storage.LVMEdit';
	    } else if (type === 'iscsi') {
		editor = 'PVE.storage.IScsiEdit';
43 44
	    } else if (type === 'rbd') {
		editor = 'PVE.storage.RBDEdit';
45 46
	    } else if (type === 'sheepdog') {
		editor = 'PVE.storage.SheepdogEdit';
47 48
	    } else if (type === 'nexenta') {
		editor = 'PVE.storage.NexentaEdit';
49 50 51 52 53 54 55 56 57 58 59
	    } else {
		return;
	    }
	    var win = Ext.create(editor, {
		storageId: rec.data.storage
	    });

	    win.show();
	    win.on('destroy', reload);
	};
	
60
	var edit_btn = new PVE.button.Button({
61
	    text: gettext('Edit'),
62
	    disabled: true,
63
	    selModel: sm,
64 65 66
	    handler: run_editor
	});

67
	var remove_btn = new PVE.button.Button({
68
	    text: gettext('Remove'),
69
	    disabled: true,
70 71 72 73 74
	    selModel: sm,
	    confirmMsg: function (rec) {
		return Ext.String.format(gettext('Are you sure you want to remove entry {0}'),
					 "'" + rec.data.storage + "'");
	    },
75
	    handler: function(btn, event, rec) {
76 77 78 79 80 81 82 83
		PVE.Utils.API2Request({
		    url: '/storage/' + rec.data.storage,
		    method: 'DELETE',
		    waitMsgTarget: me,
		    callback: function() {
			reload();
		    },
		    failure: function (response, opts) {
Dietmar Maurer's avatar
Dietmar Maurer committed
84
			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
85 86 87 88 89 90 91
		    }
		});
	    }
	});

	Ext.apply(me, {
	    store: store,
92
	    selModel: sm,
93 94 95 96 97 98
	    stateful: false,
	    viewConfig: {
		trackOver: false
	    },
	    tbar: [ 
		{
99
		    text: gettext('Add'),
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
		    menu: new Ext.menu.Menu({
			items: [
			    {
				text: 'Directory',
				iconCls: 'pve-itype-icon-itype',
				handler: function() {
				    var win = Ext.create('PVE.storage.DirEdit', {});
				    win.on('destroy', reload);
				    win.show();
				}

			    },
			    {
				text: 'LVM group',
				handler: function() {
				    var win = Ext.create('PVE.storage.LVMEdit', {});
				    win.on('destroy', reload);
				    win.show();
				}
			    },
			    {
				text: 'NFS share',
				iconCls: 'pve-itype-icon-node',
				handler: function() {
				    var win = Ext.create('PVE.storage.NFSEdit', {});
				    win.on('destroy', reload);
				    win.show();
				}
			    },
			    {
				text: 'iSCSI target',
				iconCls: 'pve-itype-icon-node',
				handler: function() {
				    var win = Ext.create('PVE.storage.IScsiEdit', {});
				    win.on('destroy', reload);
				    win.show();
				}
Dietmar Maurer's avatar
Dietmar Maurer committed
137
			    }
138 139 140
/* the following type are conidered unstable
 * so we do not enable that on the GUI for now

141 142 143 144 145 146 147 148 149
			    {
				text: 'RBD',
				iconCls: 'pve-itype-icon-node',
				handler: function() {
				    var win = Ext.create('PVE.storage.RBDEdit', {});
				    win.on('destroy', reload);
				    win.show();
				}
			    },
150 151 152 153 154 155 156 157 158
			    {
				text: 'Sheepdog',
				iconCls: 'pve-itype-icon-node',
				handler: function() {
				    var win = Ext.create('PVE.storage.SheepdogEdit', {});
				    win.on('destroy', reload);
				    win.show();
				}
			    },
159 160 161 162 163 164 165 166 167
			    {
				text: 'Nexenta',
				iconCls: 'pve-itype-icon-node',
				handler: function() {
				    var win = Ext.create('PVE.storage.NexentaEdit', {});
				    win.on('destroy', reload);
				    win.show();
				}
			    },
168
*/
169 170 171 172 173 174 175 176
			]
		    })
		},
		remove_btn,
		edit_btn
	    ],
	    columns: [
		{
177
		    header: 'ID',
178 179 180 181 182
		    width: 100,
		    sortable: true,
		    dataIndex: 'storage'
		},
		{
183
		    header: gettext('Type'),
184 185 186 187 188 189
		    width: 60,
		    sortable: true,
		    dataIndex: 'type',
		    renderer: PVE.Utils.format_storage_type
		},
		{
190
		    header: gettext('Content'),
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
		    width: 150,
		    sortable: true,
		    dataIndex: 'content',
		    renderer: PVE.Utils.format_content_types
		},
		{
		    header: 'Path/Target',
		    flex: 1,
		    sortable: true,
		    dataIndex: 'path',
		    renderer: function(value, metaData, record) {
			if (record.data.target) {
			    return record.data.target;
			}
			return value;
		    }
		},
		{
209
		    header: gettext('Shared'),
210 211 212 213 214 215
		    width: 80,
		    sortable: true,
		    dataIndex: 'shared',
		    renderer: PVE.Utils.format_boolean
		},
		{
216
		    header: gettext('Enable'),
217 218 219 220 221 222 223 224
		    width: 80,
		    sortable: true,
		    dataIndex: 'disable',
		    renderer: PVE.Utils.format_neg_boolean
		}
	    ],
	    listeners: {
		show: reload,
225
		itemdblclick: run_editor
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
	    }
	});

	me.callParent();
    }
}, function() {

    Ext.define('pve-storage', {
	extend: 'Ext.data.Model',
	fields: [ 
	    'path', 'type', 'content', 'server', 'portal', 'target', 'export', 'storage',
	    { name: 'shared', type: 'boolean'},
	    { name: 'disable', type: 'boolean'} 
	],
	idProperty: 'storage'
    });

243
});