/*
 * Ext JS Library 2.0 RC 1
 * Copyright(c) 2006-2007, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

// Sample desktop configuration
MyDesktop = new Ext.app.App({
	init :function(){
		Ext.QuickTips.init();	
	},

	getModules : function(){
		return [
			new MyDesktop.esyPlannerWindow(),
			new MyDesktop.DownloadWindow()
		];
	},

    // config for the start menu
    getStartConfig : function(){
        return {
            title: 'esyWeb',
            iconCls: 'cog'//,
/*            toolItems: [{
                text:'Settings',
                iconCls:'settings',
                scope:this
            },'-',{
                text:'Logout',
                iconCls:'logout',
                scope:this
            }]
*/       };
    }
});

//[Download
 
function renderProduct(value, p, record){
	if(record.data.bIsDownload)
	{	
		return String.format(
				'<b><a href="./download/{0}_{1}_{2}.{3}" target="_self">{4}</a></b>',
				record.data.product,record.data.version,record.data.language,record.data.ext,value);
	}
	else	
	{
		return String.format(
				'<b><span style=\'color:{1};\'>{0}</span></b>',
				value,record.data.color);		
	}
}

function renderDownloadIcon(value, p, record){
	if(record.data.bIsDownload)
	{
		return String.format(
            '<b><a href="./download/{0}_{1}_{2}.{3}" target="_self"><img src="./images/download16x16.png"></a></b>',
            record.data.product,record.data.version,record.data.language,record.data.ext,value);
	}
	else
	{
	}
}

function renderLanguage(value, p, record){

	if(record.data.language != '')
	{
		return String.format(
            '<img src="./images/languages/{0}.png">&nbsp;<span>{1}</span>',
            record.data.language,record.data.languagedescr);
	}		

	return '';
}
 
