]>
Commit | Line | Data |
---|---|---|
4b60ee19 DC |
1 | Ext.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(); | |
35 | params['dry-run'] = is_preview ? 1 : 0; | |
36 | Proxmox.Utils.API2Request({ | |
37 | url: `/access/domains/${view.realm}/sync`, | |
38 | waitMsgTarget: view, | |
39 | method: 'POST', | |
40 | params, | |
41 | failure: function(response) { | |
42 | view.show(); | |
43 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
44 | }, | |
45 | success: function(response) { | |
46 | view.hide(); | |
47 | Ext.create('Proxmox.window.TaskViewer', { | |
48 | upid: response.result.data, | |
49 | listeners: { | |
50 | destroy: function() { | |
51 | if (is_preview) { | |
52 | view.show(); | |
53 | } else { | |
54 | view.close(); | |
55 | } | |
56 | }, | |
57 | }, | |
58 | }).show(); | |
59 | }, | |
60 | }); | |
61 | }, | |
62 | }, | |
63 | ||
64 | items: [ | |
65 | { | |
66 | xtype: 'form', | |
67 | reference: 'form', | |
68 | border: false, | |
69 | fieldDefaults: { | |
70 | labelWidth: 100, | |
71 | anchor: '100%', | |
72 | }, | |
73 | items: [{ | |
74 | xtype: 'inputpanel', | |
75 | reference: 'ipanel', | |
76 | column1: [ | |
77 | { | |
78 | xtype: 'proxmoxKVComboBox', | |
79 | name: 'scope', | |
80 | fieldLabel: gettext('Scope'), | |
81 | value: '', | |
e5ede40a | 82 | emptyText: gettext('No default available'), |
4b60ee19 DC |
83 | deleteEmpty: false, |
84 | allowBlank: false, | |
85 | comboItems: [ | |
86 | ['users', gettext('Users')], | |
87 | ['groups', gettext('Groups')], | |
88 | ['both', gettext('Users and Groups')], | |
89 | ], | |
90 | }, | |
91 | { | |
92 | xtype: 'proxmoxKVComboBox', | |
93 | value: '', | |
e5ede40a | 94 | emptyText: gettext('No default available'), |
4b60ee19 DC |
95 | deleteEmpty: false, |
96 | allowBlank: false, | |
97 | comboItems: [ | |
98 | ['1', Proxmox.Utils.yesText], | |
99 | ['0', Proxmox.Utils.noText], | |
100 | ], | |
101 | name: 'full', | |
102 | fieldLabel: gettext('Full'), | |
103 | }, | |
104 | ], | |
105 | ||
106 | column2: [ | |
107 | { | |
108 | xtype: 'proxmoxKVComboBox', | |
109 | value: '1', | |
110 | deleteEmpty: false, | |
111 | allowBlank: false, | |
112 | comboItems: [ | |
113 | ['1', Proxmox.Utils.yesText], | |
114 | ['0', Proxmox.Utils.noText], | |
115 | ], | |
116 | name: 'enable-new', | |
117 | fieldLabel: gettext('Enable new'), | |
118 | }, | |
119 | { | |
120 | xtype: 'proxmoxKVComboBox', | |
121 | value: '', | |
e5ede40a | 122 | emptyText: gettext('No default available'), |
4b60ee19 DC |
123 | deleteEmpty: false, |
124 | allowBlank: false, | |
125 | comboItems: [ | |
126 | ['1', Proxmox.Utils.yesText], | |
127 | ['0', Proxmox.Utils.noText], | |
128 | ], | |
129 | name: 'purge', | |
e5ede40a | 130 | fieldLabel: gettext('Purge ACLs'), |
4b60ee19 DC |
131 | }, |
132 | ], | |
133 | ||
134 | columnB: [ | |
135 | { | |
136 | xtype: 'displayfield', | |
137 | reference: 'defaulthint', | |
138 | value: gettext('Default sync options can be set by editing the realm.'), | |
139 | userCls: 'pmx-hint', | |
f6710aac | 140 | hidden: true, |
4b60ee19 DC |
141 | }, |
142 | ], | |
143 | }], | |
144 | }, | |
145 | ], | |
146 | ||
147 | buttons: [ | |
47ea76b2 DC |
148 | { |
149 | xtype: 'proxmoxHelpButton', | |
150 | reference: 'help_btn', | |
151 | onlineHelp: 'pveum_ldap_sync', | |
152 | hidden: false, | |
153 | }, | |
154 | '->', | |
4b60ee19 DC |
155 | { |
156 | text: gettext('Preview'), | |
157 | reference: 'preview_btn', | |
158 | }, | |
159 | { | |
160 | text: gettext('Sync'), | |
161 | reference: 'sync_btn', | |
162 | }, | |
163 | ], | |
164 | ||
165 | initComponent: function() { | |
166 | let me = this; | |
167 | ||
168 | if (!me.realm) { | |
169 | throw "no realm defined"; | |
170 | } | |
171 | ||
172 | me.callParent(); | |
173 | ||
174 | Proxmox.Utils.API2Request({ | |
175 | url: `/access/domains/${me.realm}`, | |
176 | waitMsgTarget: me, | |
177 | method: 'GET', | |
178 | failure: function(response) { | |
179 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
180 | me.close(); | |
181 | }, | |
182 | success: function(response) { | |
183 | let default_options = response.result.data['sync-defaults-options']; | |
184 | if (default_options) { | |
185 | let options = PVE.Parser.parsePropertyString(default_options); | |
186 | let ipanel = me.lookup('ipanel'); | |
187 | ipanel.setValues(options); | |
188 | } else { | |
189 | me.lookup('defaulthint').setVisible(true); | |
190 | } | |
191 | ||
192 | // check validity for button state | |
193 | me.lookup('form').isValid(); | |
194 | }, | |
195 | }); | |
196 | }, | |
197 | }); |