Ext.namespace('opencarto.layerControl');
opencarto.layerControl.load = function(){
 var reader = new Ext.data.JsonReader({}, [
                {name: 'options.layerid'},
                {name: 'name'},
                {name: 'label'},
                {name: 'options.groupname'},
                {name: 'options.rang'},
                {name: 'options.grouporder'},
                {name: 'options.visibility'},
                {name: 'options.exporter'},
                {name: 'options.typegeo'},
                {name: 'options.sldFiles'},
                {name: 'options.opacity'},
                {name: 'options.search'},
                {name: 'options.editable'},
                {name: 'options.showInLegend'}
                
             ]);
            opencarto.layerStore = new Ext.data.GroupingStore({
                reader: reader,
                data: opencarto.gisobjects.layers,
                sortInfo:{field: 'options.rang', direction: "ASC"},
                groupField:'options.grouporder'
                
            });
            opencarto.layerStore.filter('options.showInLegend',true);
            var visibilityColumn = new Ext.grid.CheckColumn({
                header: "",
                dataIndex: 'options.visibility',
                menuDisabled:true,
                width: 2,
                hidden:false,
                sortable: false,
                resizable:true
             });

            opencarto.sm = new Ext.grid.RowSelectionModel({ singleSelect:true});
            opencarto.layercm = new Ext.grid.ColumnModel([
                visibilityColumn,
                {id:'id',header: "ID", width: 60, hidden:true, sortable: false, dataIndex: 'options.layerid'},
                
                {id:'name',header: "Nom", width: 60, hidden:true, sortable: false, dataIndex: 'name'},
                {header: "Nom de la couche",  menuDisabled:true,sortable: false, dataIndex: 'label', renderer: Ext.util.Format.capitalize, tooltip:'Liste des couches disponibles'},
                {header: "Groupe", width: 20, hidden:true, sortable: false,  dataIndex: 'options.groupname'},
                {header: "Rang", width: 20, hidden:true, sortable: false, dataIndex: 'options.rang'},
                {header: "Catégorie", width: 20, hidden:true, sortable: false, dataIndex: 'options.grouporder'},
                {header: "Exporter", width: 20, hidden:true, sortable: false, dataIndex: 'options.exporter'},
                {header: "Type", width: 20, hidden:true, sortable: false, dataIndex: 'options.typegeo'},
                {header: "sldFiles", width: 20, hidden:true, sortable: false, dataIndex: 'options.sldFiles'},
                {header: "opacity", width: 20, hidden:true, sortable: false, dataIndex: 'options.opacity'},
                {header: "search", width: 20, hidden:true, sortable: false, dataIndex: 'options.search'}
                ]);
            opencarto.layerGrid = new Ext.grid.EditorGridPanel({
                
            store: opencarto.layerStore,
            cm: opencarto.layercm,
            sm:opencarto.sm,
            plugins:visibilityColumn,

            view: new Ext.grid.GroupingView({
                forceFit:true,
                startCollapsed:false,
                groupTextTpl: '{[Ext.util.Format.capitalize(values.rs[0].data["options.groupname"])]}'
            }),
            autoHeight:true,
	    autoScroll:true,
            autoExpandColumn:'label',
            width:260,
            frame:false,
            border:true,
            hideGroupedColumn:true,
            collapsible: true,
            title: 'Affichage',
            animCollapse: true,
            enableColLock: false,
            iconCls: 'layerList',
            loadMask: true,
		stripeRows:true,
            listeners: {
                      rowcontextmenu:opencarto.onContextClick
                }
            });
            
            opencarto.layerGrid.getSelectionModel().on(
                'rowselect',opencarto.layerSelect
            );
            opencarto.layerGrid.getSelectionModel().on(
                'rowdeselect',opencarto.layerSelect
            );

            
            
            opencarto.leftPanel.insert(0,opencarto.layerGrid);
            opencarto.leftPanel.doLayout();
}    
