]> git.proxmox.com Git - proxmox-backup.git/blob - www/window/RemoteEdit.js
bf5c11fc94d538e8f2dd5d4900bc89f3cecff115
[proxmox-backup.git] / www / window / RemoteEdit.js
1 Ext.define('PBS.window.RemoteEdit', {
2 extend: 'Proxmox.window.Edit',
3 alias: 'widget.pbsRemoteEdit',
4 mixins: ['Proxmox.Mixin.CBind'],
5
6 onlineHelp: 'backup_remote',
7
8 userid: undefined,
9
10 isAdd: true,
11
12 subject: gettext('Remote'),
13
14 fieldDefaults: { labelWidth: 120 },
15
16 cbindData: function(initialConfig) {
17 let me = this;
18
19 let baseurl = '/api2/extjs/config/remote';
20 let name = initialConfig.name;
21
22 me.isCreate = !name;
23 me.url = name ? `${baseurl}/${name}` : baseurl;
24 me.method = name ? 'PUT' : 'POST';
25 me.autoLoad = !!name;
26 return {
27 passwordEmptyText: me.isCreate ? '' : gettext('Unchanged'),
28 };
29 },
30
31 items: {
32 xtype: 'inputpanel',
33 column1: [
34 {
35 xtype: 'pmxDisplayEditField',
36 name: 'name',
37 fieldLabel: gettext('Remote'),
38 renderer: Ext.htmlEncode,
39 allowBlank: false,
40 minLength: 4,
41 cbind: {
42 editable: '{isCreate}',
43 },
44 },
45 {
46 xtype: 'proxmoxtextfield',
47 allowBlank: false,
48 name: 'hostport',
49 submitValue: false,
50 vtype: 'HostPort',
51 fieldLabel: gettext('Host'),
52 listeners: {
53 change: function(field, newvalue) {
54 let host = newvalue;
55 let port;
56
57 let match = Proxmox.Utils.HostPort_match.exec(newvalue);
58 if (match === null) {
59 match = Proxmox.Utils.HostPortBrackets_match.exec(newvalue);
60 if (match === null) {
61 match = Proxmox.Utils.IP6_dotnotation_match.exec(newvalue);
62 }
63 }
64
65 if (match !== null) {
66 host = match[1];
67 if (match[2] !== undefined) {
68 port = match[2];
69 }
70 }
71
72 field.up('inputpanel').down('field[name=host]').setValue(host);
73 field.up('inputpanel').down('field[name=port]').setValue(port);
74 }
75 }
76 },
77 {
78 xtype: 'proxmoxtextfield',
79 hidden: true,
80 name: 'host',
81 },
82 {
83 xtype: 'proxmoxtextfield',
84 hidden: true,
85 deleteEmpty: true,
86 name: 'port',
87 },
88 ],
89
90 column2: [
91 {
92 xtype: 'proxmoxtextfield',
93 allowBlank: false,
94 name: 'userid',
95 fieldLabel: gettext('Userid'),
96 },
97 {
98 xtype: 'textfield',
99 inputType: 'password',
100 fieldLabel: gettext('Password'),
101 name: 'password',
102 cbind: {
103 emptyText: '{passwordEmptyText}',
104 allowBlank: '{!isCreate}',
105 },
106 },
107 ],
108
109 columnB: [
110 {
111 xtype: 'proxmoxtextfield',
112 name: 'fingerprint',
113 deleteEmpty: true,
114 fieldLabel: gettext('Fingerprint'),
115 },
116 {
117 xtype: 'proxmoxtextfield',
118 name: 'comment',
119 deleteEmpty: true,
120 fieldLabel: gettext('Comment'),
121 },
122 ],
123 },
124
125 setValues: function(values) {
126 let me = this;
127
128 let host = values.host;
129 if (values.port !== undefined) {
130 if (Proxmox.Utils.IP6_match.test(host)) {
131 host = `[${host}]`;
132 }
133 host += `:${values.port}`;
134 }
135 values.hostport = host;
136
137 return me.callParent([values]);
138 },
139
140 getValues: function() {
141 let me = this;
142 let values = me.callParent(arguments);
143
144 if (values.password === '') {
145 delete values.password;
146 }
147
148 return values;
149 },
150 });