added Sonia.rest.FormPanel

This commit is contained in:
Sebastian Sdorra
2010-11-08 20:24:06 +01:00
parent f041ae4bb0
commit 7cfe5d8bc8
2 changed files with 81 additions and 53 deletions

View File

@@ -92,7 +92,7 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
var editPanel = Ext.getCmp('repositoryEditPanel'); var editPanel = Ext.getCmp('repositoryEditPanel');
editPanel.removeAll(); editPanel.removeAll();
var panel = new Sonia.repository.FormPanel({ var panel = new Sonia.repository.FormPanel({
item: selected.data, item: item,
region: 'south', region: 'south',
title: 'Repository Form', title: 'Repository Form',
padding: 5, padding: 5,
@@ -121,23 +121,13 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
Ext.reg('repositoryGrid', Sonia.repository.Grid); Ext.reg('repositoryGrid', Sonia.repository.Grid);
// RepositoryFormPanel // RepositoryFormPanel
Sonia.repository.FormPanel = Ext.extend(Ext.FormPanel,{ Sonia.repository.FormPanel = Ext.extend(Sonia.rest.FormPanel,{
item: null,
onUpdate: null,
onCreate: null,
initComponent: function(){ initComponent: function(){
update = this.item != null; update = this.item != null;
var config = { var config = {
padding: 5,
labelWidth: 100,
defaults: {width: 240},
autoScroll: true,
monitorValid: true,
defaultType: 'textfield',
items:[ items:[
{id: 'repositoryName', fieldLabel: 'Name', name: 'name', readOnly: update, allowBlank: false}, {id: 'repositoryName', fieldLabel: 'Name', name: 'name', readOnly: update, allowBlank: false},
{ {
@@ -159,38 +149,11 @@ Sonia.repository.FormPanel = Ext.extend(Ext.FormPanel,{
{fieldLabel: 'Contact', name: 'contact'}, {fieldLabel: 'Contact', name: 'contact'},
{fieldLabel: 'Description', name: 'description', xtype: 'textarea'} {fieldLabel: 'Description', name: 'description', xtype: 'textarea'}
],
buttonAlign: 'center',
buttons: [
{text: 'Ok', formBind: true, scope: this, handler: this.submit},
{text: 'Cancel', scope: this, handler: this.reset}
] ]
}; };
Ext.apply(this, Ext.apply(this.initialConfig, config)); Ext.apply(this, Ext.apply(this.initialConfig, config));
Sonia.repository.FormPanel.superclass.initComponent.apply(this, arguments); Sonia.repository.FormPanel.superclass.initComponent.apply(this, arguments);
if ( update ){
this.loadData( this.item );
}
},
loadData: function(item){
this.item = item;
var data = {success: true, data: item};
this.getForm().loadRecord(data);
},
submit: function(){
if ( debug ){
console.debug( 'repository form submitted' );
}
var item = this.getForm().getFieldValues();
if ( this.item != null ){
this.update(item);
} else {
this.create(item);
}
}, },
update: function(item){ update: function(item){
@@ -237,18 +200,6 @@ Sonia.repository.FormPanel = Ext.extend(Ext.FormPanel,{
alert( 'failure' ); alert( 'failure' );
} }
}); });
},
reset: function(){
this.getForm().reset();
},
execCallback: function(obj, item){
if ( Ext.isFunction( obj ) ){
obj(item);
} else if ( Ext.isObject( obj )){
obj.fn.call( obj.scope, item );
}
} }
}); });

View File

@@ -59,6 +59,8 @@ Sonia.rest.JsonStore = Ext.extend( Ext.data.JsonStore, {
}); });
// Grid
Sonia.rest.Grid = Ext.extend(Ext.grid.GridPanel, { Sonia.rest.Grid = Ext.extend(Ext.grid.GridPanel, {
urlTemplate: '<a href="{0}" target="_blank">{0}</a>', urlTemplate: '<a href="{0}" target="_blank">{0}</a>',
@@ -107,7 +109,7 @@ Sonia.rest.Grid = Ext.extend(Ext.grid.GridPanel, {
}, },
selectItem: function(item){ selectItem: function(item){
console.debug( item );
}, },
renderUrl: function(url){ renderUrl: function(url){
@@ -118,5 +120,80 @@ Sonia.rest.Grid = Ext.extend(Ext.grid.GridPanel, {
return String.format( this.mailtoTemplate, mail ); return String.format( this.mailtoTemplate, mail );
} }
});
// FormPanel
Sonia.rest.FormPanel = Ext.extend(Ext.FormPanel,{
item: null,
onUpdate: null,
onCreate: null,
initComponent: function(){
var config = {
padding: 5,
labelWidth: 100,
defaults: {width: 240},
autoScroll: true,
monitorValid: true,
defaultType: 'textfield',
buttonAlign: 'center',
buttons: [
{text: 'Ok', formBind: true, scope: this, handler: this.submit},
{text: 'Cancel', scope: this, handler: this.reset}
]
}
Ext.apply(this, Ext.apply(this.initialConfig, config));
Sonia.rest.FormPanel.superclass.initComponent.apply(this, arguments);
if ( this.item != null ){
this.loadData(this.item);
}
},
loadData: function(item){
this.item = item;
var data = {success: true, data: item};
this.getForm().loadRecord(data);
},
submit: function(){
if ( debug ){
console.debug( 'form submitted' );
}
var item = this.getForm().getFieldValues();
if ( this.item != null ){
this.update(item);
} else {
this.create(item);
}
},
reset: function(){
if ( debug ){
console.debug( 'reset form' );
}
this.getForm().reset();
},
execCallback: function(obj, item){
if ( Ext.isFunction( obj ) ){
obj(item);
} else if ( Ext.isObject( obj )){
obj.fn.call( obj.scope, item );
}
},
update: function(item){
console.debug( 'update item: ' );
console.debug( item );
},
create: function(item){
console.debug( 'create item: ' );
console.debug( item );
}
}); });