﻿Ext.namespace("TwentyFour.Scripts.Weather");

TwentyFour.Scripts.Weather.SevereWarningsManager = function()
{
    var _renderToLocation;

     function severeWarningsCallBack(response)
     {   
        var panel = $(_renderToLocation);
        
        if (response.error === null && response.value != null)
        {
            var data = response.value;
            
            if (data.Warnings.length > 0 || data.Watches.length > 0)
            {
                var severeWarningsTemplate = new Ext.XTemplate(
                    '<table cellpadding="0" cellspacing="0" border="0" class="forecastTable">\
                        <tpl for="Watches">\
                            <tr>\
                                <td class="forecastHeading">&nbsp;</td>\
                                <td class="forecastHeading">&nbsp;</td>\
                            </tr>\
                            <tr>\
                                <td class="forecastDataLabel">Issued By</td>\
                                <td class="forecastDataItem Left">{NWSOffice}</td>\
                            </tr>\
                            <tr>\
                                <td class="forecastDataLabel">Issuing Time</td>\
                                <td class="forecastDataItem Left">{IssueTimeLocal}</td>\
                            </tr>\
                            <tr>\
                                <td class="forecastDataLabel">Broadcast Time</td>\
                                <td class="forecastDataItem Left">{BroadcastTimeLocal}</td>\
                            </tr>\
                            <tr>\
                                <td class="forecastDataLabel">Valid Time</td>\
                                <td class="forecastDataItem Left">{ValidUntilTimeLocal}</td>\
                            </tr>\
                            <tr>\
                                <td class="forecastDataLabel">Brief Description</td>\
                                <td class="forecastDataItem Left">{Description}</td>\
                            </tr>\
                            <tr>\
                                <td class="forecastDataLabel">Detailed Description</td>\
                                <td class="forecastDataItem Left">{Message}</td>\
                            </tr>\
                        </tpl>\
                        <tpl for="Warnings">\
                            <tr>\
                                <td class="forecastHeading">&nbsp;</td>\
                                <td class="forecastHeading">&nbsp;</td>\
                            </tr>\
                            <tr>\
                                <td class="forecastDataLabel">Issued By</td>\
                                <td class="forecastDataItem Left">{NWSOffice}</td>\
                            </tr>\
                            <tr>\
                                <td class="forecastDataLabel">Issuing Time</td>\
                                <td class="forecastDataItem Left">{IssueTimeLocal}</td>\
                            </tr>\
                            <tr>\
                                <td class="forecastDataLabel">Broadcast Time</td>\
                                <td class="forecastDataItem Left">{BroadcastTimeLocal}</td>\
                            </tr>\
                            <tr>\
                                <td class="forecastDataLabel">Valid Time</td>\
                                <td class="forecastDataItem Left">{ValidUntilTimeLocal}</td>\
                            </tr>\
                            <tr>\
                                <td class="forecastDataLabel">Brief Description</td>\
                                <td class="forecastDataItem Left">{Description}</td>\
                            </tr>\
                            <tr>\
                                <td class="forecastDataLabel">Detailed Description</td>\
                                <td class="forecastDataItem Left">{Message}</td>\
                            </tr>\
                        </tpl>\
                    </table>'
                );
                
                severeWarningsTemplate.overwrite(panel, data);
            }
            else
            {
                panel.update("There are no advisories for this area");
            }
        }
        else
            panel.update("There are no advisories for this area");
     }

    return {
        
        showGrid : function(cityId, renderLocation){    
            _renderToLocation = renderLocation;
            $(_renderToLocation).update('<img src="Images/loading.gif"/>&nbsp;loading...');
            TwentyFour.Weather.Web.Ajax.GetSevereWarningsReport(cityId, severeWarningsCallBack);
        }
    };
};

