﻿/// <reference path="http://www-app.gdepb.gov.cn/ext-2.2/vswd-ext_2.1.js" />
Ext.namespace('EQPublish');

EQPublish.ChartWindow = Ext.extend(Ext.Window, {
	//type: 'd', //默认为 d (天)，可以输入y (年),mo(月)
	startTime: new Date().add('d', -1),
	endTime: new Date(),
	ascxHandlerUrl: '',
	chartHandlerUrl: '',
	ID: '',
	initComponent: function() {
		Ext.apply(this, {
			//id: 'mywindows',
			closeAction: 'hide',
			width: 500,
			height: 436,
			resizable: false,
			tbar: [
				'开始时间：',
				{ id: 'startTime', format: 'Y-m-d', value: this.startTime, xtype: 'datefield', maxValue: this.endTime },
				'结果时间：',
				{ id: 'endTime', format: 'Y-m-d', xtype: 'datefield', value: this.endTime, minValue: this.startTime },
				{ id: 'onSure', xtype: 'button', text: '确定' }
			],
			buttons: [ { text: '关闭', handler: this._onCloseClick, scope: this } ],
			buttonAlign: 'center'
		});
		EQPublish.ChartWindow.superclass.initComponent.call(this, arguments);
	},
	_onCloseClick: function() {
		this.hide();
	},
	initEvents: function() {
		EQPublish.ChartWindow.superclass.initEvents.apply(this, arguments);
		Ext.getCmp('startTime').on('change', this.onDateChange, this);
		Ext.getCmp('endTime').on('change', this.onDateChange, this);
		Ext.getCmp('onSure').on('click', this.onClick, this);
	},
	afterRender: function() {
		EQPublish.ChartWindow.superclass.afterRender.call(this, arguments);
	},
	onDateChange: function(date, newValue, oldValue) {
		if (date.id === 'startTime') {
			Ext.getCmp('endTime').setMinValue(newValue);
			Ext.getCmp('endTime').validate();
		} else {
			Ext.getCmp('startTime').setMaxValue(newValue);
			Ext.getCmp('startTime').validate();
		}

	},
	onClick: function() {
		this.update();
	},
	update: function(){
		this.getUpdater().showLoadIndicator = true;
		this.getUpdater().update({
			url: this.ascxHandlerUrl,
			params: { path: this.chartHandlerUrl, MinDate: Ext.getCmp('startTime').value, MaxDate: Ext.getCmp('endTime').value + ' 23:59:59', ID: this.ID },
			text: "正在加载数据..."
		});
	},
	show: function() {
		EQPublish.ChartWindow.superclass.show.apply(this, arguments);
		this.update();
		this.filter = 0;
	},
	setID: function(id) {
		this.ID = id;
	},
	setTime: function(start, end) {
		this.startTime = start;
		this.endTime = end;
	}
});
Ext.reg('chartwindow', EQPublish.ChartWindow);