﻿Itsb_PrezziPage = function(config)
{
    Ext.apply(this, config);

	var storePrezzi = new Ext.data.Store({
        url: 'Handler/PrezziHandler.ashx?action=list',  
        reader: new Ext.data.JsonReader({
            root:          'Itsb_Bean_Prezzi',
            totalProperty: 'rowcount',
            id:            'IdAppartamento'
        }, [
            {name: 'IdAppartamento'},
            {name: 'Tipologia'},
            {name: 'PrezzoLuglioW'},
            {name: 'PrezzoLuglioS'},
            {name: 'PrezzoLuglioM'},
            {name: 'PrezzoAgostoW'},
            {name: 'PrezzoAgostoS'},
            {name: 'PrezzoAgostoM'},
            {name: 'PrezzoSettembreW'},
            {name: 'PrezzoSettembreS'},
            {name: 'PrezzoSettembreM'},
            {name: 'PrezzoOttobreW'},
            {name: 'PrezzoOttobreS'},
            {name: 'PrezzoOttobreM'}
        ])
    });   
    //storePrezzi.load();

	var tpl = new Ext.XTemplate(
	    '<tpl for=".">',
			'<tpl if="this.isOdd(IdAppartamento)">',
		       '<div class="odd">',
		        '{Tipologia}',
		        '</div>',
	        '</tpl>',
			'<tpl if="this.isEven(IdAppartamento)">',
		       '<div class="even">',
		        '{Tipologia}',
		        '</div>',
	        '</tpl>',
	    '</tpl></p>', {
     isOdd: function(id){
		if (id%2===0)
         return 'odd';
     },
     isEven: function(id){
		if (!(id%2===0))
         return 'even';
     }}
	);
	var tplPrezzoLuglioW = new Ext.XTemplate(
	    '<tpl for=".">',
			'<tpl if="this.isOdd(IdAppartamento)">',
		       '<div class="odd">',
		        '{PrezzoLuglioW}',
		        '</div>',
	        '</tpl>',
			'<tpl if="this.isEven(IdAppartamento)">',
		       '<div class="even">',
		        '{PrezzoLuglioW}',
		        '</div>',
	        '</tpl>',
	    '</tpl></p>', {
     isOdd: function(id){
		if (id%2===0)
         return 'odd';
     },
     isEven: function(id){
		if (!(id%2===0))
         return 'even';
     }}
	);
	var tplPrezzoLuglioS = new Ext.XTemplate(
	    '<tpl for=".">',
			'<tpl if="this.isOdd(IdAppartamento)">',
		       '<div class="odd">',
		        '{PrezzoLuglioS}',
		        '</div>',
	        '</tpl>',
			'<tpl if="this.isEven(IdAppartamento)">',
		       '<div class="even">',
		        '{PrezzoLuglioS}',
		        '</div>',
	        '</tpl>',
	    '</tpl></p>', {
     isOdd: function(id){
		if (id%2===0)
         return 'odd';
     },
     isEven: function(id){
		if (!(id%2===0))
         return 'even';
     }}
	);
	var tplPrezzoLuglioM = new Ext.XTemplate(
	    '<tpl for=".">',
			'<tpl if="this.isOdd(IdAppartamento)">',
		       '<div class="odd">',
		        '{PrezzoLuglioM}',
		        '</div>',
	        '</tpl>',
			'<tpl if="this.isEven(IdAppartamento)">',
		       '<div class="even">',
		        '{PrezzoLuglioM}',
		        '</div>',
	        '</tpl>',
	    '</tpl></p>', {
     isOdd: function(id){
		if (id%2===0)
         return 'odd';
     },
     isEven: function(id){
		if (!(id%2===0))
         return 'even';
     }}
	);
	var tplPrezzoAgostoW = new Ext.XTemplate(
	    '<tpl for=".">',
			'<tpl if="this.isOdd(IdAppartamento)">',
		       '<div class="odd">',
		        '{PrezzoAgostoW}',
		        '</div>',
	        '</tpl>',
			'<tpl if="this.isEven(IdAppartamento)">',
		       '<div class="even">',
		        '{PrezzoAgostoW}',
		        '</div>',
	        '</tpl>',
	    '</tpl></p>', {
     isOdd: function(id){
		if (id%2===0)
         return 'odd';
     },
     isEven: function(id){
		if (!(id%2===0))
         return 'even';
     }}
	);
	var tplPrezzoAgostoS = new Ext.XTemplate(
	    '<tpl for=".">',
			'<tpl if="this.isOdd(IdAppartamento)">',
		       '<div class="odd">',
		        '{PrezzoAgostoS}',
		        '</div>',
	        '</tpl>',
			'<tpl if="this.isEven(IdAppartamento)">',
		       '<div class="even">',
		        '{PrezzoAgostoS}',
		        '</div>',
	        '</tpl>',
	    '</tpl></p>', {
     isOdd: function(id){
		if (id%2===0)
         return 'odd';
     },
     isEven: function(id){
		if (!(id%2===0))
         return 'even';
     }}
	);
	var tplPrezzoAgostoM = new Ext.XTemplate(
	    '<tpl for=".">',
			'<tpl if="this.isOdd(IdAppartamento)">',
		       '<div class="odd">',
		        '{PrezzoAgostoM}',
		        '</div>',
	        '</tpl>',
			'<tpl if="this.isEven(IdAppartamento)">',
		       '<div class="even">',
		        '{PrezzoAgostoM}',
		        '</div>',
	        '</tpl>',
	    '</tpl></p>', {
     isOdd: function(id){
		if (id%2===0)
         return 'odd';
     },
     isEven: function(id){
		if (!(id%2===0))
         return 'even';
     }}
	);


    var listViewLA = new Ext.ListView({
        store: storePrezzi,
        multiSelect: false,
        emptyText: 'Non sono disponibili prezzi',
		title:'Luglio - Agosto',
        id:'listview-lug-ago',
        columns: [
			{header: 'Tipologia',dataIndex: 'Tipologia', align: 'center',width: .20, tpl:tpl},
            {header: 'Luglio Week-end', dataIndex: 'PrezzoLuglioW', align: 'center',tpl:tplPrezzoLuglioW},
            {header: 'Luglio Settimanale', dataIndex: 'PrezzoLuglioS', align: 'center',tpl:tplPrezzoLuglioS},
            {header: 'Luglio Mensile', dataIndex: 'PrezzoLuglioM', align: 'center',tpl:tplPrezzoLuglioM},
            {header: 'Agosto Week-end', dataIndex: 'PrezzoAgostoW', align: 'center',tpl:tplPrezzoAgostoW},
            {header: 'Agosto Settimanale', dataIndex: 'PrezzoAgostoS', align: 'center',tpl:tplPrezzoAgostoS},
            {header: 'Agosto Mensile', dataIndex: 'PrezzoAgostoM', align: 'center', tpl:tplPrezzoAgostoM}
			]
    });

	
	var tpl = new Ext.XTemplate(
	    '<tpl for=".">',
			'<tpl if="this.isOdd(IdAppartamento)">',
		       '<div class="odd">',
		        '{Tipologia}',
		        '</div>',
	        '</tpl>',
			'<tpl if="this.isEven(IdAppartamento)">',
		       '<div class="even">',
		        '{Tipologia}',
		        '</div>',
	        '</tpl>',
	    '</tpl></p>', {
     isOdd: function(id){
		if (id%2===0)
         return 'odd';
     },
     isEven: function(id){
		if (!(id%2===0))
         return 'even';
     }}
	);
	var tplPrezzoSettembreW = new Ext.XTemplate(
	    '<tpl for=".">',
			'<tpl if="this.isOdd(IdAppartamento)">',
		       '<div class="odd">',
		        '{PrezzoSettembreW}',
		        '</div>',
	        '</tpl>',
			'<tpl if="this.isEven(IdAppartamento)">',
		       '<div class="even">',
		        '{PrezzoSettembreW}',
		        '</div>',
	        '</tpl>',
	    '</tpl></p>', {
     isOdd: function(id){
		if (id%2===0)
         return 'odd';
     },
     isEven: function(id){
		if (!(id%2===0))
         return 'even';
     }}
	);
	var tplPrezzoSettembreS = new Ext.XTemplate(
	    '<tpl for=".">',
			'<tpl if="this.isOdd(IdAppartamento)">',
		       '<div class="odd">',
		        '{PrezzoSettembreS}',
		        '</div>',
	        '</tpl>',
			'<tpl if="this.isEven(IdAppartamento)">',
		       '<div class="even">',
		        '{PrezzoSettembreS}',
		        '</div>',
	        '</tpl>',
	    '</tpl></p>', {
     isOdd: function(id){
		if (id%2===0)
         return 'odd';
     },
     isEven: function(id){
		if (!(id%2===0))
         return 'even';
     }}
	);
	var tplPrezzoSettembreM = new Ext.XTemplate(
	    '<tpl for=".">',
			'<tpl if="this.isOdd(IdAppartamento)">',
		       '<div class="odd">',
		        '{PrezzoSettembreM}',
		        '</div>',
	        '</tpl>',
			'<tpl if="this.isEven(IdAppartamento)">',
		       '<div class="even">',
		        '{PrezzoSettembreM}',
		        '</div>',
	        '</tpl>',
	    '</tpl></p>', {
     isOdd: function(id){
		if (id%2===0)
         return 'odd';
     },
     isEven: function(id){
		if (!(id%2===0))
         return 'even';
     }}
	);
	var tplPrezzoOttobreW = new Ext.XTemplate(
	    '<tpl for=".">',
			'<tpl if="this.isOdd(IdAppartamento)">',
		       '<div class="odd">',
		        '{PrezzoOttobreW}',
		        '</div>',
	        '</tpl>',
			'<tpl if="this.isEven(IdAppartamento)">',
		       '<div class="even">',
		        '{PrezzoOttobreW}',
		        '</div>',
	        '</tpl>',
	    '</tpl></p>', {
     isOdd: function(id){
		if (id%2===0)
         return 'odd';
     },
     isEven: function(id){
		if (!(id%2===0))
         return 'even';
     }}
	);
	var tplPrezzoOttobreS = new Ext.XTemplate(
	    '<tpl for=".">',
			'<tpl if="this.isOdd(IdAppartamento)">',
		       '<div class="odd">',
		        '{PrezzoOttobreS}',
		        '</div>',
	        '</tpl>',
			'<tpl if="this.isEven(IdAppartamento)">',
		       '<div class="even">',
		        '{PrezzoOttobreS}',
		        '</div>',
	        '</tpl>',
	    '</tpl></p>', {
     isOdd: function(id){
		if (id%2===0)
         return 'odd';
     },
     isEven: function(id){
		if (!(id%2===0))
         return 'even';
     }}
	);
	var tplPrezzoOttobreM = new Ext.XTemplate(
	    '<tpl for=".">',
			'<tpl if="this.isOdd(IdAppartamento)">',
		       '<div class="odd">',
		        '{PrezzoOttobreM}',
		        '</div>',
	        '</tpl>',
			'<tpl if="this.isEven(IdAppartamento)">',
		       '<div class="even">',
		        '{PrezzoOttobreM}',
		        '</div>',
	        '</tpl>',
	    '</tpl></p>', {
     isOdd: function(id){
		if (id%2===0)
         return 'odd';
     },
     isEven: function(id){
		if (!(id%2===0))
         return 'even';
     }}
	);
    var listViewSO = new Ext.ListView({
        store: storePrezzi,
        multiSelect: false,
		id:'listview-sett-ott',
        emptyText: 'Non sono disponibili prezzi',
        columns: [
			{header: 'Tipologia',dataIndex: 'Tipologia', align: 'center',width: .20,tpl:tpl},
            {header: 'Settembre Week-end', dataIndex: 'PrezzoSettembreW', align: 'center',tpl:tplPrezzoSettembreW},
            {header: 'Settembre Settimanale', dataIndex: 'PrezzoSettembreS', align: 'center',tpl:tplPrezzoSettembreS},
            {header: 'Settembre Mensile', dataIndex: 'PrezzoSettembreM', align: 'center',tpl:tplPrezzoSettembreM},
            {header: 'Ott/Giu Week-end', dataIndex: 'PrezzoOttobreW', align: 'center',tpl:tplPrezzoOttobreW},
            {header: 'Ott/Giu Settimanale', dataIndex: 'PrezzoOttobreS', align: 'center',tpl:tplPrezzoOttobreS},
            {header: 'Ott/Giu Mensile', dataIndex: 'PrezzoOttobreM', align: 'center',tpl:tplPrezzoOttobreM}
			]			
    });

	var contentPrezziPageSO =  new Ext.Panel({
        id:'center-panel-prezzi-page-so',
		layout:'fit',
		frame:false,
		title:'Listino relativo ai mesi di Settembre - Ottobre/Giugno',
		height: 180,
		border : true,
		collapsible:false,
		items: [listViewSO]
    });
	
	var contentPrezziPageLA =  new Ext.Panel({
        id:'center-panel-prezzi-page-la',
		layout:'fit',
		frame:false,
		title:'Listino relativo ai mesi di Luglio - Agosto',
		height: 180,
		border : true,
		collapsible:false,
		items: [listViewLA]
    });

	/*
	var contentPrezziPanel = new Ext.Panel({
        id:'prezzicontentPanel',
        title:'',
        border:false,
        autoScroll:true,
        items:[contentPrezziPageLA,contentPrezziPageSO]
    });
	*/
	var headerImageContentPanel = new Ext.Panel({
        id:'prezzi-header-image-contentPanel',
        border:false,
        autoScroll:false,
        html :  '<img src="images/base/titolo_prezzi.png" title="I Prezzi degli appartamenti" alt="I Prezzi degli appartamenti">'
    });

	var testoHeader='N.B.:I prezzi degli appartamenti sono espressi in euro e si riferiscono ad ogni appartamento o dove compare la dicitura "Singola" alla singola camera)</small></p><br/><p>'+
					'<b><i>A fine soggiorno saranno calcolati gli importi dei consumi di elettricità e gas.</i></b><br/>'+
					'<b><i>Possono anche essere richiesti i servizi aggiuntivi di biancheria da letto e da bagno e il servizio di pulizia finale di un appartamento.</i></b></p><br/>';
					
	var headerTextContentPanel = new Ext.Panel({
        id:'prezzi-header-text-contentPanel',
        border:false,
        autoScroll:false,
        html :  testoHeader
    });

	var storeNote = new Ext.data.Store({
        url: 'Handler/NoteHandler.ashx?action=list',  
        reader: new Ext.data.JsonReader({
            root:          'Itsb_Bean_Note',
            totalProperty: 'rowcount',
            id:            'IdNota'
        }, [
            {name: 'IdNota'},
            {name: 'Nota'}
        ])
    });   
	
	storePrezzi.on('load',function(){
		storeNote.load();
	});
	storePrezzi.load();
    
    var listNote = new Ext.ListView({
        store: storeNote,
        multiSelect: false,
        emptyText: 'Non ci sono note aggiuntive',
		height: 200,
		width: 870,
		hideHeaders:true,
		autoheight: true,
		autoScroll:true,
		border : true,
        columns: [
			{dataIndex: 'Nota', align: 'left'}
			]
    });	
	
	var contentPrezziPagePanel = new Ext.Panel({
        id:'contentPrezziPagePanel',
        title:'',
        width: 910,
        border:false,
        autoScroll:true,
		layout:'ux.row',
		height:550,
        bodyStyle   : 'padding:5px 5px 5px 5px',
        items:[headerImageContentPanel,headerTextContentPanel,contentPrezziPageLA,contentPrezziPageSO,listNote]
    });
	
    Itsb_PrezziPage.superclass.constructor.call(this, {
        id          : config.id,
        title       : config.title,
        width       : 920,
        height      : 550,        
        layout      : 'fit',
        border      : false,
        modal       : true,
        plain       : true,
        resizable   : false,
        maximizable : true,
        autoDestroy : true,
		bbar        :[
			'->',
			{
                text: 'Chiudi e torna alla Home Page',
                iconCls: 'IconButton24px',
				id:'chiudi-button',
                iconAlign: 'right',
				scale:'medium',
				ctCls:'TextButton24px',
				handler: function(){                
		                Ext.getCmp(config.id).close();
					}
            }],
		items       : [contentPrezziPagePanel]
    });
};

Ext.extend(Itsb_PrezziPage, Ext.Window, {

    initComponent : function(){
        Itsb_PrezziPage.superclass.initComponent.call(this);             
    }
    
});



