From 7cfe5d8bc85240db772769c7dc5b2c2f8b1d8c12 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 8 Nov 2010 20:24:06 +0100 Subject: [PATCH] added Sonia.rest.FormPanel --- .../webapp/resources/js/sonia.repository.js | 53 +----------- .../main/webapp/resources/js/sonia.rest.js | 81 ++++++++++++++++++- 2 files changed, 81 insertions(+), 53 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.repository.js b/scm-webapp/src/main/webapp/resources/js/sonia.repository.js index 97c88ffb51..fa0fa81d6d 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.repository.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.repository.js @@ -92,7 +92,7 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { var editPanel = Ext.getCmp('repositoryEditPanel'); editPanel.removeAll(); var panel = new Sonia.repository.FormPanel({ - item: selected.data, + item: item, region: 'south', title: 'Repository Form', padding: 5, @@ -121,23 +121,13 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { Ext.reg('repositoryGrid', Sonia.repository.Grid); // RepositoryFormPanel -Sonia.repository.FormPanel = Ext.extend(Ext.FormPanel,{ - - item: null, - onUpdate: null, - onCreate: null, +Sonia.repository.FormPanel = Ext.extend(Sonia.rest.FormPanel,{ initComponent: function(){ update = this.item != null; var config = { - padding: 5, - labelWidth: 100, - defaults: {width: 240}, - autoScroll: true, - monitorValid: true, - defaultType: 'textfield', items:[ {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: '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)); 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){ @@ -237,18 +200,6 @@ Sonia.repository.FormPanel = Ext.extend(Ext.FormPanel,{ 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 ); - } } }); diff --git a/scm-webapp/src/main/webapp/resources/js/sonia.rest.js b/scm-webapp/src/main/webapp/resources/js/sonia.rest.js index 394c704592..5a264a33fa 100644 --- a/scm-webapp/src/main/webapp/resources/js/sonia.rest.js +++ b/scm-webapp/src/main/webapp/resources/js/sonia.rest.js @@ -59,6 +59,8 @@ Sonia.rest.JsonStore = Ext.extend( Ext.data.JsonStore, { }); +// Grid + Sonia.rest.Grid = Ext.extend(Ext.grid.GridPanel, { urlTemplate: '{0}', @@ -107,7 +109,7 @@ Sonia.rest.Grid = Ext.extend(Ext.grid.GridPanel, { }, selectItem: function(item){ - + console.debug( item ); }, renderUrl: function(url){ @@ -118,5 +120,80 @@ Sonia.rest.Grid = Ext.extend(Ext.grid.GridPanel, { return String.format( this.mailtoTemplate, mail ); } +}); -}); \ No newline at end of file +// 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 ); + } + +});