﻿/// <reference path="http://www-app.gdepb.gov.cn/ext-2.2/vswd-ext_2.1.js" />

Ext.namespace('EQPublish');

EQPublish.WaterMonthViewport = Ext.extend(Ext.Viewport, {
    initComponent: function() {
        Ext.apply(this, {
            layout: 'border',
            border: false,
            defaults: { border: true },
            items: [
				{ id: 'north', region: 'north', contentEl: 'hd', height: '160', border: false },
				{
					title: '江河水质月报', region: 'west', width:400, split: true,
				    collapsible: true, collapseMode: 'mini', layout: 'border',
				    items: [
						{
						    id: 'watermonthpanel', layout: 'fit', xtype: 'WaterMonthPanel', region: 'center',
   							bbar:['<img src="images/dbyes.png">','达标','-','<img src="images/dbnot.png">','未达标','->','<img src="Images/WaterLegend.gif"/>']
						}
					]
				},
				{ xtype: 'vepanel', id: 'vemap', region: 'center' },
				{ id: 'south', region: 'south', contentEl: 'ft', collapsible: false, border: false }
			]
        });
        EQPublish.WaterMonthViewport.superclass.initComponent.call(this);
    },
    initEvents: function() {
        /// 这里注册事件绑定
        Ext.getCmp('watermonthpanel').on('timeChange', this.onCondiChange, this);
        Ext.getCmp('watermonthpanel').on('rowclick', this.onRowSelect, this);
    },
    afterRender: function() {
        EQPublish.WaterMonthViewport.superclass.afterRender.apply(this, arguments);
        this.initEvents();
        /// 这里加载页面默认的数据
    },
    onRowSelect: function(thisGird, rowIndex, evObj) {
        var Longitude = thisGird.store.getAt(rowIndex).get('Longitude');
        var Latitude = thisGird.store.getAt(rowIndex).get('Latitude');
        var title = thisGird.store.getAt(rowIndex).get('RiverPartName');
        Ext.getCmp('vemap').setMapPosition(Latitude, Longitude);
        var item = {
        	id: 'marker',
        	lat: Latitude + 0.002,
        	lon: Longitude + 0.002,
        	icon: '/EQPublish/Images/MapIcon/marker.gif',
        	title: title
        }
        Ext.getCmp('vemap').deleteIcon('marker');
        Ext.getCmp('vemap').addIcon(item, true);
    },
    onCondiChange: function(thisGrid, condiObj) {
		//条件改变，走此函数，条件状态在condiObj中。在此加载地图
		function onSuccess(request, options) {
			var result = Ext.decode(request.responseText);
			if (result.Success) {
				if (result.Data.length > 0) {
					Ext.getCmp('vemap').addIcon.defer(400, Ext.getCmp('vemap'), [result.Data]);
				}
				else {
					Ext.getCmp('vemap').cleanIcon();
				}
			}
			else {
				//Ext.MessageBox.alert('', result.ErrorMessage);
				return false;
			}
		}
		function onFailure(response, options) { }
		var param = { y: condiObj.year, m: condiObj.month };
		Ext.Ajax.request({
			url: this.url,
			params: { op: 'QueryWaterMonthIcon', param: Ext.encode(param) },
			success: onSuccess,
			failure: onFailure
		});
    }
});