merge with branch issue-48

This commit is contained in:
Sebastian Sdorra
2011-09-05 13:44:25 +02:00
4 changed files with 193 additions and 16 deletions

View File

@@ -99,6 +99,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 ){
@@ -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

@@ -39,6 +39,9 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
colUrlText: 'Url',
emptyText: 'No repository is configured',
formTitleText: 'Repository Form',
searchValue: null,
typeFilter: null,
initComponent: function(){
@@ -51,6 +54,12 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
fields: [ 'id', 'name', 'type', 'contact', 'description', 'creationDate', 'url', 'public', 'permissions', 'properties' ],
sortInfo: {
field: 'name'
},
listeners: {
load: {
fn: this.storeLoad,
scope: this
}
}
});
@@ -86,6 +95,12 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
Ext.apply(this, Ext.apply(this.initialConfig, config));
Sonia.repository.Grid.superclass.initComponent.apply(this, arguments);
},
storeLoad: function(){
if (this.searchValue){
this.filterStore();
}
},
onFallBelowMinHeight: function(height, minHeight){
var p = Ext.getCmp('repositoryEditPanel');
@@ -97,6 +112,41 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
p.doLayout();
this.ownerCt.doLayout();
},
search: function(value){
this.searchValue = value;
this.filterStore();
},
filter: function(type){
this.typeFilter = type;
this.filterStore();
},
clearStoreFilter: function(){
this.searchValue = null;
this.typeFilter = null;
this.getStore().clearFilter();
},
filterStore: function(){
var store = this.getStore();
if ( ! this.searchValue && ! this.typeFilter ){
store.clearFilter();
} else {
var search = null;
if ( this.searchValue ){
search = this.searchValue.toLowerCase();
}
store.filterBy(function(rec){
return (! search ||
rec.get('name').toLowerCase().indexOf(search) >= 0 ||
rec.get('description').toLowerCase().indexOf(search) >= 0) &&
(! this.typeFilter || rec.get('type') == this.typeFilter);
}, this);
}
},
selectItem: function(item){
if ( debug ){

View File

@@ -42,17 +42,87 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, {
initComponent: function(){
// create new store for repository types
var typeStore = new Ext.data.JsonStore({
id: 1,
fields: [ 'displayName', 'name' ]
});
// load types from server state
typeStore.loadData(state.repositoryTypes);
// add empty value
var t = new typeStore.recordType({
displayName: '',
name: ''
});
typeStore.insert(0, t);
var toolbar = [];
if ( admin ){
toolbar.push(
{xtype: 'tbbutton', text: this.addText, icon: this.addIcon, scope: this, handler: this.showAddForm}
);
toolbar.push({
xtype: 'tbbutton',
text: this.addText,
icon: this.addIcon,
scope: this,
handler: this.showAddForm
});
}
toolbar.push(
{xtype: 'tbbutton', id: 'repoRmButton', disabled: true, text: this.removeText, icon: this.removeIcon, scope: this, handler: this.removeRepository},
'-',
{xtype: 'tbbutton', text: this.reloadText, icon: this.reloadIcon, scope: this, handler: this.reload}
);
toolbar.push({
xtype: 'tbbutton',
id: 'repoRmButton',
disabled: true,
text: this.removeText,
icon: this.removeIcon,
scope: this,
handler: this.removeRepository
},'-', {
xtype: 'tbbutton',
text: this.reloadText,
icon: this.reloadIcon,
scope: this,
handler: this.reload
},'-',{
xtype: 'label',
text: 'Filter: '
}, ' ', {
id: 'repositoryTypeFilter',
xtype: 'combo',
hiddenName : 'type',
typeAhead: true,
triggerAction: 'all',
lazyRender: true,
mode: 'local',
editable: false,
store: typeStore,
valueField: 'name',
displayField: 'displayName',
allowBlank: true,
listeners: {
select: {
fn: this.filterByType,
scope: this
}
},
tpl:'<tpl for=".">' +
'<div class="x-combo-list-item">' +
'{displayName}&nbsp;' +
'</div></tpl>'
}, ' ',{
xtype: 'label',
text: 'Search: '
}, ' ',{
id: 'repositorySearch',
xtype: 'textfield',
enableKeyEvents: true,
listeners: {
keyup: {
fn: this.search,
scope: this
}
}
});
var config = {
tbar: toolbar,
@@ -81,6 +151,14 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, {
Ext.apply(this, Ext.apply(this.initialConfig, config));
Sonia.repository.Panel.superclass.initComponent.apply(this, arguments);
},
filterByType: function(combo, rec){
Ext.getCmp('repositoryGrid').filter(rec.get('name'));
},
search: function(field){
Ext.getCmp('repositoryGrid').search(field.getValue());
},
removeRepository: function(){
var grid = Ext.getCmp('repositoryGrid');
@@ -142,12 +220,36 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, {
scope: this
},
created: {
fn: this.reload,
fn: this.repositoryCreated,
scope: this
}
}
}]);
},
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('');
grid.clearStoreFilter();
},
reload: function(){
Ext.getCmp('repositoryGrid').reload();

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' );