Ext.namespace('Ext.as');

Ext.data.ObjectReader = function(meta, recordType){
    Ext.data.ObjectReader.superclass.constructor.call(this, meta, recordType);
};
Ext.extend(Ext.data.ObjectReader, Ext.data.JsonReader, {
    readRecords : function(o){
	    return o;
    }
});

Ext.as.Application = function()
{
	return {
	    onSelectAnno: function(combo,record,index) {
	        this.posizioni.getUpdater().update({url:'Posizioni.aspx',params:{anno:record.get('anno')}});
	        this.archivi.body.update('');
	    },
	    onSelectPosizione: function(model,index,record) {
	        this.archivioStore.load({params:{uid:record.get('uid')}});
	    },
	    loadPersona: function(uid) {
	        this.personaDettagli.getUpdater().update({
	            url: 'Persona.aspx',
	            params: {
                    'uid': uid
                }
	        });
	    },
	    consulta: function() {
	        this.mainTab.setActiveTab(this.consultaTab);
	    },
	    ricerca: function(panel) {
	        this.mainTab.setActiveTab(this.ricercaTab);
	        if(panel != null)
	            panel.expand(false);
	    },
	    loadIstituzione: function(uid) {
	        this.istituzioneDettagli.getUpdater().update({
	            url: 'Istituzione.aspx',
	            params: {
                    'uid': uid
                }
	        });
	    },
	    loadScheda: function(uid) {
	        this.schedaDettagli.getUpdater().update({
	            url: 'Scheda.aspx',
	            params: {
                    'uid': uid
                }
	        });
	    },
	    loadArchivi: function(uid) {
	        this.archivi.getUpdater().update({url:'Archivi.aspx',params:{'uid':uid}});
	    },
	    loadArchivio: function(uid) {
	        this.mainTab.setActiveTab(this.archivioTab);
	        this.archivio.getUpdater().update({url:'Archivio.aspx',params:{'uid':uid}});
	    },
	    init: function(uid) {
	        var defaultTab = 0;
	        if(uid != null) defaultTab = 2;
	            
            this.anniStore = new Ext.data.JsonStore({
                url: 'Anni.aspx',
                root: 'anni',
                fields: ['anno']
            });
            this.anniStore.load();
			this.mainTab = new Ext.TabPanel({
			    layoutOnTabChange: true,
				activeTab: defaultTab,
				height: 492,
				renderTo: 'content',
			    items: [this.intro = new Ext.Panel({
			        title: 'Introduzione',
			        height: 445
			    }),
			    this.consultaTab = new Ext.Panel({
			        title: 'Consulta',
			        height: 445,
					items: [{
						id: 'columnLayout',
						layout:'column',
						border: false,
						items: [{
							columnWidth: .4,
							border:false,
							items: [
								this.archiviForm = new Ext.form.FormPanel({
									labelWidth: 75, // label settings here cascade unless overridden
                                    style: 'padding:3px;',
									url:'save-form.php',
									frame:true,
									header: true,
									title: '&nbsp;',
									defaults: {width: 200},
									items: [
									    new Ext.form.ComboBox({
									        listClass: 'align-correction',
									        store: this.anniStore,
									        displayField:'anno',
                                            triggerAction: 'all',
                                            fieldLabel: 'Anno',
                                            emptyText:'Seleziona un anno...',
                                            forceSelection:true,
                                            mode: 'local',
                                            typeAhead: true,
                                            name: 'Anno'
									    }),
									    new Ext.form.TextField({
                                            fieldLabel: 'Titolo',
                                            name: 'Testo'
									    })
									    
									],
                                    buttons: [{
                                        text: 'Cerca',
                                        scope: this,
                                        handler: function(e) {
                                            this.posizioni.getUpdater().update({url:'Posizioni.aspx',params:this.archiviForm.getForm().getValues()});
	                                        this.archivi.body.update('');
                                        }
                                    }]
								}),
								
								this.posizioni = new Ext.Panel({
                                    style: 'padding:3px;',
                                    height: 332, //Ext.isIE ? 400 : 418,
                                    frame:true,
                                    autoScroll: true
								})
							]
						},{
							columnWidth: .6,
							border:false,
							items: [
                                this.archivi = new Ext.Panel({
                                    style: 'padding:3px;',
                                    height: 463, //Ext.isIE ? 400 : 418,
                                    frame:true,
                                    autoScroll: true
							    })
							]
						}]
					}]
			    }),
			    this.ricercaTab = new Ext.Panel({
			        title: 'Ricerca',
			        height: 445,
					items: [
					    this.accordion = new Ext.Panel({
                            layout:'accordion',
                            style: 'padding:3px;',
                            border: true,
                            height: 463,
                            id: 'accordion',
                            items: [this.ricercaSchede = new Ext.Panel({
                                title: 'Ricerca schede',
                                items: [{
                                    layout:'column',
                                    border: false,
						            items: [{
							            columnWidth: .4,
							            border:false,
							            items:[
							                this.schedeForm = new Ext.form.FormPanel({
									            labelWidth: 100, // label settings here cascade unless overridden
                                                style: 'padding:3px;',
									            frame:true,
									            header: true,
									            title: '&nbsp;',
									            defaults: {width: 175},
									            items: [
									                new Ext.form.TextField({
                                                        fieldLabel: 'Inventario',
                                                        name: 'Inv'
									                }),
									                new Ext.form.TextField({
                                                        fieldLabel: 'Num. Inventario',
                                                        name: 'Ninv'
									                }),
									                new Ext.form.TextField({
                                                        fieldLabel: 'Num. Catalogo',
                                                        name: 'Nctn'
									                })
									            ],
                                                buttons: [{
                                                    text: 'Cerca',
                                                    scope: this,
                                                    handler: function(e) {
                                                        this.schede.getUpdater().update({url:'Schede.aspx',params:this.schedeForm.getForm().getValues()});
                                                    }
                                                }]
							                }),
								            this.schede = new Ext.Panel({
                                                style: 'padding:3px;',
                                                height: 225, //Ext.isIE ? 400 : 418,
                                                frame:true,
                                                autoScroll: true
							                })
							            ]
                                    },{
							            columnWidth: .6,
							            border:false,
							            items: [this.schedaDettagli = new Ext.Panel({
							                style: 'padding:3px;',
							                height: 381,
							                frame: true,
							                autoScroll: true
							            })]
                                    }]
                                }]
                            }),this.ricercaPersone = new Ext.Panel({
                                title: 'Ricerca persone',
                                items: [{
                                    layout:'column',
                                    border: false,
						            items: [{
							            columnWidth: .4,
							            border:false,
							            items:[
							                this.personeForm = new Ext.form.FormPanel({
									            labelWidth: 100, // label settings here cascade unless overridden
                                                style: 'padding:3px;',
									            frame:true,
									            header: true,
									            title: '&nbsp;',
									            defaults: {width: 175},
									            items: [
									                new Ext.form.TextField({
                                                        fieldLabel: 'Nome',
                                                        name: 'Nome'
									                })
									            ],
                                                buttons: [{
                                                    text: 'Cerca',
                                                    scope: this,
                                                    handler: function(e) {
                                                        this.persone.getUpdater().update({url:'Persone.aspx',params:this.personeForm.getForm().getValues()});
                                                    }
                                                }]									                
							                }),
							                this.persone = new Ext.Panel({
                                                style: 'padding:3px;',
                                                height: 271, //Ext.isIE ? 400 : 418,
                                                frame:true,
                                                autoScroll: true
							                })
							            ]
                                    },{
							            columnWidth: .6,
							            border:false,
							            items: [this.personaDettagli = new Ext.Panel({
							                style: 'padding:3px;',
							                height: 375,
							                frame: true
							            })]
                                    }]
                                }]
                            }),this.ricercaIstituzioni = new Ext.Panel({
                                title: 'Ricerca istituzioni',
                                items: [{
                                    layout:'column',
                                    border: false,
						            items: [{
							            columnWidth: .4,
							            border:false,
							            items:[
							                this.istituzioniForm = new Ext.form.FormPanel({
									            labelWidth: 100, // label settings here cascade unless overridden
                                                style: 'padding:3px;',
									            url:'save-form.php',
									            frame:true,
									            header: true,
									            title: '&nbsp;',
									            defaults: {width: 175},
									            items: [
									                new Ext.form.TextField({
                                                        fieldLabel: 'Denominazione',
                                                        name: 'Denominazione'
									                })
									            ],
                                                buttons: [{
                                                    text: 'Cerca',
                                                    scope: this,
                                                    handler: function(e) {
                                                        this.istituzioni.getUpdater().update({url:'Istituzioni.aspx',params:this.istituzioniForm.getForm().getValues()});
                                                    }
                                                }]
							                }),
							                this.istituzioni = new Ext.Panel({
                                                style: 'padding:3px;',
                                                height: 271, //Ext.isIE ? 400 : 418,
                                                frame:true,
                                                autoScroll: true
							                })
							            ]
                                    },{
							            columnWidth: .6,
							            border:false,
							            items: [this.istituzioneDettagli = new Ext.Panel({
							                style: 'padding:3px;',
							                height: 375,
							                frame: true
							            })]
                                    }]
                                }]
                            })]
                        })
					]
			    }),
			    this.archivioTab = new Ext.Panel({
                    title: 'Archivio',
			        height: 445,
			        items: [
			            this.archivio = new Ext.Panel({
			                height: 463,
			                frame: true,
			                header: false,
			                style: 'padding:3px;',
			                autoScroll:true
			            })
			        ]
			    })]
			});
			this.mainTab.doLayout();
			if(uid != null)
			{
                this.loadScheda(uid);
			}
			else
			{
    			this.intro.getUpdater().update({url:'intro.html'});
			}
			this.intro.on('activate', function() {this.intro.getUpdater().update({url:'intro.html'});}, this)
	    }
    }
}();

function metaBox(id){
if ( document.getElementById(id).style.display =='none')
	{
		document.getElementById(id).style.display='block'		
	}	
	else
	{
		document.getElementById(id).style.display='none'
	}
}
