]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
object grid: allow one to declaratively specify rows
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 21 May 2021 14:39:23 +0000 (16:39 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 21 May 2021 15:15:03 +0000 (17:15 +0200)
So that users of this component do not necesacrrily need to add an
initComponent override and make the `me.add_XYZ_row()` there, but
instead can use something like:

  gridRows: [
    {
      xtype: 'text',
      name: 'http-proxy',
      text: gettext('HTTP proxy'),
      defaultValue: Proxmox.Utils.noneText,
      vtype: 'HttpProxy',
      deleteEmpty: true,
    },
  ],

I avoid using `rows` as config key as that is internally used for
quite a few things, and potentially some existing users (did not
checked all). We can still switch to that easily if it is deemed to
be better...

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/grid/ObjectGrid.js

index 425d3c2dcbe759758c527e0270bd9751bf606fae..c323a6b978f48f337323ab22e3eae324ee4b1cbd 100644 (file)
@@ -19,6 +19,11 @@ Useful for a readonly tabular display
 Ext.define('Proxmox.grid.ObjectGrid', {
     extend: 'Ext.grid.GridPanel',
     alias: ['widget.proxmoxObjectGrid'],
+
+    // can be used as declarative replacement over manually calling the add_XYZ_row helpers,
+    // see top-level doc-comment above for details/example
+    gridRows: [],
+
     disabled: false,
     hideHeaders: true,
 
@@ -246,6 +251,17 @@ Ext.define('Proxmox.grid.ObjectGrid', {
     initComponent: function() {
        let me = this;
 
+       for (const rowdef of me.gridRows || []) {
+           let addFn = me[`add_${rowdef.xtype}_row`];
+           if (typeof addFn !== 'function') {
+               throw `unknown object-grid row xtype '${rowdef.xtype}'`;
+           } else if (typeof rowdef.name !== 'string') {
+               throw `object-grid row need a valid name string-property!`;
+           } else {
+               addFn.call(me, rowdef.name, rowdef.text || rowdef.name, rowdef);
+           }
+       }
+
        let rows = me.rows;
 
        if (!me.rstore) {