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