// File: /include/js/Shared/Views/autoLoginView.js
// Desc: Auto login view
// $Revision: 14$
// $Date: 5/14/2007 12:10:34 PM$
// $Author: Donnie Tognazzini$
// $NoKeywords$

/******************************************************************************
  VM_AutoLoginView
 ******************************************************************************/
function VM_AutoLoginView( viewController )
{
    try
    {
        UTILS.inheritFromBase( this, "VM_AutoLoginView", "#autoLoginViewFrame" );

        // Initialize members

        this.m_timer            = null;
        this.m_viewController   = viewController;

        // Event handlers

        this.bindToEvent( "viewStateChange" );
        this.bindToEvent( "GetAccountInfoFailure" );
        this.bindToEvent( "#lnkStop", "click", this.onStopLinkClick );
    }
    catch ( e )
    {
        EX_ASSERT_NO_EXCEPTIONS( e, "VM_AutoLoginView::VM_AutoLoginView( )" );
    }
}

var VM_AutoLoginView_prototype =
{
    DEFAULT_MESSAGE              : "Connecting, please wait...",
    LOGIN_RETRY_INTERVAL_SECONDS : 30,

    onviewStateChange : function( e, oldState, newState )
    {
        try
        {
            if ( newState == this.m_viewController.VIEW_STATE_SHOW_AUTOLOGIN )
            {
                CW_GetMessageArea( ).display( this.DEFAULT_MESSAGE, CW_GetMessageArea( ).MESSAGE_TYPE_STATUS );
                UTILS.adjustHeight( );
            }
        }
        catch ( e )
        {
            EX_ASSERT_NO_EXCEPTIONS( e, "VM_AutoLoginView::onviewStateChange( )" );
        }
    },

    onStopLinkClick : function( )
    {
        try
        {

            if ( this.m_timer )
            {
                clearTimeout( this.m_timer );
                this.m_timer = null;
            }

            this.m_viewController.onAutoConnectCanceled( );
        }
        catch ( e )
        {
            EX_ASSERT_NO_EXCEPTIONS( e, "VM_AutoLoginView::onStopLinkClick( )" );
        }
    },

    onGetAccountInfoFailure : function( e, statusMessage )
    {
        try
        {
            var self = this;
            var timeoutCallback = function( )
                {
                    clearTimeout( self.m_timer );
                    self.m_timer = null;
                    self.m_viewController.onGetAccountInfo( );
                };

            this.m_timer = setTimeout( timeoutCallback, this.LOGIN_RETRY_INTERVAL_SECONDS * 1000 );
        }
        catch ( e )
        {
            EX_ASSERT_NO_EXCEPTIONS( e, "VM_AutoLoginView::onGetAccountInfoFailure( )" );
        }
    }
};
