[pve-devel] help with ExtJS4

Seth Lauzon seth.lauzon at gmail.com
Tue Jun 28 22:57:23 CEST 2011


I need to get the userid from the selected record in the User List.  Can anyone help?

Ext.define('PVE.dc.UserView', {
    extend: 'Ext.grid.GridPanel',

    alias: ['widget.pveUserView'],

    initComponent : function() {
	var me = this;

        var tbar = [
          {
            text: 'Add',
            handler: function() {
              var msg = 'This feature is not implemented yet!';
              Ext.Msg.alert('Not Implemented', msg);
            }
          },
          {
            text: 'Modify',
            handler: function() {
              var msg = 'This feature is not implemented yet!';
              Ext.Msg.alert('Not Implemented', msg);
            }
          },
          {
            text: 'Delete',
            handler: function() {
              var msg = 'Are you sure you want to permanently delete the user: ' + me.getSelectionModel.getSelection()[0];
              Ext.Msg.confirm('Deletion Confirmation', msg, function(btn) {
              if (btn !== 'yes')
                  return;
              Ext.Msg.alert('Not Implemented', 'This feature is not implemented yet!');
              });
            }
          },
        ];

	var store = new Ext.data.Store({
	    model: 'pve-users',
	    proxy: {
                type: 'pve',
		url: "/api2/json/access/users"
	    },
	    sorters: { 
		property: 'userid', 
		order: 'DESC' 
	    }
	});

	var render_expire = function(date) {
	    if (!date)
		return 'never';

	    return Ext.Date.format(date, "Y-m-d");
	};

	var render_full_name = function(firstname, metaData, record) {

	    var first = firstname || '';
	    var last = record.data.lastname || '';
	    return first + " " + last;
	};

	var render_username = function(userid) {
	    return userid.match(/^([^@]+)/)[1];
	};

	var render_realm = function(userid) {
	    return userid.match(/@([^@]+)$/)[1];
	};

	Ext.apply(me, {
	    store: store,
            tbar: tbar,
	    columns: [
		{
		    header: 'User name',
		    width: 200,
		    sortable: true,
		    renderer: render_username,
		    dataIndex: 'userid'
		},
		{
		    header: 'Realm',
		    width: 100,
		    sortable: true,
		    renderer: render_realm,
		    dataIndex: 'userid'
		},
		{
		    header: 'Enabled',
		    width: 80,
		    sortable: true,
		    dataIndex: 'enabled'
		},
		{
		    header: 'Expire',
		    width: 80,
		    sortable: true,
		    renderer: render_expire, 
		    dataIndex: 'expire'
		},
		{
		    header: 'Name',
		    width: 150,
		    sortable: true,
		    renderer: render_full_name,
		    dataIndex: 'firstname'
		},
		{
		    id: 'comment',
		    header: 'Comment',
		    sortable: false,
		    dataIndex: 'comment',
		    flex: 1
		}
	    ],
	    listeners: {
		show: function() {
		    store.load();
		}
	    }
	});

	me.callParent();
    }
}, function() {

    Ext.define('pve-users', {
	extend: 'Ext.data.Model',
	fields: [ 
	    'userid', 'firstname', 'lastname' , 'email', 'comment',
	    { type: 'boolean', name: 'enabled' }, 
	    { type: 'date', dateFormat: 'timestamp', name: 'expire' },
	],
	idProperty: 'userid'
    });




More information about the pve-devel mailing list