added sonia.rest.Grid

This commit is contained in:
Sebastian Sdorra
2010-11-08 20:10:20 +01:00
parent 0fd3f15125
commit f041ae4bb0
3 changed files with 89 additions and 105 deletions

View File

@@ -46,24 +46,10 @@ Ext.ns('Sonia.repository');
// RepositoryGrid // RepositoryGrid
Sonia.repository.Grid = Ext.extend(Ext.grid.GridPanel, { Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
urlTemplate: '<a href="{0}" target="_blank">{0}</a>',
mailtoTemplate: '<a href="mailto: {0}">{0}</a>',
initComponent: function(){ initComponent: function(){
var selectionModel = new Ext.grid.RowSelectionModel({
singleSelect: true
});
selectionModel.on({
selectionchange: {
scope: this,
fn: this.selectionChanged
}
});
var repositoryStore = new Sonia.rest.JsonStore({ var repositoryStore = new Sonia.rest.JsonStore({
url: restUrl + 'repositories.json', url: restUrl + 'repositories.json',
root: 'repositories', root: 'repositories',
@@ -90,35 +76,18 @@ Sonia.repository.Grid = Ext.extend(Ext.grid.GridPanel, {
}); });
var config = { var config = {
loadMask: true,
autoExpandColumn: 'description', autoExpandColumn: 'description',
store: repositoryStore, store: repositoryStore,
colModel: repositoryColModel, colModel: repositoryColModel
sm: selectionModel
}; };
Ext.apply(this, Ext.apply(this.initialConfig, config)); Ext.apply(this, Ext.apply(this.initialConfig, config));
Sonia.repository.Grid.superclass.initComponent.apply(this, arguments); Sonia.repository.Grid.superclass.initComponent.apply(this, arguments);
// load data
if ( debug ){
console.debug( 'load repository list' );
}
repositoryStore.load();
}, },
reload: function(){ selectItem: function(item){
if ( debug ){ if ( debug ){
console.debug('reload store'); console.debug( item.name + ' selected' );
}
this.store.load();
},
selectionChanged: function(sm){
var selected = sm.getSelected();
if ( selected ){
if ( debug ){
console.debug( selected.data.name + ' selected' );
} }
var editPanel = Ext.getCmp('repositoryEditPanel'); var editPanel = Ext.getCmp('repositoryEditPanel');
editPanel.removeAll(); editPanel.removeAll();
@@ -138,24 +107,14 @@ Sonia.repository.Grid = Ext.extend(Ext.grid.GridPanel, {
}); });
editPanel.add(panel); editPanel.add(panel);
editPanel.doLayout(); editPanel.doLayout();
}
}, },
renderRepositoryType: function(repositoryType){ renderRepositoryType: function(repositoryType){
return repositoryTypeStore.queryBy(function(rec){ return repositoryTypeStore.queryBy(function(rec){
return rec.data.name == repositoryType; return rec.data.name == repositoryType;
}).itemAt(0).data.displayName; }).itemAt(0).data.displayName;
},
renderUrl: function(url){
return String.format( this.urlTemplate, url );
},
renderMailto: function(mail){
return String.format( this.mailtoTemplate, mail );
} }
}); });
// register xtype // register xtype

View File

@@ -58,3 +58,65 @@ Sonia.rest.JsonStore = Ext.extend( Ext.data.JsonStore, {
} }
}); });
Sonia.rest.Grid = Ext.extend(Ext.grid.GridPanel, {
urlTemplate: '<a href="{0}" target="_blank">{0}</a>',
mailtoTemplate: '<a href="mailto: {0}">{0}</a>',
initComponent: function(){
var selectionModel = new Ext.grid.RowSelectionModel({
singleSelect: true
});
selectionModel.on({
selectionchange: {
scope: this,
fn: this.selectionChanged
}
});
var config = {
loadMask: true,
sm: selectionModel
};
Ext.apply(this, Ext.apply(this.initialConfig, config));
Sonia.rest.Grid.superclass.initComponent.apply(this, arguments);
// load store
if ( debug ){
console.debug( 'load store' );
}
this.store.load();
},
reload: function(){
if ( debug ){
console.debug('reload store');
}
this.store.load();
},
selectionChanged: function(sm){
var selected = sm.getSelected();
if ( selected ){
this.selectItem( selected.data );
}
},
selectItem: function(item){
},
renderUrl: function(url){
return String.format( this.urlTemplate, url );
},
renderMailto: function(mail){
return String.format( this.mailtoTemplate, mail );
}
});

View File

@@ -33,23 +33,10 @@
Ext.ns('Sonia.user'); Ext.ns('Sonia.user');
// UserGrid // UserGrid
Sonia.user.Grid = Ext.extend(Ext.grid.GridPanel, { Sonia.user.Grid = Ext.extend(Sonia.rest.Grid, {
mailtoTemplate: '<a href="mailto: {0}">{0}</a>',
initComponent: function(){ initComponent: function(){
var selectionModel = new Ext.grid.RowSelectionModel({
singleSelect: true
});
selectionModel.on({
selectionchange: {
scope: this,
fn: this.selectionChanged
}
});
var userStore = new Sonia.rest.JsonStore({ var userStore = new Sonia.rest.JsonStore({
url: restUrl + 'users.json', url: restUrl + 'users.json',
root: 'users', root: 'users',
@@ -74,40 +61,16 @@ Sonia.user.Grid = Ext.extend(Ext.grid.GridPanel, {
}); });
var config = { var config = {
loadMask: true,
store: userStore, store: userStore,
colModel: userColModel, colModel: userColModel
sm: selectionModel
}; };
Ext.apply(this, Ext.apply(this.initialConfig, config)); Ext.apply(this, Ext.apply(this.initialConfig, config));
Sonia.user.Grid.superclass.initComponent.apply(this, arguments); Sonia.user.Grid.superclass.initComponent.apply(this, arguments);
// load data
if ( debug ){
console.debug( 'load user list' );
}
userStore.load();
}, },
reload: function(){ selectItem: function(item){
if ( debug ){ console.debug( item );
console.debug('reload store');
}
this.store.load();
},
selectionChanged: function(sm){
var selected = sm.getSelected();
if ( selected ){
if ( debug ){
console.debug( selected.data.name + ' selected' );
}
}
},
renderMailto: function(mail){
return String.format( this.mailtoTemplate, mail );
} }
}); });