[pbs-devel] [PATCH proxmox-backup 1/4] ui: add GroupSelector
Dominik Csapak
d.csapak at proxmox.com
Mon Nov 22 15:20:21 CET 2021
to select either a local or remote group from a datastore
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
www/Makefile | 1 +
www/form/GroupSelector.js | 83 +++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+)
create mode 100644 www/form/GroupSelector.js
diff --git a/www/Makefile b/www/Makefile
index 616c3e12..c975387c 100644
--- a/www/Makefile
+++ b/www/Makefile
@@ -42,6 +42,7 @@ JSSRC= \
form/DataStoreSelector.js \
form/CalendarEvent.js \
form/PermissionPathSelector.js \
+ form/GroupSelector.js \
data/RunningTasksStore.js \
button/TaskButton.js \
config/UserView.js \
diff --git a/www/form/GroupSelector.js b/www/form/GroupSelector.js
new file mode 100644
index 00000000..1e6c1bd4
--- /dev/null
+++ b/www/form/GroupSelector.js
@@ -0,0 +1,83 @@
+Ext.define('pbs-groups', {
+ extend: 'Ext.data.Model',
+ fields: [
+ 'backup-type',
+ 'backup-id',
+ {
+ name: 'group',
+ type: 'string',
+ convert: function(value, record) {
+ if (record.data['backup-type'] && record.data['backup-id']) {
+ return `${record.data['backup-type']}/${record.data['backup-id']}`;
+ }
+ return value;
+ },
+ },
+ ],
+ proxy: {
+ type: 'proxmox',
+ },
+});
+
+Ext.define('PBS.form.GroupSelector', {
+ extend: 'Proxmox.form.ComboGrid',
+ alias: 'widget.pbsGroupSelector',
+
+ allowBlank: false,
+ autoSelect: false,
+ notFoundIsValid: true,
+ editable: true,
+ valueField: 'group',
+ displayField: 'group',
+
+ reload: function() {
+ let me = this;
+ if (!me.isDisabled()) {
+ let value = me.getValue();
+ me.getStore().load({
+ callback: function() {
+ me.setValue(value);
+ },
+ });
+ }
+ },
+
+ setLocalDatastore: function(datastore) {
+ let me = this;
+ me.getStore().getProxy().setUrl(`/api2/json/admin/datastore/${datastore}/groups`);
+ me.reload();
+ },
+
+ setRemoteDatastore: function(remote, datastore) {
+ let me = this;
+ me.getStore().getProxy().setUrl(`/api2/json/config/remote/${remote}/scan/${datastore}/groups`);
+ me.reload();
+ },
+
+ store: {
+ sorters: 'group',
+ model: 'pbs-groups',
+ },
+
+ listConfig: {
+ columns: [
+ {
+ header: gettext('Group'),
+ sortable: true,
+ dataIndex: 'group',
+ renderer: Ext.String.htmlEncode,
+ flex: 1,
+ },
+ ],
+ },
+
+ initComponent: function() {
+ let me = this;
+ me.callParent();
+ if (me.remote && me.datastore) {
+ me.setRemoteDatastore(me.remote, me.datastore);
+ } else if (me.datastore) {
+ me.setLocalDatastore(me.datastore);
+ }
+ },
+});
--
2.30.2
More information about the pbs-devel
mailing list