]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/dc/SyncWindow.js
ui: realm: clarify that the sync jobs really are for the realm
[pve-manager.git] / www / manager6 / dc / SyncWindow.js
CommitLineData
4b60ee19
DC
1Ext.define('PVE.dc.SyncWindow', {
2 extend: 'Ext.window.Window',
3
4 title: gettext('Realm Sync'),
5
6 width: 600,
7 bodyPadding: 10,
8 modal: true,
9 resizable: false,
10
11 controller: {
12 xclass: 'Ext.app.ViewController',
13
14 control: {
15 'form': {
16 validitychange: function(field, valid) {
17 let me = this;
18 me.lookup('preview_btn').setDisabled(!valid);
19 me.lookup('sync_btn').setDisabled(!valid);
20 },
21 },
22 'button': {
23 click: function(btn) {
47ea76b2 24 if (btn.reference === 'help_btn') return;
4b60ee19
DC
25 this.sync_realm(btn.reference === 'preview_btn');
26 },
27 },
28 },
29
30 sync_realm: function(is_preview) {
31 let me = this;
32 let view = me.getView();
33 let ipanel = me.lookup('ipanel');
34 let params = ipanel.getValues();
3e43739f
DC
35
36 let vanished_opts = [];
37 ['acl', 'entry', 'properties'].forEach((prop) => {
38 if (params[`remove-vanished-${prop}`]) {
39 vanished_opts.push(prop);
40 }
41 delete params[`remove-vanished-${prop}`];
42 });
43 if (vanished_opts.length > 0) {
44 params['remove-vanished'] = vanished_opts.join(';');
5347251f
DC
45 } else {
46 params['remove-vanished'] = 'none';
3e43739f
DC
47 }
48
4b60ee19
DC
49 params['dry-run'] = is_preview ? 1 : 0;
50 Proxmox.Utils.API2Request({
51 url: `/access/domains/${view.realm}/sync`,
52 waitMsgTarget: view,
53 method: 'POST',
54 params,
55 failure: function(response) {
56 view.show();
57 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
58 },
59 success: function(response) {
60 view.hide();
61 Ext.create('Proxmox.window.TaskViewer', {
62 upid: response.result.data,
63 listeners: {
64 destroy: function() {
65 if (is_preview) {
66 view.show();
67 } else {
68 view.close();
69 }
70 },
71 },
72 }).show();
73 },
74 });
75 },
76 },
77
78 items: [
79 {
80 xtype: 'form',
81 reference: 'form',
82 border: false,
83 fieldDefaults: {
84 labelWidth: 100,
85 anchor: '100%',
86 },
87 items: [{
88 xtype: 'inputpanel',
89 reference: 'ipanel',
90 column1: [
91 {
92 xtype: 'proxmoxKVComboBox',
93 name: 'scope',
94 fieldLabel: gettext('Scope'),
95 value: '',
e5ede40a 96 emptyText: gettext('No default available'),
4b60ee19
DC
97 deleteEmpty: false,
98 allowBlank: false,
99 comboItems: [
100 ['users', gettext('Users')],
101 ['groups', gettext('Groups')],
102 ['both', gettext('Users and Groups')],
103 ],
104 },
4b60ee19
DC
105 ],
106
107 column2: [
108 {
109 xtype: 'proxmoxKVComboBox',
110 value: '1',
111 deleteEmpty: false,
112 allowBlank: false,
113 comboItems: [
114 ['1', Proxmox.Utils.yesText],
115 ['0', Proxmox.Utils.noText],
116 ],
117 name: 'enable-new',
118 fieldLabel: gettext('Enable new'),
119 },
4b60ee19
DC
120 ],
121
122 columnB: [
3e43739f 123 {
a9faeb43
DC
124 xtype: 'fieldset',
125 title: gettext('Remove Vanished Options'),
126 items: [
127 {
128 xtype: 'proxmoxcheckbox',
129 fieldLabel: gettext('ACL'),
130 name: 'remove-vanished-acl',
131 boxLabel: gettext('Remove ACLs of vanished users and groups.'),
132 },
133 {
134 xtype: 'proxmoxcheckbox',
135 fieldLabel: gettext('Entry'),
136 name: 'remove-vanished-entry',
137 boxLabel: gettext('Remove vanished user and group entries.'),
138 },
139 {
140 xtype: 'proxmoxcheckbox',
141 fieldLabel: gettext('Properties'),
142 name: 'remove-vanished-properties',
2637f372 143 boxLabel: gettext('Remove vanished properties from synced users.'),
a9faeb43
DC
144 },
145 ],
3e43739f 146 },
4b60ee19
DC
147 {
148 xtype: 'displayfield',
149 reference: 'defaulthint',
150 value: gettext('Default sync options can be set by editing the realm.'),
151 userCls: 'pmx-hint',
f6710aac 152 hidden: true,
4b60ee19
DC
153 },
154 ],
155 }],
156 },
157 ],
158
159 buttons: [
47ea76b2
DC
160 {
161 xtype: 'proxmoxHelpButton',
162 reference: 'help_btn',
163 onlineHelp: 'pveum_ldap_sync',
164 hidden: false,
165 },
166 '->',
4b60ee19
DC
167 {
168 text: gettext('Preview'),
169 reference: 'preview_btn',
170 },
171 {
172 text: gettext('Sync'),
173 reference: 'sync_btn',
174 },
175 ],
176
177 initComponent: function() {
178 let me = this;
179
180 if (!me.realm) {
181 throw "no realm defined";
182 }
183
184 me.callParent();
185
186 Proxmox.Utils.API2Request({
187 url: `/access/domains/${me.realm}`,
188 waitMsgTarget: me,
189 method: 'GET',
190 failure: function(response) {
191 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
192 me.close();
193 },
194 success: function(response) {
195 let default_options = response.result.data['sync-defaults-options'];
196 if (default_options) {
197 let options = PVE.Parser.parsePropertyString(default_options);
3e43739f
DC
198 if (options['remove-vanished']) {
199 let opts = options['remove-vanished'].split(';');
200 for (const opt of opts) {
201 options[`remove-vanished-${opt}`] = 1;
202 }
203 }
4b60ee19
DC
204 let ipanel = me.lookup('ipanel');
205 ipanel.setValues(options);
206 } else {
207 me.lookup('defaulthint').setVisible(true);
208 }
209
210 // check validity for button state
211 me.lookup('form').isValid();
212 },
213 });
214 },
215});