/**
 * query.js
 */

Ext.Loader.setConfig({
    enabled: true
});
Ext.Loader.setPath('Ext.ux', '../../res/extjs/examples/ux');

Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.ux.RowExpander',
    'Ext.selection.CheckboxModel'
]);

var myStore;
var baseUrl;
var level;
var dwtype;
var objid;
var theme;
var pieMask;
var company_code;
var maxHeight = 10000;
var maxWidth = 10000;
var V_LOGINNAME = "";

var sm = Ext.create('Ext.selection.CheckboxModel');


Ext.define('queryOption',{
	extend: 'Ext.data.Model',
	fields: [
		{ name:'id', type:'int'},
		{ name:'name',	type:'string' },
		{ name:'status',	type:'string' },
		{ name:'device_code',	type:'string' },
		{ name:'company_code',	type:'string' },
		{ name:'company_name',	type:'string' },
		{ name:'fullname', type:'string' },
		{ name:'time', type:'string' },
		{ name:'data', type:'string' },
		{ name:'data2', type:'string' },
		{ name:'clzt', type:'string' },
		{ name:'clr_name', type:'string' },
		{ name:'clnr', type:'string' },
		{ name:'clsj', type:'string' }
	]
});

var body_resize = function(){
	maxHeight =  document.documentElement.clientHeight;
	maxWidth = document.documentElement.clientWidth;
	Ext.getCmp('queryPanel').setHeight(maxHeight);
	Ext.getCmp('queryPanel').setWidth(maxWidth);
}

Ext.onReady(function(){  
	baseUrl = document.getElementById('basePath').value;
	theme = document.getElementById('theme').value;
	dwtype= document.getElementById('dwtype').value;
	level = document.getElementById('level').value;
	objid = document.getElementById('objid').value;
	company_code = document.getElementById('company_code').value;
	$("#V_LOGINNAME").val(sessionStorage.getItem('V_LOGINNAME'));
	V_LOGINNAME = $("#V_LOGINNAME").val();
	var queryJson = new Object();
	queryJson.dwtype = dwtype;
	queryJson.level = level;
	queryJson.objid = objid;
	queryJson.company_code = company_code;
	queryJson.V_LOGINNAME = V_LOGINNAME;
	myStore = Ext.create('Ext.data.Store', {
	    model: 'queryOption',
	    pageSize: 5, 
	    proxy: {
	        type: 'ajax',
	        actionMethods: {
                create : 'POST',
                read   : 'POST', // by default GET
                update : 'POST',
                destroy: 'POST'
	        },
	        url: baseUrl+'iot/frontpage/getAlarmList',
	        reader: {
	            type: 'json',
	            root: 'RESULT',
	            totalProperty: 'totalCount'
	        },
	        extraParams:{
	        	queryJson:Ext.JSON.encode(queryJson)
	        }
	    },
	    sorters:[{
	    	property:'time',
	    	direction:'DESC'
	    }],
	    remoteSort: true
	});
	var storeReload=function(){
		var queryJson = new Object();
		queryJson.dwtype = dwtype;
		queryJson.level = level;
		queryJson.objid = objid;
		queryJson.company_code = company_code;
		myStore.getProxy().extraParams = {queryJson:Ext.JSON.encode(queryJson)};
		myStore.reload();
		setTimeout(storeReload,30000);
	}
	
	var storeReload2=function(){
		var queryJson = new Object();
		queryJson.dwtype = dwtype;
		queryJson.level = level;
		queryJson.objid = objid;
		queryJson.company_code = company_code;
		myStore.getProxy().extraParams = {queryJson:Ext.JSON.encode(queryJson)};
		myStore.reload();
	}
 
	var proLevelGrid = Ext.create('Ext.grid.Panel', {
		header :{
			height:0,
			border:'0px solid #000000'
		},
	    titleCollapse:true,
	    id: 'queryPanel',
	    cellTip:true,
