/*!
 * Ext JS Library 3.1.0
 * Copyright(c) 2006-2009 Ext JS, LLC
 * licensing@extjs.com
 * http://www.extjs.com/license
 */

// Sample desktop configuration
MyDesktop = new Ext.app.App({
	init :function(){
		Ext.QuickTips.init();
	},

	getModules : function(){
		return [
			new MyDesktop.GridWindow(),
            new MyDesktop.TabWindow(),
            new MyDesktop.AccordionWindow(),
            new MyDesktop.ImportanteWnd(),
			new MyDesktop.BibliotecaWnd
		];
	},

    // config for the start menu
    getStartConfig : function(){
        return {
            title: 'Invitado',
            iconCls: 'user',
            toolItems: [{
                text:'Config',
                iconCls:'settings',
                scope:this
            },'-',{
                text:'Salir',
                iconCls:'logout',
                scope:this
            }]
        };
    }
});



/*
 * Example windows
 */
 
 
/***************************************************************/
MyDesktop.BibliotecaWnd = Ext.extend(Ext.app.Module, {
    id:'biblio-win',
    init : function(){		
        this.launcher = {
            text: 'Biblioteca',
            iconCls:'tabs',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
		var tree = new Ext.tree.TreePanel({  	
			region:'west',
			title:'Documentos',
			width:250,
			split:true,
			collapsible:true,
			border: false,
			autoScroll:true,
			dataUrl:'leer-archivos.php',
			root: new Ext.tree.AsyncTreeNode({
				id:'.',
				text: 'Categorías',
				expanded:true
			})
		});
		
		var main = new Ext.Panel({
			region:'center',
			layout:'fit',
			border:false
		});
		
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('biblio');
        if(!win){
            win = desktop.createWindow({
                id: 'biblio',
                title:'Biblioteca Cristiana en línea | La Gracia Soberana',
				layout:'border',
                width:700,
                height:450,
				maximizable: true,
                iconCls: 'tabs',
                shim:false,
                animCollapse:false,

				items: [tree,main]
            });
        }
        win.show();
		
		tree.on('click',function(node){
			var el = Ext.get(Ext.DomQuery.select('.x-panel-body',main.el.dom)[0]);
			while (el.dom.childNodes[0]){
				el.dom.removeChild(el.dom.childNodes[0]);
			}
			el.createChild({
				tag:'iframe',
				src:'.archivos/'+node.id,
				style:'border:none;width:100%;height:100%;'
			});
		});
    }
});
/***************************************************************/

MyDesktop.GridWindow = Ext.extend(Ext.app.Module, {
    id:'grid-win',
    init : function(){
        this.launcher = {
            text: 'Contenido del sitio',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('grid-win');
        if(!win){
            win = desktop.createWindow({
                id: 'grid-win',
                title:'Contenido del sitio',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items:
                    new Ext.grid.GridPanel({
                        border:false,
                        ds: new Ext.data.Store({
                            reader: new Ext.data.ArrayReader({}, [
                               {name: 'categoria'},
                               {name: 'contenido', type: 'float'},
                               {name: 'comentarios', type: 'float'},
                               {name: 'descargas', type: 'float'}
                            ]),
                            data: Ext.grid.dummyData
                        }),
                        cm: new Ext.grid.ColumnModel([
                            new Ext.grid.RowNumberer(),
                            {header: "Categoría", width: 120, sortable: true, dataIndex: 'categoria'},
                            {header: "Contenido", width: 70, sortable: true, dataIndex: 'contenido'},
                            {header: "Comentarios", width: 70, sortable: true, dataIndex: 'comentarios'},
                            {header: "Descargas", width: 70, sortable: true, dataIndex: 'descargas'}
                        ]),

                        viewConfig: {
                            forceFit:true
                        },
                        //autoExpandColumn:'company',

                        
                    })
            });
        }
        win.show();
    }
});



MyDesktop.TabWindow = Ext.extend(Ext.app.Module, {
    id:'tab-win',
    init : function(){
        this.launcher = {
            text: 'Contacto y comentarios',
            iconCls:'tabs',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('tab-win');
        if(!win){
            win = desktop.createWindow({
                id: 'tab-win',
                title:'Contacto y Comentarios',
                width:740,
                height:480,
                iconCls: 'tabs',
                shim:false,
                animCollapse:false,
                border:false,
                constrainHeader:true,

                layout: 'fit',
                items:
                    new Ext.TabPanel({
                        activeTab:0,

                        items: [{
                            title: 'Contacto',
                            header:false,
                            html : '<p>En construcción</p>',
                            border:false
                        },{
                            title: 'Leer libro de visitas',
                            header:false,
                            html : '<iframe src="http://gbooks1.melodysoft.com/app?ID=gracia" style="width:100%;height:100%;" frameborder=0 scrolling="auto"></iframe>',
                            border:false
                        },{
                            title: 'Escribir libro de visitas',
                            header:false,
                            html : '<iframe src="http://gbooks1.melodysoft.com/app?ID=gracia&amp;do=sign" style="width:100%;height:100%;" frameborder=0 scrolling="auto"></iframe>',
                            border:false
                        }]
                    })
            });
        }
        win.show();
    }
});



MyDesktop.AccordionWindow = Ext.extend(Ext.app.Module, {
    id:'acc-win',
    init : function(){
        this.launcher = {
            text: 'Accordion Window',
            iconCls:'accordion',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('acc-win');
        if(!win){
            win = desktop.createWindow({
                id: 'acc-win',
                title: 'Accordion Window',
                width:250,
                height:400,
                iconCls: 'accordion',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                tbar:[{
                    tooltip:{title:'Rich Tooltips', text:'Let your users know what they can do!'},
                    iconCls:'connect'
                },'-',{
                    tooltip:'Add a new user',
                    iconCls:'user-add'
                },' ',{
                    tooltip:'Remove the selected user',
                    iconCls:'user-delete'
                }],

                layout:'accordion',
                border:false,
                layoutConfig: {
                    animate:false
                },

                items: [
                    new Ext.tree.TreePanel({
                        id:'im-tree',
                        title: 'Online Users',
                        loader: new Ext.tree.TreeLoader(),
                        rootVisible:false,
                        lines:false,
                        autoScroll:true,
                        tools:[{
                            id:'refresh',
                            on:{
                                click: function(){
                                    var tree = Ext.getCmp('im-tree');
                                    tree.body.mask('Loading', 'x-mask-loading');
                                    tree.root.reload();
                                    tree.root.collapse(true, false);
                                    setTimeout(function(){ // mimic a server call
                                        tree.body.unmask();
                                        tree.root.expand(true, true);
                                    }, 1000);
                                }
                            }
                        }],
                        root: new Ext.tree.AsyncTreeNode({
                            text:'Online',
                            children:[{
                                text:'Friends',
                                expanded:true,
                                children:[{
                                    text:'Jack',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Brian',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Jon',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Tim',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Nige',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Fred',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Bob',
                                    iconCls:'user',
                                    leaf:true
                                }]
                            },{
                                text:'Family',
                                expanded:true,
                                children:[{
                                    text:'Kelly',
                                    iconCls:'user-girl',
                                    leaf:true
                                },{
                                    text:'Sara',
                                    iconCls:'user-girl',
                                    leaf:true
                                },{
                                    text:'Zack',
                                    iconCls:'user-kid',
                                    leaf:true
                                },{
                                    text:'John',
                                    iconCls:'user-kid',
                                    leaf:true
                                }]
                            }]
                        })
                    }), {
                        title: 'Settings',
                        html:'<p>Something useful would be in here.</p>',
                        autoScroll:true
                    },{
                        title: 'Even More Stuff',
                        html : '<p>Something useful would be in here.</p>'
                    },{
                        title: 'My Stuff',
                        html : '<p>Something useful would be in here.</p>'
                    }
                ]
            });
        }
        win.show();
    }
});

// for example purposes
MyDesktop.ImportanteWnd = Ext.extend(Ext.app.Module, {
    init : function(){
        this.launcher = {
            text: 'Importante',
            iconCls:'bogus',
            handler : this.createWindow,
            scope: this,
            //windowId:windowIndex
        }
    },

    createWindow : function(src){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('importante');
        if(!win){
            win = desktop.createWindow({
                id: 'importante',
                title:'Aclaración',
                width:640,
                height:250,
                html : '<br /><h1 align=center>La experiencia incomparable de conocer la Verdad del único Evangelio</h1><p>El propósito de esta página es el de hacer disponible al público en general literatura que va de acuerdo con la sana doctrina expuesta en la Biblia y delineada en nuestra confesión de fe. Esperamos que sea de beneficio para el que posee un espíritu de amor para la verdad que rompe las cadenas de la ignorancia y del pecado.</p><br /><div align=center><font color=blue>Nota importante:</font></div><p>Los Editores de esta página no estamos de acuerdo con todo el contenido de los libros y artículos disponibles en este sitio. Sin embargo, reconocemos que contienen muchas verdades maravillosas, algunas de las cuales serán revolucionarias para muchos lectores. Confiamos en que el Espíritu de Dios sea nuestro maestro y revelador de toda verdad.</p><br /><div align=right>José L. Rizo Martínez &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>',
                iconCls: 'bogus',
                shim:false,
                animCollapse:false,
                constrainHeader:true
            });
        }
        win.show();
    }
});


// Array data for the grid
Ext.grid.dummyData = [
    ['Artículos',0,0,0],
    ['Bautismo',0,0,0],
    ['Comentarios',0,0,0],
    ['Confesiones de Fe',0,0,0],
    ['Creación',0,0,0],
    ['Enciclopedias',0,0,0],
    ['Escatología',0,0,0],
    ['Escrituras',0,0,0],
    ['Evangelio',0,0,0],
    ['Himnología',0,0,0],
    ['Historia y Reforma',0,0,0],
    ['Novelas',0,0,0],
    ['Oración',0,0,0],
    ['Pentecostalismo',0,0,0],
    ['Predicador',0,0,0],
    ['Reino',0,0,0],
    ['Sectas',0,0,0],
    ['Sermones',0,0,0],
    ['Sobre esta Piedra',0,0,0],
    ['Soteriología',0,0,0],
	['Spurgeon',0,0,0],
	['Teología sistemática',0,0,0],
	['Teología del Nuevo Pacto',0,0,0],
	['Tratados',0,0,0],
	['Vida Cristiana',0,0,0]
];