select new repository after creation

This commit is contained in:
Sebastian Sdorra
2011-09-05 12:23:59 +02:00
parent f81ab4f5d1
commit c64d47d0a5
3 changed files with 49 additions and 12 deletions

View File

@@ -100,6 +100,16 @@ Sonia.repository.FormPanel = Ext.extend(Sonia.rest.FormPanel,{
});
},
getIdFromResponse: function(response){
var id = null;
var location = response.getResponseHeader('Location')
if (location){
var parts = location.split('/');
id = parts[parts.length - 1];
}
return id;
},
create: function(item){
if ( debug ){
console.debug( 'create repository: ' + item.name );
@@ -115,10 +125,16 @@ Sonia.repository.FormPanel = Ext.extend(Sonia.rest.FormPanel,{
jsonData: item,
method: 'POST',
scope: this,
success: function(){
success: function(response){
if ( debug ){
console.debug('create success');
}
var id = this.getIdFromResponse(response);
if (id){
item.id = id;
}
this.fireEvent('created', item);
this.getForm().reset();
clearTimeout(tid);

View File

@@ -220,23 +220,35 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, {
scope: this
},
created: {
fn: this.clearRepositoryFilter,
fn: this.repositoryCreated,
scope: this
}
}
}]);
},
clearRepositoryFilter: function(){
repositoryCreated: function(item){
var grid = Ext.getCmp('repositoryGrid');
this.clearRepositoryFilter(grid);
grid.reload(function(){
if (debug){
console.debug('select repository ' + item.id + " after creation");
}
grid.selectById(item.id);
});
},
clearRepositoryFilter: function(grid){
if (debug){
console.debug('clear repository filter');
}
if (! grid ){
grid = Ext.getCmp('repositoryGrid');
}
Ext.getCmp('repositorySearch').setValue('');
Ext.getCmp('repositoryTypeFilter').setValue('');
var grid = Ext.getCmp('repositoryGrid');
grid.clearStoreFilter();
grid.reload();
},
reload: function(){

View File

@@ -87,11 +87,14 @@ Sonia.rest.Grid = Ext.extend(Ext.grid.GridPanel, {
Sonia.rest.Grid.superclass.onDestroy.apply(this, arguments);
},
reload: function(){
reload: function(callback, scope){
if ( debug ){
console.debug('reload store');
}
this.store.load();
this.store.load({
callback: callback,
scope: scope
});
},
selectionChanged: function(sm){
@@ -131,12 +134,18 @@ Sonia.rest.Grid = Ext.extend(Ext.grid.GridPanel, {
return String.format( this.checkboxTemplate, param );
},
selectById: function(id){
var index = this.getStore().indexOfId(id);
if ( index >= 0 ){
this.getSelectionModel().selectRow(index);
} else if (debug) {
console.debug('could not find item with id ' + id);
}
},
handleHistory: function(params){
if (params && params.length > 0){
var index = this.getStore().indexOfId(params[0]);
if ( index >= 0 ){
this.getSelectionModel().selectRow(index);
}
this.selectById(params[0])
} else {
if (debug){
console.debug( 'clear selection' );