]> git.proxmox.com Git - pmg-gui.git/blame - js/MyNetworks.js
mail proxy: networks: consitent add/edit/remove button & modernization
[pmg-gui.git] / js / MyNetworks.js
CommitLineData
96feba89
DM
1Ext.define('pmg-mynetworks', {
2 extend: 'Ext.data.Model',
c87d46fb 3 fields: ['cidr', 'comment'],
96feba89
DM
4 proxy: {
5 type: 'proxmox',
c87d46fb 6 url: "/api2/json/config/mynetworks",
96feba89 7 },
c87d46fb 8 idProperty: 'cidr',
96feba89
DM
9});
10
11Ext.define('PMG.MyNetworks', {
12 extend: 'Ext.grid.GridPanel',
13 alias: ['widget.pmgMyNetworks'],
14
c87d46fb 15 initComponent: function() {
216711f1 16 let me = this;
96feba89 17
216711f1 18 let store = new Ext.data.Store({
96feba89
DM
19 model: 'pmg-mynetworks',
20 sorters: {
21 property: 'cidr',
18722987 22 direction: 'ASC',
c87d46fb 23 },
96feba89 24 });
216711f1 25 let reload = () => store.load();
96feba89
DM
26
27 me.selModel = Ext.create('Ext.selection.RowModel', {});
28
216711f1
TL
29 let run_editor = function() {
30 let rec = me.selModel.getSelection()[0];
96feba89
DM
31 if (!rec) {
32 return;
33 }
216711f1
TL
34 Ext.createWidget('proxmoxWindowEdit', {
35 autoShow: true,
36 autoLoad: true,
96feba89 37 url: "/api2/extjs/config/mynetworks/" + rec.data.cidr,
573a6e8b 38 onlineHelp: 'pmgconfig_mailproxy_networks',
96feba89
DM
39 method: 'PUT',
40 subject: gettext("Trusted Network"),
41 items: [
42 {
43 xtype: 'displayfield',
44 name: 'cidr',
d2d9df1a 45 fieldLabel: gettext('CIDR'),
96feba89
DM
46 },
47 {
48 xtype: 'textfield',
49 name: 'comment',
c87d46fb
TL
50 fieldLabel: gettext("Comment"),
51 },
52 ],
216711f1
TL
53 listeners: {
54 destroy: () => reload(),
55 },
56 });
96feba89
DM
57 };
58
216711f1
TL
59 let tbar = [
60 {
61 text: gettext('Create'),
62 handler: () => Ext.createWidget('proxmoxWindowEdit', {
63 autoShow: true,
64 method: 'POST',
65 url: "/api2/extjs/config/mynetworks",
66 onlineHelp: 'pmgconfig_mailproxy_networks',
67 isCreate: true,
68 subject: gettext("Trusted Network"),
69 items: [
70 {
71 xtype: 'proxmoxtextfield',
72 name: 'cidr',
73 fieldLabel: gettext('CIDR'),
74 },
75 {
76 xtype: 'proxmoxtextfield',
77 name: 'comment',
78 fieldLabel: gettext("Comment"),
79 },
80 ],
81 listeners: {
82 destroy: () => reload(),
83 },
84 }),
85 },
86 '-',
96feba89
DM
87 {
88 xtype: 'proxmoxButton',
89 text: gettext('Edit'),
90 disabled: true,
91 selModel: me.selModel,
c87d46fb 92 handler: run_editor,
96feba89 93 },
216711f1
TL
94 {
95 xtype: 'proxmoxStdRemoveButton',
96 selModel: me.selModel,
97 baseurl: '/config/mynetworks',
98 callback: reload,
99 waitMsgTarget: me,
100 },
4703989a
DC
101 '->',
102 {
103 xtype: 'pmgFilterField',
104 filteredFields: ['cidr', 'comment'],
105 },
96feba89
DM
106 ];
107
2f8fe1a3 108 Proxmox.Utils.monStoreErrors(me, store, true);
96feba89
DM
109
110 Ext.apply(me, {
111 store: store,
112 tbar: tbar,
01e0e5e5 113 run_editor: run_editor,
96feba89 114 viewConfig: {
c87d46fb 115 trackOver: false,
96feba89
DM
116 },
117 columns: [
118 {
1000bed1 119 header: gettext('Trusted Network'),
96feba89
DM
120 width: 200,
121 sortable: true,
c87d46fb 122 dataIndex: 'cidr',
96feba89
DM
123 },
124 {
125 header: gettext('Comment'),
126 sortable: false,
127 renderer: Ext.String.htmlEncode,
128 dataIndex: 'comment',
c87d46fb
TL
129 flex: 1,
130 },
96feba89
DM
131 ],
132 listeners: {
133 itemdblclick: run_editor,
c87d46fb
TL
134 activate: reload,
135 },
96feba89
DM
136 });
137
138 me.callParent();
c87d46fb 139 },
96feba89 140});