DNS.Pesquisas.MarcasDominiosPT = Ext.extend(Ext.form.FormPanel, {

    frame: false,
    border: false,
    autoWidth: true,
    autoHeight: true,
    bodyStyle: 'padding-top: 20px; padding-left: 15px; padding-right: 15px; padding-bottom: 10px;',
    
    constructor: function(config){
		
        var self = this;

        this.nome = new DNS.Pesquisas.TextField({
            maxLength: 130,
            allowBlank: false,
            fieldLabel: DNS.lblTextField,
            width: 280,
            name: 'nome_marca'
        });

        this.pesquisar = new Ext.Button({
            text: DNS.lblPesquisar,
            iconCls: 'registos-online-button-search-icn',
            handler: this.doPesquisar,
            scope: this
        });

        this.store = new Ext.ux.data.PagingStore({
            proxy: new Ext.data.HttpProxy({
                //url: '/pesquisas/DominiosNome',
                url: 'http://onlineservices.dns.pt/pesquisas/servlet/DominiosNome',
                method: 'POST'
            }),
            lastOptions: {
                params:{
                    start: 0,
                    limit: 10
                }
            },

            reader: new Ext.data.XmlReader({
                //totalRecords: 'results',
                record: 'PROCESSO',
                //id: 'NUMERO'

                fields: [{
                    name: 'SITUACAO'
                }, {
                    name: 'NUMERO',
                    type: 'float'
                }, {
                    name: 'SINAL'
                }, {
                    name: 'DATA_PEDIDO',
                    type: 'date',
                    dateFormat: 'd-m-Y'
                }, {
                    name: 'URL'
                }]
            })
        });

        this.store2 = new Ext.ux.data.PagingStore({
            proxy: new Ext.data.HttpProxy({
                url: 'http://onlineservices.dns.pt/pesquisas/servlet/MarcasNome',
                method: 'POST'
            }),
            lastOptions: {
                params:{
                    start: 0,
                    limit: 10
                }
            },

            reader: new Ext.data.XmlReader({
                //totalRecords: 'results',
                record: 'PROCESSO',
                //id: 'NUMERO'
	            
                fields: [{
                    name: 'NOME'
                }, {
                    name: 'HIERARQUIA'
                }, {
                    name: 'SITUACAO'
                }, {
                    name: 'DATA',
                    type: 'date',
                    dateFormat: 'd-m-Y'
                }, {
                    name: 'URL'
                }]
            })
        });
		
        this.pagbar = new Ext.PagingToolbar({
            pageSize: 10,
            store: this.store,
            displayInfo: true,
            displayMsg: DNS.lblProcesso,
            emptyMsg: DNS.lblMsgVazia
        });
        
        this.gridSm = new Ext.grid.RowSelectionModel({
            singleSelect: 'true'
        });
        
        this.gridId = Ext.id();
        this.gridCf = {
            xtype: 'grid',
            title: DNS.lblGrid1Titulo,
            id: this.gridId,		
            store: this.store,
            bbar: this.pagbar,
            autoWidth: true,
            viewConfig: {
                autoFill: true,
                forceFit: true
            },
            width: 730,
            height: 308,
            frame: 'true',
            enableColumnMove: true,
            enableColumnResize: true,
			
            loadMask: {
                msg: DNS.lblCarregar,
                msgCls: 'x-mask-loading'
            },
            
            columns: [{
                id: 'numero_marca',
                align: 'left',
                header: DNS.lblNumeroProcesso,
                width: 60,
                dataIndex: 'NUMERO',
                sortable: true
            //
            //renderer: function change(value, metada, record, rowIndex, colIndex, store){
            //    return '<div text-align="left"><a target=_blank href="'+record.get('URL')+'">'+value+'</a></div>';
            //}
								
            }, {
                id: 'sinal_marca',
                align: 'left',
                header: DNS.lblNomeMarca,
                width: 160,
                dataIndex: 'SINAL',
                sortable: true,
                renderer: function change(value, metada, record, rowIndex, colIndex, store){
                    return '<div text-align="left"><a target=_blank href="'+record.get('URL')+'">'+value+'</a></div>';
                }				
            }, {
                id: 'situacao_marca',
                align: 'left',
                header: DNS.lblSituacao,
                width: 120,
                dataIndex: 'SITUACAO',
                sortable: true
            }, {
                id: 'data_pedido_marca',
                align: 'left',
                header: DNS.lblDataPedido,
                width: 60,
                dataIndex: 'DATA_PEDIDO',
                sortable: true,
                renderer: Ext.util.Format.dateRenderer('d-m-Y')
            }],
            autoExpandColumn: 'sinal_marca',
            sm: this.gridSm,
            stripeRows: true,
            listeners: {
                afterrender: {
                    scope: this,
                    fn: function(component){
                        component.getBottomToolbar().refresh.hideParent = true;
                        component.getBottomToolbar().refresh.hide();
                    }
                }
            }
        };

        this.pagbar2 = new Ext.PagingToolbar({
            pageSize: 10,
            store: this.store2,
            displayInfo: true,
            displayMsg: DNS.lblProcesso,
            emptyMsg: DNS.lblMsgVazia
        });
        
        this.gridSm2 = new Ext.grid.RowSelectionModel({
            singleSelect: 'true'
        });
        
        this.gridId2 = Ext.id();
        this.gridCf2 = {
            xtype: 'grid',
            title: DNS.lblGrid2Titulo,
            id: this.gridId2,		
            store: this.store2,
            bbar: this.pagbar2,
            autoWidth: true,
            viewConfig: {
                autoFill: true,
                forceFit: true
            },
            width: 730,
            height: 308,
            frame: 'true',
            enableColumnMove: true,
            enableColumnResize: true,
            loadMask: {
                msg: DNS.lblCarregar,
                msgCls: 'x-mask-loading'
            },
            columns: [ {
                id: 'hierarquia_nome',
                align: 'left',
                header: DNS.lblHierarquia,
                width: 60,
                dataIndex: 'HIERARQUIA',
                sortable: true
            }, {
                id: 'nome_dominio',
                align: 'left',
                header: DNS.lblNomeDominio,
                width: 160,
                dataIndex: 'NOME',
                sortable: true,
                renderer: function change(value, metada, record, rowIndex, colIndex, store){
                    return '<div text-align="left"><a target=_blank href="'+record.get('URL')+'">'+value+'</a></div>';
                }
								
            },{
                id: 'situacao_nome',
                align: 'left',
                header: DNS.lblSituacao,
                width: 120,
                dataIndex: 'SITUACAO',
                sortable: true
            }, {
                id: 'data_pedido_nome',
                align: 'left',
                header: DNS.lblDataPedido,
                width: 60,
                dataIndex: 'DATA',
                sortable: true,
                renderer: Ext.util.Format.dateRenderer('d-m-Y')
            }],
            autoExpandColumn: 'nome_dominio',
            sm: this.gridSm2,
            stripeRows: true,
            listeners: {
                afterrender: {
                    scope: this,
                    fn: function(component){
                        component.getBottomToolbar().refresh.hideParent = true;
                        component.getBottomToolbar().refresh.hide();
                    }
                }
            }
        };
		
        config = Ext.apply({
            labelWidth: 200,
            url: DNS.Pesquisas.Config.serverController,
            //defaultType: 'textfield',
            monitorValid: true,
            items: [
            {
                xtype: 'panel',
                layout: 'column',
                border: false,
                items: [
                {
                    xtype: 'fieldset',
                    border: false,
                    items: this.nome,
                    bodyStyle: 'padding-right: 20px;'
                }
                ,this.pesquisar]
            },
            {
                xtype: 'panel',
                border: false,
                frame: false,
                height: 5
            }, this.gridCf, {
                xtype: 'panel',
                border: false,
                frame: false,
                height: 10
            },
            this.gridCf2],
            buttonAlign: 'left'
        }, config);
        DNS.Pesquisas.MarcasDominiosPT.superclass.constructor.call(this, config);
		
    },
    
    doPesquisar: function(){
        if (this.validateForm()) {
			
            delete this.store.lastParams;
            this.store.baseParams = {
                nome: this.nome.getValue()
            };

            delete this.store2.lastParams;
            this.store2.baseParams = {
                nome: this.nome.getValue()
            //nome: 'anacom'
            };

            //this.getEl().mask(DNS.lblCarregar, 'x-mask-loading');
            this.store.load({
                params: {
                    start: 0,
                    limit: 10
                },
                callback: this.storeclb,
                scope: this
            });
		
            this.store2.load({
                params: {
                    start: 0,
                    limit: 10
                },
                callback: this.store2clb,
                scope: this
            });
						
        }
    },
	
    storeclb: function(r, option, success){
        if (success) {
        // all ok
        } else {
            Ext.getCmp(this.gridId).getEl().unmask();
            this.store.removeAll();
            Ext.Msg.alert(DNS.lblAtencao, DNS.lblErroPesquisaMarcas);
        }
    //this.getEl().unmask();
    },

    store2clb: function(r, option, success){
        if (success) {
        // all ok
        } else {
            Ext.getCmp(this.gridId2).getEl().unmask();
            this.store2.removeAll();
            Ext.Msg.alert(DNS.lblAtencao, DNS.lblErroPesquisaDominios);
        }
    //this.getEl().unmask();
    },
	   
    validateForm: function(){

        if (!this.getForm().isValid()) {
            Ext.Msg.alert(DNS.lblAtencao, DNS.lblAviso1);
            return false;
        }
		
        return true;
    }
    
});
Ext.reg('marcas-dominiospt', DNS.Pesquisas.MarcasDominiosPT);

var Main = new DNS.Pesquisas.MarcasDominiosPT({
    id: 'marcas-dominios',
    height: 664
});

// application main entry point
Ext.onReady(function() {
 
    Ext.QuickTips.init();
    //Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

    // Apply a set of config properties to the singleton
    Ext.apply(Ext.QuickTips.getQuickTip(), {
        maxWidth: 200,
        minWidth: 100,
        showDelay: 50,
        dismissDelay: 15000,
        hideDelay: 1,
        trackMouse: true
    });
	
    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

    limpaContexto();
    Main.render('ropanel');
		
}); 
// eo function onReady
		