]> git.proxmox.com Git - proxmox-widget-toolkit.git/blame - src/window/AuthEditBase.js
window/AuthEditBase: handle differenc config api urls
[proxmox-widget-toolkit.git] / src / window / AuthEditBase.js
CommitLineData
6a504e19
DC
1Ext.define('Proxmox.window.AuthEditBase', {
2 extend: 'Proxmox.window.Edit',
3
4 isAdd: true,
5
6 fieldDefaults: {
7 labelWidth: 120,
8 },
9
335633d2
DC
10 baseurl: '/access/domains',
11 useTypeInUrl: false,
12
6a504e19
DC
13 initComponent: function() {
14 var me = this;
15
16 me.isCreate = !me.realm;
17
335633d2
DC
18 me.url = `/api2/extjs${me.baseUrl}`;
19 if (me.useTypeInUrl) {
20 me.url += `/${me.authType}`;
21 }
22
6a504e19 23 if (me.isCreate) {
6a504e19
DC
24 me.method = 'POST';
25 } else {
335633d2 26 me.url += `/${me.realm}`;
6a504e19
DC
27 me.method = 'PUT';
28 }
29
bc2b6fdd 30 let authConfig = Proxmox.Schema.authDomains[me.authType];
6a504e19
DC
31 if (!authConfig) {
32 throw 'unknown auth type';
33 } else if (!authConfig.add && me.isCreate) {
34 throw 'trying to add non addable realm';
35 }
36
37 me.subject = authConfig.name;
38
39 let items;
40 let bodyPadding;
41 if (authConfig.syncipanel) {
42 bodyPadding = 0;
43 items = {
44 xtype: 'tabpanel',
45 region: 'center',
46 layout: 'fit',
47 bodyPadding: 10,
48 items: [
49 {
50 title: gettext('General'),
51 realm: me.realm,
52 xtype: authConfig.ipanel,
53 isCreate: me.isCreate,
54 type: me.authType,
55 },
56 {
57 title: gettext('Sync Options'),
58 realm: me.realm,
59 xtype: authConfig.syncipanel,
60 isCreate: me.isCreate,
61 type: me.authType,
62 },
63 ],
64 };
65 } else {
66 items = [{
67 realm: me.realm,
68 xtype: authConfig.ipanel,
69 isCreate: me.isCreate,
70 type: me.authType,
71 }];
72 }
73
74 Ext.apply(me, {
75 items,
76 bodyPadding,
77 });
78
79 me.callParent();
80
81 if (!me.isCreate) {
82 me.load({
83 success: function(response, options) {
84 var data = response.result.data || {};
85 // just to be sure (should not happen)
335633d2
DC
86 // only check this when the type is not in the api path
87 if (!me.useTypeInUrl && data.type !== me.authType) {
6a504e19
DC
88 me.close();
89 throw "got wrong auth type";
90 }
91 me.setValues(data);
92 },
93 });
94 }
95 },
96});