Commit 38d1f88d authored by Dietmar Maurer's avatar Dietmar Maurer

implement ha resource editor

parent ac69b6b5
......@@ -166,6 +166,7 @@ JSSRC= \
storage/ZFSEdit.js \
storage/ZFSPoolEdit.js \
ha/StatusView.js \
ha/ResourceEdit.js \
ha/Resources.js \
ha/GroupEdit.js \
ha/Groups.js \
......
......@@ -113,8 +113,8 @@ Ext.define('PVE.ha.GroupsView', {
}
],
listeners: {
show: reload
// itemdblclick: run_editor
show: reload,
itemdblclick: run_editor
}
});
......
Ext.define('PVE.ha.VMResourceInputPanel', {
extend: 'PVE.panel.InputPanel',
// only usable to type 'vm'
vmid: undefined,
onGetValues: function(values) {
var me = this;
if (me.create) {
values.type = 'vm';
values.sid = values.vmid;
delete values['delete']; // ignore
}
delete values.vmid;
if (values.enable) {
values.state = 'enabled';
} else {
values.state = 'disabled';
}
delete values.enable;
return values;
},
initComponent : function() {
var me = this;
me.column1 = [
{
xtype: me.vmid ? 'displayfield' : 'pveVMIDSelector',
name: 'vmid',
fieldLabel: 'VM ID',
value: me.vmid,
loadNextFreeVMID: false,
validateExists: true
}
];
me.column2 = [
{
xtype: 'pvetextfield', // fixme: group selector
name: 'group',
value: '',
deleteEmpty: true,
fieldLabel: gettext('Group')
},
{
xtype: 'pvecheckbox',
name: 'enable',
checked: true,
uncheckedValue: 0,
fieldLabel: gettext('enable')
}
];
me.columnB = [
{
xtype: 'textfield',
name: 'comment',
fieldLabel: gettext('Comment')
}
];
me.callParent();
}
});
Ext.define('PVE.ha.VMResourceEdit', {
extend: 'PVE.window.Edit',
vmid: undefined,
initComponent : function() {
var me = this;
me.create = !me.vmid;
if (me.create) {
me.url = '/api2/extjs/cluster/ha/resources';
me.method = 'POST';
} else {
me.url = '/api2/extjs/cluster/ha/resources/vm:' + me.vmid;
me.method = 'PUT';
}
var ipanel = Ext.create('PVE.ha.VMResourceInputPanel', {
create: me.create,
vmid: me.vmid
});
Ext.apply(me, {
subject: gettext('VM Resource'),
isAdd: true,
items: [ ipanel ]
});
me.callParent();
if (!me.create) {
me.load({
success: function(response, options) {
var values = response.result.data;
values.enable = false;
if (values.state === 'enabled') {
values.enable = true;
}
var regex = /^(\S+):(\S+)$/;
var res = regex.exec(values.sid);
if (res[1] !== 'vm') { throw "got unexpected resource type"; };
values.vmid = res[2];
ipanel.setValues(values);
}
});
}
}
});
......@@ -23,6 +23,52 @@ Ext.define('PVE.ha.ResourcesView', {
var sm = Ext.create('Ext.selection.RowModel', {});
var run_editor = function() {
var rec = sm.getSelection()[0];
var sid = rec.data.sid;
var regex = /^(\S+):(\S+)$/;
var res = regex.exec(sid);
if (res[1] !== 'vm') { return; };
var vmid = res[2];
var win = Ext.create('PVE.ha.VMResourceEdit',{
vmid: vmid
});
win.on('destroy', reload);
win.show();
};
var remove_btn = new PVE.button.Button({
text: gettext('Remove'),
disabled: true,
selModel: sm,
handler: function(btn, event, rec) {
var sid = rec.data.sid;
PVE.Utils.API2Request({
url: '/cluster/ha/resources/' + sid,
method: 'DELETE',
waitMsgTarget: me,
callback: function() {
reload();
},
failure: function (response, opts) {
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
}
});
}
});
var edit_btn = new PVE.button.Button({
text: gettext('Edit'),
disabled: true,
selModel: sm,
handler: run_editor
});
Ext.apply(me, {
store: store,
selModel: sm,
......@@ -30,6 +76,18 @@ Ext.define('PVE.ha.ResourcesView', {
viewConfig: {
trackOver: false
},
tbar: [
{
text: gettext('Add'),
handler: function() {
var win = Ext.create('PVE.ha.VMResourceEdit',{});
win.on('destroy', reload);
win.show();
}
},
edit_btn, remove_btn
],
columns: [
{
header: 'ID',
......@@ -59,8 +117,8 @@ Ext.define('PVE.ha.ResourcesView', {
}
],
listeners: {
show: reload
// itemdblclick: run_editor
show: reload,
itemdblclick: run_editor
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment