var searchPanel;
var searchGrid;
var searchStore;
var eastSearchPanel;
var xxx = "xxx";

searchStore = new Ext.data.GroupingStore({
    proxy: new Ext.data.ScriptTagProxy({
        url: 'http://'+domain+'/sannop/',
		metod: 'GET'
    }),
    reader: new Ext.data.JsonReader({
        root: 'subjects',
        totalProperty: 'totalCount',
		id: 'uri'
    },[
        {name: 'name', mapping: 'name'},
        {name: 'type', mapping: 'type'},
		{name: 'uri', mapping: 'uri'},
		{name: 'classUri'}
    ]),
    sortInfo:{field: 'name', direction: "ASC"},
    groupField:'type'
});
searchInfoStore = new Ext.data.Store({
    proxy: new Ext.data.ScriptTagProxy({
        url: 'http://'+domain+'/sannop/',
		metod: 'GET'
    }),
    reader: new Ext.data.JsonReader({
        root: 'infos',
        totalProperty: 'totalCount',
		id:'value'
    },[
        {name: 'name', mapping: 'name'},
        {name: 'value', mapping: 'value'}
    ])
});
Ext.onReady(function(){
	//var ssMask = new Ext.LoadMask(Ext.getBody(), {store:searchStore, msg:'정보 가져오는중...'});
    searchGrid = new Ext.grid.GridPanel({
        store: searchStore,
        columns: [
            {id:'uri',header: "Name", width:260, sortable: true, dataIndex: 'name'},
            {header: "Type", width:150, sortable: true, dataIndex: 'type'},
			{header: "URI", width:110, sortable: true, dataIndex: 'uri'}
        ],
		loadingText: 'Searching...',
        view: new Ext.grid.GroupingView({
            forceFit:true,
            groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
        }),
        frame:false,
		width:420,
        height: 150,
		region: 'center',
        collapsible: true,
        animCollapse: false,
        title: 'Subject 리스트',
		autoResize: true
    });
	searchGrid.on("cellclick", cellclickEvent);
	//searchGrid.render('search_grid');
	//var lmSubjectInfoStore = new Ext.LoadMask(Ext.getBody(), {store:searchInfoStore, msg:'정보 가져오는중...'});
	eastSearchPanel = new Ext.grid.GridPanel({
	        store: searchInfoStore,
	        columns: [
	            {id:'name',header: "Name", width:120, sortable: true, dataIndex: 'name'},
				{header: "Value", width:140, sortable: true, dataIndex: 'value'}
	        ],
			width: 260,
	        stripeRows: true,
	        autoExpandColumn: 'name',
	        title:'Property',
            region      : 'east',
            split       : true,
            collapsible : true
	    });
	//eastSearchPanel.render('east_search');
	var searchPanel = new Ext.Panel({
		width:680,
		height:200,
		layout: 'border',
		defaults: {
			collapsible: true,
			split: true,
			bodyStyle: 'padding:15px'
		},
		items: [searchGrid, eastSearchPanel]
	});
	searchPanel.render("searcht");	
});

function searchTriple(keyword) {
	searchStore.load({
		params: {
			method: 'sannop.kbi.subject.getList',
			name: keyword
		}
	});	
}
cellclickEvent = function(grid, rowIndex, columnIndex, e) {
	var data = grid.getSelectionModel().getSelected().data;
	eastSearchPanel.expand(true);
	var uri = "";
	if (data.uri[0] == 'h')
	{
		uri = data.uri;
	} else {
		uri = namespaces.slx+data.uri;
	}
	searchInfoStore.load({
		params: {
			method: 'sannop.kbi.subject.getInfo',
			uri: uri
		}
	});
}