MyDesktop.DownloadWindow = Ext.extend(Ext.app.Module, {
    id:'download-win',
    init : function(){
        this.launcher = {
            text: 'Download Window',
            iconCls:'download',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
    	
	    var expander = new Ext.grid.RowExpander({
	        tpl : new Ext.Template(
	            '<p><b>{product}&nbsp; {version}</b></p>',
	            '<p>{description}</p>'
	        )
	    });    	
    	
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('grid-win');
        if(!win){     	
        	
            win = desktop.createWindow({
                id: 'download-win',
                title:'Download Window',
                width:840,
                height:480,
                iconCls: 'download',
                shim:false,
                constrainHeader:true,
                animCollapse:true,
                collapsible: true,

                layout: 'fit',
                items:
                    new Ext.grid.GridPanel({
                        id:'gvDownload',                	
                        border:false,
                        plugins: expander,
                        ds: new Ext.data.Store({
                            reader: new Ext.data.ArrayReader({}, [
                               {name: 'product'},
                               {name: 'version'},
                               {name: 'language'},
                               {name: 'languagedescr'},
                               {name: 'releasedate'},
                               {name: 'os'},
                               {name: 'info'},
                               {name: 'description'},
                               {name: 'empty'},
                               {name: 'ext'},
							   {name: 'bIsDownload'},
							   {name: 'color'}
                            ]),
                            data: Ext.grid.downloadData
                        }),
                        cm: new Ext.grid.ColumnModel([
                            //new Ext.grid.RowNumberer(),
							expander,
							{header: "Download", width: 30, renderer: renderDownloadIcon, sortable: false, dataIndex: 'empty'},
                            {id:'product', header: "Product", width: 130, renderer: renderProduct, sortable: true, dataIndex: 'product'},
                            {header: "Ver.", width: 40, sortable: true, dataIndex: 'version'},
                            {header: "Language", width: 60, renderer: renderLanguage, sortable: true, dataIndex: 'languagedescr'},
                            {header: "Date", width: 60, sortable: true, dataIndex: 'releasedate'},
                            {header: "OS", width: 60, sortable: true, dataIndex: 'os'},
                            {header: "Info", width: 60, sortable: true, dataIndex: 'info'}
                        ]),

                        viewConfig: {
                            forceFit:true
                        }
/*                        ,
                        autoExpandColumn:'product'
*/                        
                    })
            });
        }
        win.show();
    }
});

// Array data for the grid
// es. beta ['esyPlanner','1.1_beta','eng',...
Ext.grid.downloadData = [
    ['esyPlanner','2.2.10.0121','eng','<b>english</b>','2010-01-21','Windows','freeware',
     'Revision history<br><br><font color=#880000>ver. 2.2.10.0121</font><br> automatic note save only if necessary;<br><br><font color=#880000>ver. 2.2.10.0120</font><br> bug fixed on row selection over a list view;<br> restored event resize in the planner view;<br> updated database engine;<br> added note clone function;<br><br><font color=#880000>ver. 2.2.10.0109</font><br> bug fixed on folder drag&drop inside notes tree view;<br> restored day selection in the planner view;<br><br><font color=#880000>ver. 2.2.10.0108</font><br> improved planner rendering<br><br><font color=#880000>ver. 2.2.09.1229</font><br> events are more visible inside the planner<br> added a color indication for a task status inside the notes panel;<br> graphic interface is now more suitable for resolution 1024x768<br><br><font color=#880000>ver. 2.2.09.1203</font><br> speed up startup loading time;<br> speed up searching process for yearly recurrences;<br> a better way to manage contacts informations<br> new print functionality inside warning panel and planner;<br><br><font color=#880000>ver. 2.1.09.1021</font><br> fixed bugs on recurrences with a maximum number of repetitions and recurrences with an ending date;<br> improved reminders for events and notes;<br> date format dd/mm/yyyy | mm/dd/yyyy;<br> time format 24 hours | 12 hours am/pm;<br> contacts dialog;',
     '','exe',true,''],     
    ['esyPlanner','2.2.10.0121','ita','<b>italiano</b>','2010-01-21','Windows','gratuito',
     'Revisioni<br><br><font color=#880000>ver. 2.2.10.0121</font><br> salvataggio automatico note solo se necessario;<br><br><font color=#880000>ver. 2.2.10.0120</font><br> risolto baco su selezione riga nelle liste;<br> ripristinato il ridimensionamento degli eventi nel planner;<br> aggiornato motore database;<br> aggiunta clonazione note;<br><br><font color=#880000>ver. 2.2.10.0109</font><br> risolto baco su drag&drop di cartelle nell&acute;albero delle note;<br> ripristinata la selezione di una giornata nel planner;<br><br><font color=#880000>ver. 2.2.10.0108</font><br> migliorato rendering del planner;<br><br><font color=#880000>ver. 2.2.09.1229</font><br> migliorata visibilitΰ eventi nel planner;<br> indicazione colorata dello stato delle attivitΰ nell&acute;albero delle note;<br> migliorato adattamento dell&acute;interfaccia alla risoluzione 1024x768<br><br><font color=#880000>ver. 2.2.09.1203</font><br> ridotti tempi di caricamento iniziale;<br> ridotti tempi di ricerca per ricorrenze annuali;<br> migliorata gestione contatti;<br> introdotte stampe nel pannello avvisi e nel planner;<br><br><font color=#880000>ver. 2.1.09.1021</font><br> fissati bachi su ricorrenze con numero max di ripetizioni e ricorrenze con data di fine;<br> migliorati avvisi per eventi e note;<br> formato data dd/mm/yyyy | mm/dd/yyyy;<br> formato ora 24 ore | 12 ore am/pm;<br> dialog contatti;',
     '','exe',true,''],
    ['Coming next ...','','','','','','',
     '<font color=#880000><b>esyCalService</b></font> an integrated .NET service to import / export calendars (ical format) or subscribe calendars on the web (ex. google calendar) or your local LAN',
     '','',false,'#880000'],
    ['Prossimamente ...','','','','','','',
     '<font color=#880000><b>esyCalService</b></font> un servizio .NET integrato per importare / esportare calendari (in formato ical) o sottoscrivere calendari sul web (es. google calendar) o in rete locale LAN',
     '','',false,'#880000']		 
/*	 
    ['Coming next ...','','','','','','',
     '<font color=#880000><b>esyCalService</b></font> an integrated .NET service to import / export calendars (ical format) or subscribe calendars on the web or your local LAN<br><br><font color=#880000><b>esyMobileProvider</b></font> a .NET provider to syncronize your mobile phone with esyPlanner 2',
     '','',false,'#880000'],
    ['Prossimamente ...','','','','','','',
     '<font color=#880000><b>esyCalService</b></font> un servizio .NET integrato per importare / esportare calendari (in formato ical) o sottoscrivere calendari sul web o in rete locale LAN<br><br><font color=#880000><b>esyMobileProvider</b></font> un provider .NET per sincronizzare il tuo cellulare con esyPlanner 2',
     '','',false,'#880000']	 
*/	 
];

/*
// add in some dummy descriptions
for(var i = 0; i < Ext.grid.downloadData.length; i++){
    Ext.grid.downloadData[i].push('inner text example');
}
*/

//]

//[esyPlanner

function renderImg(value, p, record){
    
	var b_myLightbox = false;
	
	try
	{
		b_myLightbox = myLightbox != undefined;
	}
	catch(e)
	{
	
	}
	
	if(b_myLightbox)
	{
		return String.format(
				'<b><a href="./products/esyPlanner/images/{0}" rel="lightbox[images]" onclick="myLightbox.start(this);return false;"><img src="./products/esyPlanner/images/{1}"></a></b>',
				record.data.imgBig,record.data.img);
	}
	else	
	{
		return String.format(
				'<b><a href="./products/esyPlanner/images/{0}"><img src="./products/esyPlanner/images/{1}"></a></b>',
				record.data.imgBig,record.data.img);		
	}
}

function renderDescription(value, p, record){
    return String.format(
            '<p style="white-space: normal;">{0}</p>',
            record.data.description);
}

MyDesktop.esyPlannerWindow = Ext.extend(Ext.app.Module, {
    id:'esyPlanner-win',
    init : function(){
        this.launcher = {
            text: 'esyPlanner',
            iconCls:'esyPlanner',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('esyPlanner-win');
        if(!win){
            win = desktop.createWindow({
                id: 'esyPlanner-win',
                title: 'esyPlanner ... your easy planner',
                width:600,
                height:400,
                iconCls: 'esyPlanner',
                shim:false,
                constrainHeader:true,
                animCollapse:true,
                collapsible: true,
                
                layout:'accordion',
                border:false,
                layoutConfig: {
                    animate:false
                },

                items: [   
	                    new Ext.grid.GridPanel({
	                        id:'esyPlannerEng',
	                        title: '<img src=\"./images/languages/eng.png\"><b>  english</b>',	                    	
	                        border:false,
	                        ds: new Ext.data.Store({
	                            reader: new Ext.data.ArrayReader({}, [
	                               {name: 'img'},
	                               {name: 'description'},
	                               {name: 'imgBig'}
	                            ]),
	                            data: Ext.grid.esyPlannerDataEng
	                        }),
	                        cm: new Ext.grid.ColumnModel([
	                            //new Ext.grid.RowNumberer(),
								{header: "", width: 150, renderer:renderImg , sortable: false, dataIndex: 'img'},
	                            {header: "Description", width: 395, renderer:renderDescription, sortable: false, dataIndex: 'description'}
	                        ]),
	
	                        viewConfig: {
	                            //forceFit:true
	                        }                      
	                    }),                            
	                    new Ext.grid.GridPanel({
	                        id:'esyPlannerIta',
	                        title: '<img src=\"./images/languages/ita.png\"><b><font color=#880000>  italiano</font></b>',	                    	
	                        border:false,
	                        ds: new Ext.data.Store({
	                            reader: new Ext.data.ArrayReader({}, [
	                               {name: 'img'},
	                               {name: 'description'},
	                               {name: 'imgBig'}
	                            ]),
	                            data: Ext.grid.esyPlannerDataIta
	                        }),
	                        cm: new Ext.grid.ColumnModel([
	                            //new Ext.grid.RowNumberer(),
								{header: "", width: 150, renderer:renderImg , sortable: false, dataIndex: 'img'},
	                            {header: "Descrizione", width: 395, renderer:renderDescription, sortable: false, dataIndex: 'description'}
	                        ]),
	
	                        viewConfig: {
	                            //forceFit:true
	                        }                      
	                    })
                ]
            });	
        }
        win.show();
    }
});

// Array data for the grid

Ext.grid.esyPlannerDataIta = [
    ['main.gif'
    ,'<font color=#880000><b>esyPlanner</b></font> θ un software <u>gratuito</u> che ti permette di raccogliere e gestire <b>note</b> ed <b>eventi</b>, registrare <b>spese</b> e <b>avvisi</b>.<br>Puoi salvare le tue <b>password</b> e scrivere il tuo <b>diario</b> quotidiano.<br><br>Installa esyPlanner sulla tua <b>chiavetta usb</b> e usarlo su qualsiasi computer (Windows) <u>senza reinstallarlo ogni volta</u>.'
    ,'main_big.gif'],
    ['note.gif'
    ,'Organizza le tue note in una gerarchia ad albero, contrassegnale con <b>colori</b> e <b>allarmi</b>.<br>Puoi associare ad una nota delle <b>immagini</b> (es. catturando immagini dal desktop con lo strumento di cattura immagini)'
    ,'note_big.gif'],
    ['warnings.gif'
    ,'Il pannello degli <b>allarmi</b> ti ricorda le prossime scadenze, gli eventi e gli allarmi che hai impostato.'
    ,'warnings_big.gif'],
    ['planner.gif'
    ,'Il pannello <b>planner</b> ti permette di registrare eventi con un calendario mensile delle attivitΰ.'
    ,'planner_big.gif'],
    ['search.gif'
    ,'<b>Ricerca</b> tra le note, nel planner, nel diario con estrema semplicitΰ e <b>stampa</b> dei report di ricerca.'
    ,'search_big.gif'],
    ['expenses.gif'
    ,'<b>Ricerca</b> tra le note spesa e controlla i totali.'
    ,'expenses_big.gif']
];

Ext.grid.esyPlannerDataEng = [
    ['main.gif'
    ,'<font color=#880000><b>esyPlanner</b></font> is a <u>freeware</u> software that allows you to manage your <b>tasks</b> and <b>calendar</b>, register <b>expenses</b>, save your <b>passwords</b> and write your daily <b>diary</b>.<br><br>Install esyPlanner on your <b>pen drive</b> and execute it on every computer (Windows) <u>without reinstall it each time</u>.'
    ,'main_big.gif'],
    ['note.gif'
    ,'Organize your notes in a tree view structure, assign them a <b>color</b> and <b>warnings</b>.<br>You can add <b>images</b> to a note (ex. capturing an image from the desktop using the capture image tool)'
    ,'note_big.gif'],
    ['warnings.gif'
    ,'The <b>warnings</b> panel shows you scheduled events and the warnings you set.'
    ,'warnings_big.gif'],
    ['planner.gif'
    ,'The <b>planner</b> panel allows you to register events with a calendar for the activities.'
    ,'planner_big.gif'],
    ['search.gif'
    ,'<b>Search</b> for notes, planner events and diary pages in a simple way and <b>print</b> a report.'
    ,'search_big.gif'],
    ['expenses.gif'
    ,'<b>Search</b> for expenses and check their sum.'
    ,'expenses_big.gif']
];

