Commit 778a7af5 authored by Dietmar Maurer's avatar Dietmar Maurer

rename IPSetSelector to IPRefSelector, and use it in IPSet

parent df3feb46
......@@ -44,7 +44,7 @@ JSSRC= \
form/StorageSelector.js \
form/BridgeSelector.js \
form/SecurityGroupSelector.js \
form/IPSetSelector.js \
form/IPRefSelector.js \
form/IPProtocolSelector.js \
form/CPUModelSelector.js \
form/VNCKeyboardSelector.js \
......
......@@ -200,7 +200,7 @@ Ext.define('PVE.SecurityGroups', {
var rule_panel = Ext.createWidget('pveFirewallRules', {
region: 'center',
allow_groups: false,
ipset_base_url: '/cluster/firewall/refs',
list_refs_url: '/cluster/firewall/refs',
tbar_prefix: '<b>' + gettext('Rules') + ':</b>',
flex: 0.75,
border: false
......
Ext.define('PVE.form.IPSetSelector', {
Ext.define('PVE.form.IPRefSelector', {
extend: 'PVE.form.ComboGrid',
alias: ['widget.pveIPSetSelector'],
alias: ['widget.pveIPRefSelector'],
base_url: undefined,
preferredValue: '', // hack: else Form sets dirty flag?
ref_type: undefined, // undefined = any [undefined, 'ipset' or 'alias']
initComponent: function() {
var me = this;
......@@ -13,13 +15,18 @@ Ext.define('PVE.form.IPSetSelector', {
throw "no base_url specified";
}
var url = "/api2/json" + me.base_url;
if (me.ref_type) {
url += "?type=" + me.ref_type;
}
var store = Ext.create('Ext.data.Store', {
autoLoad: true,
fields: [ 'type', 'name', 'ref', 'comment' ],
idProperty: 'ref',
proxy: {
type: 'pve',
url: "/api2/json" + me.base_url
url: url
},
sorters: {
property: 'ref',
......@@ -28,38 +35,44 @@ Ext.define('PVE.form.IPSetSelector', {
});
var disable_query_for_ips = function(f, value) {
if (value.match(/^\d/)) { // IP address starts with \d
if (value === null ||
value.match(/^\d/)) { // IP address starts with \d
f.queryDelay = 9999999999; // hack: disbale with long delay
} else {
f.queryDelay = 10;
}
};
var columns = [];
if (!me.ref_type) {
columns.push({
header: gettext('Type'),
dataIndex: 'type',
hideable: false,
width: 60
});
}
columns.push([
{
header: gettext('Name'),
dataIndex: 'ref',
hideable: false,
width: 140
},
{
header: gettext('Comment'),
dataIndex: 'comment',
flex: 1
}
]);
Ext.apply(me, {
store: store,
valueField: 'ref',
displayField: 'ref',
listConfig: {
columns: [
{
header: gettext('Type'),
dataIndex: 'type',
hideable: false,
width: 60
},
{
header: gettext('Name'),
dataIndex: 'ref',
hideable: false,
width: 140
},
{
header: gettext('Comment'),
dataIndex: 'comment',
flex: 1
}
]
}
listConfig: { columns: columns }
});
me.on('change', disable_query_for_ips);
......
......@@ -51,7 +51,7 @@ Ext.define('PVE.FirewallRulePanel', {
allow_iface: false,
ipset_base_url: undefined,
list_refs_url: undefined,
onGetValues: function(values) {
var me = this;
......@@ -73,8 +73,8 @@ Ext.define('PVE.FirewallRulePanel', {
initComponent : function() {
var me = this;
if (!me.ipset_base_url) {
throw "no ipset_base_url specified";
if (!me.list_refs_url) {
throw "no list_refs_url specified";
}
me.column1 = [
......@@ -129,21 +129,21 @@ Ext.define('PVE.FirewallRulePanel', {
value: ''
},
{
xtype: 'pveIPSetSelector',
xtype: 'pveIPRefSelector',
name: 'source',
autoSelect: false,
editable: true,
base_url: me.ipset_base_url,
base_url: me.list_refs_url,
value: '',
fieldLabel: gettext('Source')
},
{
xtype: 'pveIPSetSelector',
xtype: 'pveIPRefSelector',
name: 'dest',
autoSelect: false,
editable: true,
base_url: me.ipset_base_url,
base_url: me.list_refs_url,
value: '',
fieldLabel: gettext('Destination')
}
......@@ -228,7 +228,7 @@ Ext.define('PVE.FirewallRuleEdit', {
extend: 'PVE.window.Edit',
base_url: undefined,
ipset_base_url: undefined,
list_refs_url: undefined,
allow_iface: false,
......@@ -239,8 +239,8 @@ Ext.define('PVE.FirewallRuleEdit', {
if (!me.base_url) {
throw "no base_url specified";
}
if (!me.ipset_base_url) {
throw "no ipset_base_url specified";
if (!me.list_refs_url) {
throw "no list_refs_url specified";
}
me.create = (me.rule_pos === undefined);
......@@ -255,7 +255,7 @@ Ext.define('PVE.FirewallRuleEdit', {
var ipanel = Ext.create('PVE.FirewallRulePanel', {
create: me.create,
ipset_base_url: me.ipset_base_url,
list_refs_url: me.list_refs_url,
allow_iface: me.allow_iface,
rule_pos: me.rule_pos
});
......@@ -380,7 +380,7 @@ Ext.define('PVE.FirewallRules', {
alias: 'widget.pveFirewallRules',
base_url: undefined,
ipset_base_url: undefined,
list_refs_url: undefined,
addBtn: undefined,
removeBtn: undefined,
......@@ -490,8 +490,8 @@ Ext.define('PVE.FirewallRules', {
/*jslint confusion: true */
var me = this;
if (!me.ipset_base_url) {
throw "no ipset_base_url specified";
if (!me.list_refs_url) {
throw "no list_refs_url specified";
}
var store = new Ext.data.Store({
......@@ -524,7 +524,7 @@ Ext.define('PVE.FirewallRules', {
digest: rec.data.digest,
allow_iface: me.allow_iface,
base_url: me.base_url,
ipset_base_url: me.ipset_base_url,
list_refs_url: me.list_refs_url,
rule_pos: rec.data.pos
});
......@@ -546,7 +546,7 @@ Ext.define('PVE.FirewallRules', {
var win = Ext.create('PVE.FirewallRuleEdit', {
allow_iface: me.allow_iface,
base_url: me.base_url,
ipset_base_url: me.ipset_base_url
list_refs_url: me.list_refs_url
});
win.on('destroy', reload);
win.show();
......
......@@ -20,14 +20,16 @@ Ext.define('PVE.panel.Firewall', {
throw "unknown firewall panel type";
}
var list_refs_url = me.fwtype === 'vm' ? (me.base_url + '/refs') :
'/cluster/firewall/refs';
var items = [
{
xtype: 'pveFirewallRules',
title: 'Rules',
allow_iface: true,
base_url: me.base_url + '/rules',
ipset_base_url: me.fwtype === 'vm' ? (me.base_url + '/refs') :
'/cluster/firewall/refs',
list_refs_url: list_refs_url,
itemId: 'rules'
}
];
......@@ -45,7 +47,8 @@ Ext.define('PVE.panel.Firewall', {
});
items.push({
xtype: 'pveIPSet',
base_url: '/cluster/firewall/ipset',
base_url: '/cluster/firewall/ipset',
list_refs_url: list_refs_url,
itemId: 'ipset'
});
}
......@@ -59,6 +62,7 @@ Ext.define('PVE.panel.Firewall', {
items.push({
xtype: 'pveIPSet',
base_url: me.base_url + '/ipset',
list_refs_url: list_refs_url,
itemId: 'ipset'
});
}
......
......@@ -180,6 +180,7 @@ Ext.define('PVE.IPSetCidrEdit', {
me.create = (me.cidr === undefined);
if (me.create) {
me.url = '/api2/extjs' + me.base_url;
me.method = 'POST';
......@@ -188,17 +189,36 @@ Ext.define('PVE.IPSetCidrEdit', {
me.method = 'PUT';
}
var column1 = [];
if (me.create) {
if (!me.list_refs_url) {
throw "no alias_base_url specified";
}
column1.push({
xtype: 'pveIPRefSelector',
name: 'cidr',
ref_type: 'alias',
autoSelect: false,
editable: true,
base_url: me.list_refs_url,
value: '',
fieldLabel: gettext('IP/CIDR')
});
} else {
column1.push({
xtype: 'displayfield',
name: 'cidr',
height: 22, // hack: set same height as text fields
value: '',
fieldLabel: gettext('IP/CIDR')
});
}
var ipanel = Ext.create('PVE.panel.InputPanel', {
create: me.create,
column1: [
{
xtype: me.create ? 'textfield' : 'displayfield',
name: 'cidr',
height: 22, // hack: set same height as text fields
value: '',
fieldLabel: gettext('IP/CIDR')
}
],
column1: column1,
column2: [
{
xtype: 'pvecheckbox',
......@@ -242,6 +262,7 @@ Ext.define('PVE.IPSetGrid', {
alias: 'widget.pveIPSetGrid',
base_url: undefined,
list_refs_url: undefined,
addBtn: undefined,
removeBtn: undefined,
......@@ -270,6 +291,10 @@ Ext.define('PVE.IPSetGrid', {
/*jslint confusion: true */
var me = this;
if (!me.list_refs_url) {
throw "no1 list_refs_url specified";
}
var store = new Ext.data.Store({
model: 'pve-ipset'
});
......@@ -308,7 +333,8 @@ Ext.define('PVE.IPSetGrid', {
return;
}
var win = Ext.create('PVE.IPSetCidrEdit', {
base_url: me.base_url
base_url: me.base_url,
list_refs_url: me.list_refs_url
});
win.show();
win.on('destroy', reload);
......@@ -393,11 +419,18 @@ Ext.define('PVE.IPSet', {
title: 'IPSet',
list_refs_url: undefined,
initComponent: function() {
var me = this;
if (!me.list_refs_url) {
throw "no list_refs_url specified";
}
var ipset_panel = Ext.createWidget('pveIPSetGrid', {
region: 'center',
list_refs_url: me.list_refs_url,
flex: 0.5,
border: false
});
......
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