]> git.proxmox.com Git - pmg-gui.git/blame - js/Transport.js
mail proxy: relay domains: consitent add/edit/remove button
[pmg-gui.git] / js / Transport.js
CommitLineData
c51d3f79
DM
1Ext.define('pmg-transport', {
2 extend: 'Ext.data.Model',
c87d46fb
TL
3 fields: ['domain', 'host', 'protocol', { name: 'port', type: 'integer' },
4 { name: 'use_mx', type: 'boolean' }, 'comment'],
c51d3f79
DM
5 proxy: {
6 type: 'proxmox',
c87d46fb 7 url: "/api2/json/config/transport",
c51d3f79 8 },
c87d46fb 9 idProperty: 'domain',
c51d3f79
DM
10});
11
12Ext.define('PMG.Transport', {
13 extend: 'Ext.grid.GridPanel',
14 alias: ['widget.pmgTransport'],
15
c87d46fb 16 initComponent: function() {
c502e50c 17 let me = this;
c51d3f79 18
c502e50c 19 let store = new Ext.data.Store({
c51d3f79
DM
20 model: 'pmg-transport',
21 sorters: {
22 property: 'domain',
18722987 23 direction: 'ASC',
c87d46fb 24 },
c51d3f79 25 });
c502e50c
TL
26 Proxmox.Utils.monStoreErrors(me, store, true);
27 let reload = () => store.load();
c51d3f79
DM
28
29 me.selModel = Ext.create('Ext.selection.RowModel', {});
30
c502e50c
TL
31 let run_editor = function() {
32 let rec = me.selModel.getSelection()[0];
c51d3f79
DM
33 if (!rec) {
34 return;
35 }
36
00b648d2 37 let win = Ext.createWidget('pmgTransportEditor', {
c51d3f79
DM
38 url: "/api2/extjs/config/transport/" + rec.data.domain,
39 method: 'PUT',
00b648d2 40 });
c51d3f79
DM
41 win.load();
42 win.on('destroy', reload);
43 win.show();
44 };
45
c51d3f79
DM
46 Ext.apply(me, {
47 store: store,
00b648d2
TL
48 tbar: [
49 {
50 xtype: 'proxmoxButton',
51 text: gettext('Edit'),
52 disabled: true,
53 selModel: me.selModel,
c87d46fb 54 handler: run_editor,
00b648d2
TL
55 },
56 {
57 text: gettext('Create'),
58 handler: function() {
59 let win = Ext.createWidget('pmgTransportEditor', {
60 method: 'POST',
61 url: "/api2/extjs/config/transport",
62 isCreate: true,
63 });
64 win.on('destroy', reload);
65 win.show();
c87d46fb 66 },
00b648d2
TL
67 },
68 {
69 xtype: 'proxmoxStdRemoveButton',
70 selModel: me.selModel,
71 baseurl: '/config/transport',
72 callback: reload,
c87d46fb 73 waitMsgTarget: me,
00b648d2 74 },
4703989a
DC
75 '->',
76 {
77 xtype: 'pmgFilterField',
78 filteredFields: ['domain', 'host', 'port', 'protocol', 'comment'],
79 },
00b648d2 80 ],
c51d3f79 81 viewConfig: {
c87d46fb 82 trackOver: false,
c51d3f79
DM
83 },
84 columns: [
85 {
86 header: gettext('Relay Domain'),
87 width: 200,
c87d46fb 88 dataIndex: 'domain',
c51d3f79
DM
89 },
90 {
91 header: gettext('Host'),
92 width: 200,
c87d46fb 93 dataIndex: 'host',
c51d3f79 94 },
d895a746
JZ
95 {
96 header: gettext('Protocol'),
97 width: 200,
c87d46fb 98 dataIndex: 'protocol',
d895a746 99 },
c51d3f79
DM
100 {
101 header: gettext('Port'),
102 width: 80,
c87d46fb 103 dataIndex: 'port',
c51d3f79
DM
104 },
105 {
ae377bbe 106 header: gettext('Use MX'),
c51d3f79
DM
107 width: 80,
108 renderer: Proxmox.Utils.format_boolean,
c87d46fb 109 dataIndex: 'use_mx',
c51d3f79
DM
110 },
111 {
112 header: gettext('Comment'),
c51d3f79
DM
113 renderer: Ext.String.htmlEncode,
114 dataIndex: 'comment',
c87d46fb
TL
115 flex: 1,
116 },
c51d3f79
DM
117 ],
118 listeners: {
119 itemdblclick: run_editor,
c87d46fb
TL
120 activate: reload,
121 },
c51d3f79
DM
122 });
123
124 me.callParent();
c87d46fb 125 },
c51d3f79 126});
00b648d2
TL
127
128Ext.define('PMG.TransportEditor', {
129 extend: 'Proxmox.window.Edit',
130 alias: 'widget.pmgTransportEditor',
131 mixins: ['Proxmox.Mixin.CBind'],
132
c87d46fb 133 cbindData: (cfg) => ({
00b648d2 134 domainXType: cfg.method === 'POST' ? 'proxmoxtextfield' : 'displayfield',
c87d46fb 135 }),
00b648d2 136
ae377bbe
TL
137 viewModel: {
138 data: {
139 proto: 'smtp',
140 },
141 formulas: {
142 protoIsSMTP: get => get('proto') === 'smtp',
143 },
144 },
00b648d2
TL
145 onlineHelp: 'pmgconfig_mailproxy_transports',
146 subject: gettext("Transport"),
147
148 items: [
149 {
150 xtype: 'displayfield',
151 cbind: {
152 xtype: '{domainXType}',
153 },
154 name: 'domain',
c87d46fb 155 fieldLabel: gettext("Relay Domain"),
00b648d2
TL
156 },
157 {
158 xtype: 'textfield',
159 name: 'host',
c87d46fb 160 fieldLabel: gettext("Host"),
00b648d2
TL
161 },
162 {
163 xtype: 'proxmoxKVComboBox',
164 name: 'protocol',
165 fieldLabel: gettext('Protocol'),
166 deleteEmpty: false,
167 comboItems: [
c87d46fb
TL
168 ['smtp', 'SMTP'],
169 ['lmtp', 'LMTP'],
00b648d2
TL
170 ],
171 allowBlank: true,
172 value: 'smtp',
ae377bbe 173 bind: {
c87d46fb 174 value: '{proto}',
ae377bbe 175 },
00b648d2
TL
176 },
177 {
178 xtype: 'proxmoxintegerfield',
179 name: 'port',
180 value: 25,
181 minValue: 1,
182 maxValue: 65535,
c87d46fb 183 fieldLabel: gettext("Port"),
00b648d2
TL
184 },
185 {
186 xtype: 'proxmoxcheckbox',
187 name: 'use_mx',
188 checked: true,
ae377bbe
TL
189 bind: {
190 disabled: '{!protoIsSMTP}',
191 hidden: '{!protoIsSMTP}',
192 },
00b648d2
TL
193 uncheckedValue: 0,
194 fieldLabel: gettext('Use MX'),
195 },
196 {
197 xtype: 'textfield',
198 name: 'comment',
c87d46fb 199 fieldLabel: gettext("Comment"),
00b648d2
TL
200 },
201 ],
202});