App.Administration = function(){
    
    // begin private
    
    // end private
   
    // begin public
    return{
        
        start: function(){
            App.setTrace('App.Administration.start');
            
            App.setNavigation('Administration');
            this.toolbar();

        },
        
        wakeup: function(){
            
            App.setTrace('App.Administration.wakeup');
            
            if(!this.isWindow){
                this.isWindow = true;
                this.buildWindow.add(this.buildProperty);
            }
            
            this.buildStore.load();
            this.buildWindow.show();
            
            return;
        },
        
        toolbar: function(){
            App.setTrace('App.Administration.toolbar');
            
            var toolbar = App.getToolbar();
            toolbar.add({
                xtype: 'tbbutton',
                text: 'Administration',
                cls: 'x-btn-text-icon',
                icon: 'library/icons/wrench.png',
                handler: function(){
                    App.checkNavigation('Administration',0);
                }
            });
            
            toolbar.add({
                xtype: 'tbseparator'
            });
            
            App.doLayoutToolbar();
            
            return;
        },
        
        isWindow: false,
        
        buildWindow: new Ext.Window({
            title: 'Administration',
            width: 300,
            x: 120,
            y: 85,
            iconCls: 'icon-administration',
            id: 'Administration',
            draggable: true,
            resizable: false,
            autoHeight: true,
            closeAction: 'hide',
            shadow: false
        }),
        
        buildStore: new Ext.data.JsonStore({
            url: 'frontend/controler/app.php',
            baseParams: {
                modul: 'admin',
                aktion: 'holen'
            },
            root: 'data',
            fields: ['Debugmodus', 'Telekom Benutzer', 'Telekom Passwort','Telefon Buero','Mailadresse Buero','Absender'],
            listeners: {
                load: {
                    fn: function(store, records, options){
                        // get the property grid component
                        var propGrid = Ext.getCmp('AdministrationPropGrid');
                        // make sure the property grid exists
                        if (propGrid) {
                            // populate the property grid with store data
                            propGrid.setSource(store.getAt(0).data);
                        }
                    }
                }
            }
        }),
        
        buildProperty: {
            xtype: 'propertygrid',
            id: 'AdministrationPropGrid',
            autoHeight: true,
            width: 300,
            source: {}, //initialize source config object
            buttonAlign: 'center',
            tbar: {
                items: [{
                    xtype: 'tbfill'
                },{
                    xtype: 'tbseparator'
                },{
                    xtype: 'tbbutton',
                    text: 'Information',
                    cls: 'x-btn-text-icon',
                    icon: 'library/icons/information.png'
                },{
                    xtype: 'tbseparator' 
                },{
                    xtype: 'tbspacer',
                    width: 50
                }]
            },
            fbar: [{
                xtype: 'tbseparator'
            },{
                "xtype": "button",
                "text": "&auml;ndern",
                cls: 'x-btn-text-icon',
                icon: 'library/icons/button_ok.png',
                handler: function(){
                    App.Administration.onSubmit();
                }
            },{
               xtype: 'tbseparator' 
            }]
        },
        
        onSubmit: function() {
            App.setTrace('App.Administration.onSubmit');
            
    		var propGridValues = Ext.util.JSON.encode(this.buildStore.getAt(0).data);
            
    		Ext.Ajax.request({
    			url: 'frontend/controler/app.php',
    			method: 'POST',
    			scope: this,
    			params: {
    				form: propGridValues,
                    modul: 'admin',
                    aktion: 'updaten'
    			}
    		});
    	}
        

    } // end public
    
}();

Ext.onReady(App.Administration.start,App.Administration);
