/*

 var testjsondata =
 [
 {
 'uri-uuid' : '/addama-rest/clark-repo2/uuid/e7cd5f48-c2b1-4bca-9ea2-692e6b17c5c6',
 'repository' : 'clark-repo2',
 'name' : 'Biological Reagents',
 'path' : '/sampleData/Biological Reagents',
 'isFile' : 'fdf',
 'host-url' : 'http://orzo:8080',
 'uri' : '/addama-rest/clark-repo2/path/sampleData/Biological Reagents'
 },
 {
 'uri-uuid' : '/addama-rest/clark-repo2/uuid/7a11f70e-3c1d-4c89-8249-19bff82cdb8c',
 'repository' : 'clark-repo2',
 'name' : 'microarray',
 'path' : '/sampleData/microarray',
 'isFile' : 'false',
 'host-url' : 'http://orzo:8080',
 'uri' : '/addama-rest/clark-repo2/path/sampleData/microarray'
 }
 ];

 var propertyStore = new Ext.data.JsonStore({
 storeId:"stuff",
 method:'GET',
 url: "/addama-rest/clark-repo2/path/sampleData/microarray/NamingSchemes/Aderem Expression/namingScheme/dir",
 root: "children",
 fields: ["uri-uuid","repository","name","path","isFile","host-url","uri"],
 sortInfo: {field: "uri-uuid",direction:"ASC"}
 });
 */


ExonArray = function()
{
    var getAccordionPanel = function(namingSchemeFactory) {
        var accordion = new Ext.Panel({
            layoutConfig: {
                animate: true
            },
            layout:'accordion',
            autoWidth:true,

            items: [
                {
                    title: 'Info',
                    autoHeight:true,
                    html: "Info"
                },
                {
                    title: 'Basic Search',
                    autoHeight:true,
                    html: 'sample text'
                },
                {
                    title: 'Search by Aderem Expression Array Metadata',
                    height:400,
                    autoHeight:true,
                    //html: searchHtml
                    items:[namingSchemeFactory.getSearchForm()]
                },
                {
                    title: 'Display All Aderem Expression Exon Samples',
                    autoHeight:true,
                    html: '<p>Panel content!<br>b<br>b<br>b<br>'
                }]
        });
        return  accordion;
    }


    var getSearchTablePanel = function() {
        var Grid1Store = new Ext.data.JsonStore({
            root: 'users',
            fields: [ 'id', 'name', 'email' ],
            autoLoad: true,
            data: { users: [
                { "id": 1, "name":"John Smith", "email":"jsmith@example.com"},
                { "id": 2, "name":"Anna Smith", "email":"asmith@example.com"},
                { "id": 3, "name":"Peter Smith", "email":"psmith@example.com"},
                { "id": 4, "name":"Tom Smith", "email":"tsmith@example.com"}
            ]}
        });

        var grid = new Ext.grid.GridPanel({
            store: Grid1Store,
            title: 'Search Results',
            height:400,
            id:'SearchResults',
            viewConfig:{forceFit:true},
            columns: [
                {
                    id: 'name',
                    header: "Name",
                    sortable: true,
                    dataIndex: 'name'
                },{
                id: 'email',
                header: "Email",
                sortable: true,
                dataIndex: 'email'
            }
            ],
            autoExpandColumn: 'email',
            border: true});
        return grid;
    }

    var getSelectedResultsPanel = function() {

        var Grid1Store = new Ext.data.JsonStore({
            root: 'users',
            fields: [ 'id', 'name', 'email' ],
            autoLoad: true,
            data: { users: [
                { "id": 1, "name":"John Smith", "email":"jsmith@example.com"},
                { "id": 2, "name":"Anna Smith", "email":"asmith@example.com"},
                { "id": 3, "name":"Peter Smith", "email":"psmith@example.com"},
                { "id": 4, "name":"Tom Smith", "email":"tsmith@example.com"}
            ]}
        });

        var grid = new Ext.grid.GridPanel({
            store: Grid1Store,
            viewConfig:{forceFit:true},
            title: 'Selected Search Results',
            id:'SelectedSearchResults',
            height:400,
            columns: [
                {
                    id: 'name',
                    header: "Name",
                    sortable: true,
                    dataIndex: 'name'
                },{
                id: 'email',
                header: "Email",
                sortable: true,
                dataIndex: 'email'
            }
            ],
            autoExpandColumn: 'email',
            border: true});
        return grid;
    }


    return {

        init: function()
        {


            new Ajax.Request("/addama-rest/clark-repo2/path/sampleData/microarray/NamingSchemes/Aderem Expression/",
            {
                method: "get",
                onSuccess: function(response) {
                    var json = Ext.util.JSON.decode(response.responseJSON.namingSchemeJSON);
                    var namingSchemeFactory = new NamingSchemeItemSelector(json.namingScheme);

                    new Ext.Viewport({
                        layout: 'border',
                        items:[
                            {
                                region:'west',
                                title:"Search",
                                split:true,
                                width:360,
                                items: [getAccordionPanel(namingSchemeFactory)]
                            },
                            {
                                region:'center',
                                width:600,
                                items: [getSearchTablePanel(),getSelectedResultsPanel()]
                            }
                        ]
                    })
                }
            });


        }
    }
}();