From 6d3da7ce9850111f2836ef5246e4d9901bf19e2b Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 16 Nov 2011 18:44:49 +0100 Subject: [PATCH] implement new history method for groupPanel --- .../resources/js/group/sonia.group.grid.js | 10 ++++ .../resources/js/group/sonia.group.panel.js | 51 +++++++++++++++++-- .../js/repository/sonia.repository.panel.js | 2 +- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/group/sonia.group.grid.js b/scm-webapp/src/main/webapp/resources/js/group/sonia.group.grid.js index 7666e49f71..7ed4599e6b 100644 --- a/scm-webapp/src/main/webapp/resources/js/group/sonia.group.grid.js +++ b/scm-webapp/src/main/webapp/resources/js/group/sonia.group.grid.js @@ -38,6 +38,9 @@ Sonia.group.Grid = Ext.extend(Sonia.rest.Grid, { colTypeText: 'Type', emptyGroupStoreText: 'No group is configured', groupFormTitleText: 'Group Form', + + // parent panel for history + parentPanel: null, initComponent: function(){ var groupStore = new Sonia.rest.JsonStore({ @@ -82,6 +85,9 @@ Sonia.group.Grid = Ext.extend(Sonia.rest.Grid, { Ext.apply(this, Ext.apply(this.initialConfig, config)); Sonia.group.Grid.superclass.initComponent.apply(this, arguments); + + // store grid in parent panel + this.parentPanel.groupGrid = this; }, @@ -115,6 +121,10 @@ Sonia.group.Grid = Ext.extend(Sonia.rest.Grid, { if ( debug ){ console.debug( group.name + ' selected' ); } + + if (this.parentPanel){ + this.parentPanel.updateHistory(group); + } Ext.getCmp('groupRmButton').setDisabled(false); Sonia.group.setEditPanel([{ diff --git a/scm-webapp/src/main/webapp/resources/js/group/sonia.group.panel.js b/scm-webapp/src/main/webapp/resources/js/group/sonia.group.panel.js index a529f81a4f..83b1eec369 100644 --- a/scm-webapp/src/main/webapp/resources/js/group/sonia.group.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/group/sonia.group.panel.js @@ -37,6 +37,9 @@ Sonia.group.Panel = Ext.extend(Sonia.rest.Panel, { removeMsgText: 'Remove Group "{0}"?', errorTitleText: 'Error', errorMsgText: 'Group deletion failed', + + // grid + groupGrid: null, initComponent: function(){ var config = { @@ -49,7 +52,8 @@ Sonia.group.Panel = Ext.extend(Sonia.rest.Panel, { items: [{ id: 'groupGrid', xtype: 'groupGrid', - region: 'center' + region: 'center', + parentPanel: this }, { id: 'groupEditPanel', xtype: 'tabpanel', @@ -71,9 +75,24 @@ Sonia.group.Panel = Ext.extend(Sonia.rest.Panel, { Ext.apply(this, Ext.apply(this.initialConfig, config)); Sonia.group.Panel.superclass.initComponent.apply(this, arguments); }, + + getGrid: function(){ + if (!this.groupGrid){ + if (debug){ + console.debug('could not find group grid, fetch by id'); + } + this.groupGrid = Ext.getCmp('groupGrid'); + } + return this.groupGrid; + }, + + updateHistory: function(group){ + var token = Sonia.History.createToken(['groupPanel', group.name]); + Sonia.History.add(token); + }, removeGroup: function(){ - var grid = Ext.getCmp('groupGrid'); + var grid = this.getGrid(); var selected = grid.getSelectionModel().getSelected(); if ( selected ){ var item = selected.data; @@ -140,10 +159,36 @@ Sonia.group.Panel = Ext.extend(Sonia.rest.Panel, { }, reload: function(){ - Ext.getCmp('groupGrid').reload(); + this.getGrid().reload(); } }); // register xtype Ext.reg('groupPanel', Sonia.group.Panel); + +// register history handler +Sonia.History.register('groupPanel', { + + onActivate: function(panel){ + var token = null; + var rec = panel.getGrid().getSelectionModel().getSelected(); + if ( rec != null ){ + token = Sonia.History.createToken('groupPanel', rec.get('name')); + } else { + token = Sonia.History.createToken('groupPanel'); + } + return token; + }, + + onChange: function(repoId){ + var panel = Ext.getCmp('groups'); + if ( ! panel ){ + main.addGroupsTabPanel(); + panel = Ext.getCmp('groups'); + } + if (repoId){ + panel.getGrid().selectById(repoId); + } + } +}); \ No newline at end of file diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js index cd74ba3bba..54d186b139 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js @@ -300,4 +300,4 @@ Sonia.History.register('repositoryPanel', { panel.getGrid().selectById(repoId); } } -}) \ No newline at end of file +}); \ No newline at end of file