modx.grid.user.online.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Loads a grid of all users who are online.
  3. *
  4. * @class MODx.grid.WhoIsOnline
  5. * @extends MODx.grid.Grid
  6. * @param {Object} config An object of options.
  7. * @xtype modx-grid-user-online
  8. */
  9. MODx.grid.WhoIsOnline = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config,{
  12. title: _('onlineusers_title')
  13. ,url: MODx.config.connector_url
  14. ,baseParams: {
  15. action: 'security/user/getonline'
  16. }
  17. ,autosave: false
  18. ,save_action: ''
  19. ,pageSize: 10
  20. ,fields: ['user','username','occurred','action']
  21. ,columns: [{
  22. header: _('onlineusers_userid')
  23. ,dataIndex: 'user'
  24. ,width: 80
  25. ,fixed: true
  26. },{
  27. header: _('onlineusers_user')
  28. ,dataIndex: 'username'
  29. },{
  30. header: _('onlineusers_lasthit')
  31. ,dataIndex: 'occurred'
  32. },{
  33. header: _('onlineusers_action')
  34. ,dataIndex: 'action'
  35. }]
  36. ,paging: true
  37. ,listeners: {
  38. afterrender: this.onAfterRender
  39. ,scope: this
  40. }
  41. });
  42. MODx.grid.WhoIsOnline.superclass.constructor.call(this,config);
  43. };
  44. Ext.extend(MODx.grid.WhoIsOnline,MODx.grid.Grid,{
  45. // Workaround to resize the grid when in a dashboard widget
  46. onAfterRender: function() {
  47. var cnt = Ext.getCmp('modx-content')
  48. // Dashboard widget "parent" (renderTo)
  49. ,parent = Ext.get('modx-grid-user-online');
  50. if (cnt && parent) {
  51. cnt.on('afterlayout', function(elem, layout) {
  52. var width = parent.getWidth();
  53. // Only resize when more than 500px (else let's use/enable the horizontal scrolling)
  54. if (width > 500) {
  55. this.setWidth(width);
  56. }
  57. }, this);
  58. }
  59. }
  60. });
  61. Ext.reg('modx-grid-user-online',MODx.grid.WhoIsOnline);