]>
Commit | Line | Data |
---|---|---|
c1594495 DC |
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 | ||
8d4faa88 DC |
13 | baseUrl: '/access/domains', |
14 | useTypeInUrl: false, | |
15 | ||
c1594495 DC |
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', | |
1025802e | 42 | direction: 'ASC', |
c1594495 DC |
43 | }, |
44 | }, | |
45 | ||
46 | openEditWindow: function(authType, realm) { | |
47 | let me = this; | |
48 | Ext.create('Proxmox.window.AuthEditBase', { | |
8d4faa88 DC |
49 | baseUrl: me.baseUrl, |
50 | useTypeInUrl: me.useTypeInUrl, | |
c1594495 DC |
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 | ||
770b2612 | 71 | if (!Proxmox.Schema.authDomains[rec.data.type].edit) { |
c1594495 DC |
72 | return; |
73 | } | |
74 | ||
75 | me.openEditWindow(rec.data.type, rec.data.realm); | |
76 | }, | |
77 | ||
78 | initComponent: function() { | |
79 | var me = this; | |
80 | ||
81 | let menuitems = []; | |
770b2612 | 82 | for (const [authType, config] of Object.entries(Proxmox.Schema.authDomains).sort()) { |
c1594495 DC |
83 | if (!config.add) { continue; } |
84 | menuitems.push({ | |
85 | text: config.name, | |
86 | iconCls: 'fa fa-fw ' + (config.iconCls || 'fa-address-book-o'), | |
87 | handler: () => me.openEditWindow(authType), | |
88 | }); | |
89 | } | |
90 | ||
91 | let tbar = [ | |
92 | { | |
93 | text: gettext('Add'), | |
94 | menu: { | |
95 | items: menuitems, | |
96 | }, | |
97 | }, | |
98 | { | |
99 | xtype: 'proxmoxButton', | |
100 | text: gettext('Edit'), | |
101 | disabled: true, | |
770b2612 | 102 | enableFn: (rec) => Proxmox.Schema.authDomains[rec.data.type].edit, |
c1594495 DC |
103 | handler: () => me.run_editor(), |
104 | }, | |
105 | { | |
106 | xtype: 'proxmoxStdRemoveButton', | |
8d4faa88 DC |
107 | getUrl: (rec) => { |
108 | let url = me.baseUrl; | |
109 | if (me.useTypeInUrl) { | |
110 | url += `/${rec.get('type')}`; | |
111 | } | |
112 | url += `/${rec.getId()}`; | |
113 | return url; | |
114 | }, | |
770b2612 | 115 | enableFn: (rec) => Proxmox.Schema.authDomains[rec.data.type].add, |
c1594495 DC |
116 | callback: () => me.reload(), |
117 | }, | |
118 | ]; | |
119 | ||
120 | if (me.extraButtons) { | |
121 | tbar.push('-'); | |
122 | for (const button of me.extraButtons) { | |
123 | tbar.push(button); | |
124 | } | |
125 | } | |
126 | ||
127 | Ext.apply(me, { | |
128 | tbar, | |
129 | listeners: { | |
130 | activate: () => me.reload(), | |
131 | itemdblclick: () => me.run_editor(), | |
132 | }, | |
133 | }); | |
134 | ||
135 | me.callParent(); | |
136 | }, | |
137 | }); |