]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/panel/AuthView.js
language selector: increase only picker list view
[proxmox-widget-toolkit.git] / src / panel / AuthView.js
1 Ext.define('Proxmox.panel.AuthView', {
2 extend: 'Ext.grid.GridPanel',
3
4 alias: 'widget.pmxAuthView',
5
6 stateful: true,
7 stateId: 'grid-authrealms',
8
9 viewConfig: {
10 trackOver: false,
11 },
12
13 baseUrl: '/access/domains',
14 useTypeInUrl: false,
15
16 columns: [
17 {
18 header: gettext('Realm'),
19 width: 100,
20 sortable: true,
21 dataIndex: 'realm',
22 },
23 {
24 header: gettext('Type'),
25 width: 100,
26 sortable: true,
27 dataIndex: 'type',
28 },
29 {
30 header: gettext('Comment'),
31 sortable: false,
32 dataIndex: 'comment',
33 renderer: Ext.String.htmlEncode,
34 flex: 1,
35 },
36 ],
37
38 store: {
39 model: 'pmx-domains',
40 sorters: {
41 property: 'realm',
42 direction: 'ASC',
43 },
44 },
45
46 openEditWindow: function(authType, realm) {
47 let me = this;
48 Ext.create('Proxmox.window.AuthEditBase', {
49 baseUrl: me.baseUrl,
50 useTypeInUrl: me.useTypeInUrl,
51 authType,
52 realm,
53 listeners: {
54 destroy: () => me.reload(),
55 },
56 }).show();
57 },
58
59 reload: function() {
60 let me = this;
61 me.getStore().load();
62 },
63
64 run_editor: function() {
65 let me = this;
66 let rec = me.getSelection()[0];
67 if (!rec) {
68 return;
69 }
70
71 if (!Proxmox.Schema.authDomains[rec.data.type].edit) {
72 return;
73 }
74
75 me.openEditWindow(rec.data.type, rec.data.realm);
76 },
77
78 open_sync_window: function() {
79 let rec = this.getSelection()[0];
80 if (!rec) {
81 return;
82 }
83 if (!Proxmox.Schema.authDomains[rec.data.type].sync) {
84 return;
85 }
86 Ext.create('Proxmox.window.SyncWindow', {
87 type: rec.data.type,
88 realm: rec.data.realm,
89 listeners: {
90 destroy: () => this.reload(),
91 },
92 }).show();
93 },
94
95 initComponent: function() {
96 var me = this;
97
98 let menuitems = [];
99 for (const [authType, config] of Object.entries(Proxmox.Schema.authDomains).sort()) {
100 if (!config.add) { continue; }
101 menuitems.push({
102 text: config.name,
103 iconCls: 'fa fa-fw ' + (config.iconCls || 'fa-address-book-o'),
104 handler: () => me.openEditWindow(authType),
105 });
106 }
107
108 let tbar = [
109 {
110 text: gettext('Add'),
111 menu: {
112 items: menuitems,
113 },
114 },
115 {
116 xtype: 'proxmoxButton',
117 text: gettext('Edit'),
118 disabled: true,
119 enableFn: (rec) => Proxmox.Schema.authDomains[rec.data.type].edit,
120 handler: () => me.run_editor(),
121 },
122 {
123 xtype: 'proxmoxStdRemoveButton',
124 getUrl: (rec) => {
125 let url = me.baseUrl;
126 if (me.useTypeInUrl) {
127 url += `/${rec.get('type')}`;
128 }
129 url += `/${rec.getId()}`;
130 return url;
131 },
132 enableFn: (rec) => Proxmox.Schema.authDomains[rec.data.type].add,
133 callback: () => me.reload(),
134 },
135 {
136 xtype: 'proxmoxButton',
137 text: gettext('Sync'),
138 disabled: true,
139 enableFn: (rec) => Proxmox.Schema.authDomains[rec.data.type].sync,
140 handler: () => me.open_sync_window(),
141 },
142 ];
143
144 if (me.extraButtons) {
145 tbar.push('-');
146 for (const button of me.extraButtons) {
147 tbar.push(button);
148 }
149 }
150
151 Ext.apply(me, {
152 tbar,
153 listeners: {
154 activate: () => me.reload(),
155 itemdblclick: () => me.run_editor(),
156 },
157 });
158
159 me.callParent();
160 },
161 });