diff --git a/js/MailProxyConfiguration.js b/js/MailProxyConfiguration.js index fe58248..c000dc9 100644 --- a/js/MailProxyConfiguration.js +++ b/js/MailProxyConfiguration.js @@ -27,7 +27,7 @@ Ext.define('PMG.MailProxyConfiguration', { }, { title: gettext('Networks'), - html: "Networks" + xtype: 'pmgMyNetworks' }, { title: gettext('TLS'), diff --git a/js/Makefile b/js/Makefile index 8d3bf6a..e35f3b1 100644 --- a/js/Makefile +++ b/js/Makefile @@ -8,6 +8,7 @@ JSSRC= \ MailProxyPorts.js \ MailProxyOptions.js \ Transport.js \ + MyNetworks.js \ RelayDomains.js \ MailProxyConfiguration.js \ ConfigPanel.js \ diff --git a/js/MyNetworks.js b/js/MyNetworks.js new file mode 100644 index 0000000..c40e9b2 --- /dev/null +++ b/js/MyNetworks.js @@ -0,0 +1,157 @@ +Ext.define('pmg-mynetworks', { + extend: 'Ext.data.Model', + fields: [ 'cidr', 'comment' ], + proxy: { + type: 'proxmox', + url: "/api2/json/config/mynetworks" + }, + idProperty: 'cidr' +}); + +Ext.define('PMG.MyNetworks', { + extend: 'Ext.grid.GridPanel', + alias: ['widget.pmgMyNetworks'], + + initComponent : function() { + var me = this; + + var store = new Ext.data.Store({ + model: 'pmg-mynetworks', + sorters: { + property: 'cidr', + order: 'DESC' + } + }); + + var reload = function() { + store.load(); + }; + + me.selModel = Ext.create('Ext.selection.RowModel', {}); + + var remove_btn = Ext.createWidget('proxmoxButton', { + text: gettext('Remove'), + disabled: true, + selModel: me.selModel, + confirmMsg: function (rec) { + return Ext.String.format( + gettext('Are you sure you want to remove entry {0}'), + "'" + rec.data.cidr + "'"); + }, + handler: function(btn, event, rec) { + Proxmox.Utils.API2Request({ + url: '/config/mynetworks/' + rec.data.cidr, + method: 'DELETE', + waitMsgTarget: me, + callback: function() { + reload(); + }, + failure: function (response, opts) { + Ext.Msg.alert(gettext('Error'), response.htmlStatus); + } + }); + } + }); + + var run_editor = function() { + var rec = me.selModel.getSelection()[0]; + if (!rec) { + return; + } + + var config = { + url: "/api2/extjs/config/mynetworks/" + rec.data.cidr, + method: 'PUT', + subject: gettext("Trusted Network"), + items: [ + { + xtype: 'displayfield', + name: 'cidr', + fieldLabel: 'CIDR' + }, + { + xtype: 'textfield', + name: 'comment', + fieldLabel: gettext("Comment") + } + ] + }; + + var win = Ext.createWidget('proxmoxWindowEdit', config); + + win.load(); + win.on('destroy', reload); + win.show(); + }; + + var tbar = [ + { + xtype: 'proxmoxButton', + text: gettext('Edit'), + disabled: true, + selModel: me.selModel, + handler: run_editor + }, + { + text: gettext('Create'), + handler: function() { + var config = { + method: 'POST', + url: "/api2/extjs/config/mynetworks", + create: true, + subject: gettext("Trusted Network"), + items: [ + { + xtype: 'proxmoxtextfield', + name: 'cidr', + fieldLabel: 'CIDR' + }, + { + xtype: 'proxmoxtextfield', + name: 'comment', + fieldLabel: gettext("Comment") + } + ] + }; + + var win = Ext.createWidget('proxmoxWindowEdit', config); + + win.on('destroy', reload); + win.show(); + } + }, + remove_btn + ]; + + Proxmox.Utils.monStoreErrors(me, store); + + Ext.apply(me, { + store: store, + tbar: tbar, + viewConfig: { + trackOver: false + }, + columns: [ + { + header: gettext('Trusted Netowrk'), + width: 200, + sortable: true, + dataIndex: 'cidr' + }, + { + header: gettext('Comment'), + sortable: false, + renderer: Ext.String.htmlEncode, + dataIndex: 'comment', + flex: 1 + } + ], + listeners: { + itemdblclick: run_editor, + activate: reload + } + }); + + me.callParent(); + } +});