From 1ec8771064e01b22db52c5017871d05d0f695a9d Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 19 Nov 2011 16:39:10 +0100 Subject: [PATCH] added history functions for user panel --- .../resources/js/user/sonia.user.grid.js | 7 +++ .../resources/js/user/sonia.user.panel.js | 47 ++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.grid.js b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.grid.js index 69f78adb84..506d0d60a7 100644 --- a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.grid.js +++ b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.grid.js @@ -40,6 +40,9 @@ Sonia.user.Grid = Ext.extend(Sonia.rest.Grid, { colCreationDateText: 'Creation Date', colLastModifiedText: 'Last modified', colTypeText: 'Type', + + // parent for history + parentPanel: null, initComponent: function(){ @@ -85,6 +88,10 @@ Sonia.user.Grid = Ext.extend(Sonia.rest.Grid, { Ext.apply(this, Ext.apply(this.initialConfig, config)); Sonia.user.Grid.superclass.initComponent.apply(this, arguments); + + if (this.parentPanel){ + this.parentPanel.userGrid = this; + } }, onFallBelowMinHeight: function(height, minHeight){ diff --git a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js index 5716792c32..3af0e05f57 100644 --- a/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/user/sonia.user.panel.js @@ -37,6 +37,9 @@ Sonia.user.Panel = Ext.extend(Sonia.rest.Panel, { removeMsgText: 'Remove User "{0}"?', errorTitleText: 'Error', errorMsgText: 'User deletion failed', + + // userGrid for history + userGrid: null, initComponent: function(){ @@ -51,7 +54,8 @@ Sonia.user.Panel = Ext.extend(Sonia.rest.Panel, { items: [{ id: 'userGrid', xtype: 'userGrid', - region: 'center' + region: 'center', + parentPanel: this },{ id: 'userEditPanel', layout: 'fit', @@ -72,6 +76,16 @@ Sonia.user.Panel = Ext.extend(Sonia.rest.Panel, { Ext.apply(this, Ext.apply(this.initialConfig, config)); Sonia.user.Panel.superclass.initComponent.apply(this, arguments); }, + + getGrid: function(){ + if (!this.userGrid){ + if (debug){ + console.debug('userGrid not found retrvie by id'); + } + this.userGrid = Ext.getCmp('userGrid'); + } + return this.userGrid; + }, showAddPanel: function(){ var editPanel = Ext.getCmp('userEditPanel'); @@ -99,7 +113,7 @@ Sonia.user.Panel = Ext.extend(Sonia.rest.Panel, { removeUser: function(){ - var grid = Ext.getCmp('userGrid'); + var grid = this.getGrid(); var selected = grid.getSelectionModel().getSelected(); if ( selected ){ var item = selected.data; @@ -153,3 +167,32 @@ Sonia.user.Panel = Ext.extend(Sonia.rest.Panel, { // register xtype Ext.reg('userPanel', Sonia.user.Panel); + + +// register history handler +Sonia.History.register('userPanel', { + + onActivate: function(panel){ + var token = null; + var rec = panel.getGrid().getSelectionModel().getSelected(); + if (rec){ + token = Sonia.History.createToken('userPanel', rec.get('name')); + } else { + token = Sonia.History.createToken('userPanel'); + } + return token; + }, + + onChange: function(userId){ + var panel = Ext.getCmp('users'); + if ( ! panel ){ + main.addUsersTabPanel(); + panel = Ext.getCmp('users'); + } else { + main.addTab(panel); + } + if (userId){ + panel.getGrid().selectById(userId); + } + } +}); \ No newline at end of file