]> git.proxmox.com Git - pmg-gui.git/blame - js/Transport.js
mail proxy: transports: 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 48 tbar: [
a5549117
TL
49 {
50 text: gettext('Create'),
51 handler: () => Ext.createWidget('pmgTransportEditor', {
52 autoShow: true,
53 method: 'POST',
54 url: "/api2/extjs/config/transport",
55 isCreate: true,
56 listeners: {
57 destroy: () => reload(),
58 },
59 }),
60 },
61 '-',
00b648d2
TL
62 {
63 xtype: 'proxmoxButton',
64 text: gettext('Edit'),
65 disabled: true,
66 selModel: me.selModel,
c87d46fb 67 handler: run_editor,
00b648d2 68 },
00b648d2
TL
69 {
70 xtype: 'proxmoxStdRemoveButton',
71 selModel: me.selModel,
72 baseurl: '/config/transport',
73 callback: reload,
c87d46fb 74 waitMsgTarget: me,
00b648d2 75 },
4703989a
DC
76 '->',
77 {
78 xtype: 'pmgFilterField',
79 filteredFields: ['domain', 'host', 'port', 'protocol', 'comment'],
80 },
00b648d2 81 ],
c51d3f79 82 viewConfig: {
c87d46fb 83 trackOver: false,
c51d3f79
DM
84 },
85 columns: [
86 {
87 header: gettext('Relay Domain'),
88 width: 200,
c87d46fb 89 dataIndex: 'domain',
c51d3f79
DM
90 },
91 {
92 header: gettext('Host'),
93 width: 200,
c87d46fb 94 dataIndex: 'host',
c51d3f79 95 },
d895a746
JZ
96 {
97 header: gettext('Protocol'),
98 width: 200,
c87d46fb 99 dataIndex: 'protocol',
d895a746 100 },
c51d3f79
DM
101 {
102 header: gettext('Port'),
103 width: 80,
c87d46fb 104 dataIndex: 'port',
c51d3f79
DM
105 },
106 {
ae377bbe 107 header: gettext('Use MX'),
c51d3f79
DM
108 width: 80,
109 renderer: Proxmox.Utils.format_boolean,
c87d46fb 110 dataIndex: 'use_mx',
c51d3f79
DM
111 },
112 {
113 header: gettext('Comment'),
c51d3f79
DM
114 renderer: Ext.String.htmlEncode,
115 dataIndex: 'comment',
c87d46fb
TL
116 flex: 1,
117 },
c51d3f79
DM
118 ],
119 listeners: {
120 itemdblclick: run_editor,
c87d46fb
TL
121 activate: reload,
122 },
c51d3f79
DM
123 });
124
125 me.callParent();
c87d46fb 126 },
c51d3f79 127});
00b648d2
TL
128
129Ext.define('PMG.TransportEditor', {
130 extend: 'Proxmox.window.Edit',
131 alias: 'widget.pmgTransportEditor',
132 mixins: ['Proxmox.Mixin.CBind'],
133
c87d46fb 134 cbindData: (cfg) => ({
00b648d2 135 domainXType: cfg.method === 'POST' ? 'proxmoxtextfield' : 'displayfield',
c87d46fb 136 }),
00b648d2 137
ae377bbe
TL
138 viewModel: {
139 data: {
140 proto: 'smtp',
141 },
142 formulas: {
143 protoIsSMTP: get => get('proto') === 'smtp',
144 },
145 },
00b648d2
TL
146 onlineHelp: 'pmgconfig_mailproxy_transports',
147 subject: gettext("Transport"),
148
149 items: [
150 {
151 xtype: 'displayfield',
152 cbind: {
153 xtype: '{domainXType}',
154 },
155 name: 'domain',
c87d46fb 156 fieldLabel: gettext("Relay Domain"),
00b648d2
TL
157 },
158 {
159 xtype: 'textfield',
160 name: 'host',
c87d46fb 161 fieldLabel: gettext("Host"),
00b648d2
TL
162 },
163 {
164 xtype: 'proxmoxKVComboBox',
165 name: 'protocol',
166 fieldLabel: gettext('Protocol'),
167 deleteEmpty: false,
168 comboItems: [
c87d46fb
TL
169 ['smtp', 'SMTP'],
170 ['lmtp', 'LMTP'],
00b648d2
TL
171 ],
172 allowBlank: true,
173 value: 'smtp',
ae377bbe 174 bind: {
c87d46fb 175 value: '{proto}',
ae377bbe 176 },
00b648d2
TL
177 },
178 {
179 xtype: 'proxmoxintegerfield',
180 name: 'port',
181 value: 25,
182 minValue: 1,
183 maxValue: 65535,
c87d46fb 184 fieldLabel: gettext("Port"),
00b648d2
TL
185 },
186 {
187 xtype: 'proxmoxcheckbox',
188 name: 'use_mx',
189 checked: true,
ae377bbe
TL
190 bind: {
191 disabled: '{!protoIsSMTP}',
192 hidden: '{!protoIsSMTP}',
193 },
00b648d2
TL
194 uncheckedValue: 0,
195 fieldLabel: gettext('Use MX'),
196 },
197 {
198 xtype: 'textfield',
199 name: 'comment',
c87d46fb 200 fieldLabel: gettext("Comment"),
00b648d2
TL
201 },
202 ],
203});