// auswertung
// 
// beinhaltet den Wechseln-Dialog
//
// 
var auswertung = new fClass({
	
	
	chooseStrukturWindow: 	null,
	
	
	init:function(config){
		Ext.apply(this,config);


		this.buildChooseStrukturWindow();


		
		if(!rcm.Application.state.kostenstruktur.id){
			this.chooseStrukturWindow.show();
		}else{
			this.onReady(this.eventScope);
		}
		
		
		if(!rcm.Application.state.eigenes_institut){
			this.chooseStrukturWindow.hide();				
			if(rcm.Application.state.user.berechtigungsstufe == 1){
				Ext.MessageBox.alert('Fehler',"Es gibt noch kein Institut, oder Sie haben sich noch kein eigenes Institut zugewiesen. <br/>Sie werden in den Bereich Institute weitergeleitet.",function(){
					rcm.Application.loadInstituteTable();
					return;
				});
				
			}else{
				Ext.MessageBox.alert('Fehler',"Es gibt noch kein Institut, oder Sie haben sich noch kein eigenes Institut zugewiesen. <br/>Bitte wenden Sie sich an den Administrator.",function(){
					return;
				});
				
			}
		}
		
		return this;
		
	},
	
	
	buildChooseStrukturWindow:function(){

		// var forcedView = this.forcedView || true;
		this.chooseStrukturWindow = new Ext.Window({
			title:'Kostenstuktur auswählen',
			modal:true,
			width:400,
			autoDestroy:false,
			height:150,
			closable:false,
			layout:'fit',
			items: new Ext.FormPanel({
				head:false,
				bodyStyle:'padding:10px',
				id:'chooseKostenstrukturPanel',
				items:[{
					fieldLabel:'Kostenstruktur',
					allowBlank:false,
					xtype:'combo',
					triggerAction:'all',
					store:rcm.Application.multiStores['bcm_kostenstrukturen_name'],
					mode:'local',
					valueField:'id',
					displayField:'name'
					
					
				}]
			}),
			buttons:[{
				text:'Abbrechen',
				disabled:'true',
				scope:this,
				id:'btAbbrechenKS',
				handler:function(){
					this.chooseStrukturWindow.hide();
				}
			},{
				text:'Auswählen',
				scope:this,
				handler:function(){
					if(Ext.getCmp('chooseKostenstrukturPanel').getForm().isValid()){
						var val = Ext.getCmp('chooseKostenstrukturPanel').items.items[0].getValue();
						Ext.MessageBox.wait('Kostentruktur wird gewechselt..',false,waitDialogConfig);
						Ext.Ajax.request({
							url:cfg_backend_url + "auswertungen/changeStruktur/"+val,
							method:'post',
							scope:this,
							success:function(response){
								rcm.Application.state.kostenstruktur.name = response.responseText;
								
								Ext.get('selectedKostenstruktur').dom.innerHTML='ausgewählte Kostenstruktur: <b>'+rcm.Application.state.kostenstruktur.name+'</b>';		
								
								rcm.Application.state.kostenstruktur.id = val;
								Ext.MessageBox.hide();
								
								rcm.Application.loadCombostores(function(scope){
									scope.chooseStrukturWindow.hide();
									scope.onReady(scope.eventScope);
									
									if(scope.forcedView!=null){  // ob der content gelöscht werden soll
										rcm.Application.removeRegionCenterContent();
										
										Ext.getCmp('regionCenter').add(new Ext.Panel({  // ein pseudo inhalt, weil man den vorherigen inhalt irgendwie nich löschen kann
											head:false,
											border:false
										}));
										Ext.getCmp('regionCenter').doLayout();
										
									}
									
									
									
								},this);

							}
						});
						
					}
				}
			}]
		});
	},
	
	
	
	onReady:function(scope){
		
	}
	
	
	
});
