]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
add panel/AuthView from PVE
authorDominik Csapak <d.csapak@proxmox.com>
Fri, 9 Jul 2021 11:42:23 +0000 (13:42 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 9 Jul 2021 12:46:27 +0000 (14:46 +0200)
added the following (necessary) changes:
* use Proxmox.Utils.authSchema
* omit the sync button/handler, but add a possibilty to add extra buttons
* check for an 'edit' property in the authSchema for enabling editing
* removed the onlineHelp property
* removed 'TFA' column (can be added by the caller)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/Makefile
src/panel/AuthView.js [new file with mode: 0644]

index 903879e8b0af81c4054c3c08b04369d732685625..0f094c6308931637f71088f04bcfb7574c4657bc 100644 (file)
@@ -45,6 +45,7 @@ JSSRC=                                        \
        button/HelpButton.js            \
        grid/ObjectGrid.js              \
        grid/PendingObjectGrid.js       \
+       panel/AuthView.js               \
        panel/DiskList.js               \
        panel/InputPanel.js             \
        panel/InfoWidget.js             \
diff --git a/src/panel/AuthView.js b/src/panel/AuthView.js
new file mode 100644 (file)
index 0000000..c9b52e0
--- /dev/null
@@ -0,0 +1,125 @@
+Ext.define('Proxmox.panel.AuthView', {
+    extend: 'Ext.grid.GridPanel',
+
+    alias: 'widget.pmxAuthView',
+
+    stateful: true,
+    stateId: 'grid-authrealms',
+
+    viewConfig: {
+       trackOver: false,
+    },
+
+    columns: [
+       {
+           header: gettext('Realm'),
+           width: 100,
+           sortable: true,
+           dataIndex: 'realm',
+       },
+       {
+           header: gettext('Type'),
+           width: 100,
+           sortable: true,
+           dataIndex: 'type',
+       },
+       {
+           header: gettext('Comment'),
+           sortable: false,
+           dataIndex: 'comment',
+           renderer: Ext.String.htmlEncode,
+           flex: 1,
+       },
+    ],
+
+    store: {
+       model: 'pmx-domains',
+       sorters: {
+           property: 'realm',
+           order: 'DESC',
+       },
+    },
+
+    openEditWindow: function(authType, realm) {
+       let me = this;
+       Ext.create('Proxmox.window.AuthEditBase', {
+           authType,
+           realm,
+           listeners: {
+               destroy: () => me.reload(),
+           },
+       }).show();
+    },
+
+    reload: function() {
+       let me = this;
+       me.getStore().load();
+    },
+
+    run_editor: function() {
+       let me = this;
+       let rec = me.getSelection()[0];
+       if (!rec) {
+           return;
+       }
+
+       if (!Proxmox.Utils.authSchema[rec.data.type].edit) {
+           return;
+       }
+
+       me.openEditWindow(rec.data.type, rec.data.realm);
+    },
+
+    initComponent: function() {
+       var me = this;
+
+       let menuitems = [];
+       for (const [authType, config] of Object.entries(Proxmox.Utils.authSchema).sort()) {
+           if (!config.add) { continue; }
+           menuitems.push({
+               text: config.name,
+               iconCls: 'fa fa-fw ' + (config.iconCls || 'fa-address-book-o'),
+               handler: () => me.openEditWindow(authType),
+           });
+       }
+
+       let tbar = [
+           {
+               text: gettext('Add'),
+               menu: {
+                   items: menuitems,
+               },
+           },
+           {
+               xtype: 'proxmoxButton',
+               text: gettext('Edit'),
+               disabled: true,
+               enableFn: (rec) => Proxmox.Utils.authSchema[rec.data.type].edit,
+               handler: () => me.run_editor(),
+           },
+           {
+               xtype: 'proxmoxStdRemoveButton',
+               baseurl: '/access/domains/',
+               enableFn: (rec) => Proxmox.Utils.authSchema[rec.data.type].add,
+               callback: () => me.reload(),
+           },
+       ];
+
+       if (me.extraButtons) {
+           tbar.push('-');
+           for (const button of me.extraButtons) {
+               tbar.push(button);
+           }
+       }
+
+       Ext.apply(me, {
+           tbar,
+           listeners: {
+               activate: () => me.reload(),
+               itemdblclick: () => me.run_editor(),
+           },
+       });
+
+       me.callParent();
+    },
+});