OW2 Consortium telosys

Rev

Blame | Last modification | View Log | RSS feed

//------------------------------------------------------------------------------
// TelosysEnv_class.js : Telosys environment object
// Telosys framework
// Author  : Laurent Guérin 
//------------------------------------------------------------------------------
/**
 * This object stores the absolute URLs to access the server side with AJAX calls.
 * It provides different kind of objects ( Screen, Service, Actions, ... )
 *
 * @param String : Application root URL ( required )
 * @param String : Screen Map URL ( required )
 * @param String : Screen Context AJAX calls URL ( required )
 * @param String : Current Screen Name 
 * @param int    : Current Screen ID
 *
 */
//------------------------------------------------------------------------------
 
//------------------------------------------------------------------------------
// CLASS DEFINITION
//------------------------------------------------------------------------------
//function TelosysEnv( sRootUrl, sScreenMapUrl, sAjaxUrl, sScreenName, iScreenId )
function TelosysEnv()
{
        //==============================================================================
        // PRIVATE ATTRIBUTES
        //==============================================================================
        //--- URLs 
        var _sRootUrl      = null ;
        var _sScreenMapUrl = null ;
        var _sAjaxUrl      = null ;

        //--- Current Screen Map   
        var _sScreenName   = null ;
        var _iScreenId     = 0 ;
        var _screen        = null ;
        var _actions       = null ;     
        
        //--- Keyboard & browser  
        var _keyboard      = Keyboard.getKeyboard(); 
        var _browser       = Browser.getBrowser() ; 
        
        //alert ( "in TelosysEnv : this = " + this + "\n constructor : \n" + this.constructor ) ;
        
        //==============================================================================
        // CONSTRUCTOR
        //==============================================================================
        _constructor.apply ( this, arguments );  //--- Call the constructor
        function _constructor ( sRootUrl, sScreenMapUrl, sAjaxUrl, sScreenName, iScreenId ) 
        {
                if ( arguments.length != 3 && arguments.length != 5 )
                {
                        alert("ERROR : TelosysEnv constructor : 3 or 5 arguments expected ! \n"
                                + "( sRootUrl, sScreenMapUrl, sAjaxUrl [ , sScreenName, iScreenId ] )  ");
                        return null ;
                }
                
                _sRootUrl      = sRootUrl ;
                _sScreenMapUrl = sScreenMapUrl ;
                _sAjaxUrl      = sAjaxUrl ;
                
                if ( arguments.length == 5 )
                {
                        //--- Initialize the current screen
                        _sScreenName = sScreenName ;
                        _iScreenId   = iScreenId ;
                        _screen      = _createScreen (_sScreenName, _iScreenId) ;
                        _actions     = _createActions(_screen);
                }
        }
        
        //==============================================================================
        // PRIVATE METHODS 
        //==============================================================================
        function _createScreen (sScreenName, sContextId) 
        {
                if ( arguments.length < 2 )
                {
                        alert("ERROR : TelosysEnv._createScreen() : 2 arguments expected !");
                        return null ;
                }
                //--- Create a new Screen and return it
                return new Screen( sScreenName, _sAjaxUrl, sContextId ) ;
        }
        //------------------------------------------------------------------------------
        function _createActions (oScreen) 
        {
                if ( arguments.length < 1 )
                {
                        alert("ERROR : TelosysEnv._createActions() : 1 argument expected !");
                        return null ;
                }
                return new ScreenActions( oScreen );
        }
        
        //==============================================================================
        // PUBLIC / PRIVILEGED  METHODS 
        //==============================================================================
        //------------------------------------------------------------------------------
        /**
         * Return the absolute root URL of the WebApp 
         * @return String : the URL
         */
        this.getRootUrl = function () 
        {
                return _sRootUrl ;
        }

        //------------------------------------------------------------------------------
        // Return the absolute URL for screenmap calls with optional parameters.
        this.getScreenMapUrl = function (sName, sType, sContextId, sContextName, sAction, sParams) 
        {
                if ( arguments.length == 0 ) {
                        return _sScreenMapUrl ;
                }
                /**
                if ( arguments.length != 5  ) {
                        alert("ERROR : TelosysEnv.getScreenMapUrl() : 0 or 5 arguments expected !");
                        return null ;
                }
                */
                if ( sName == null ) {
                        alert("ERROR : TelosysEnv.getScreenMapUrl() : argument 'name' is null !");
                        return null ;
                }
                //--- Build the ScreenMap URL with parameters ...
                var s = _sScreenMapUrl + "/" + sName ;
        if ( sType != null ) {
            s = s + "-" + sType ;
        }
        
        if ( sContextId != null ) {
            s = s + "/" + sContextId ;
        }
        if ( sContextName != null ) {
                if ( sContextId != null  ) {
                        s = s + "-" + sContextName;
                }
                else {
                        s = s + "/" + sContextName;
                }
        }
        if ( sAction != null ) {
            s = s + ":" + sAction ;
        }                               
        if ( sParams != null ) {
            s = s + "?" + sParams ;
        }                               
                return s ;
        }

        //------------------------------------------------------------------------------
        /**
         * Return the absolute URL for Screen actions calls ( AJAX calls )
         * @return String : the URL
         */
        this.getAjaxUrl = function () 
        {
                return _sAjaxUrl ;
        }

        //------------------------------------------------------------------------------
        /**
         * Returns the current 'Screen' instance 
         * Runtime error if no current screen
         * @return Screen : the Screen instance ( or null after runtime error )
         */
        this.getCurrentScreen = function () 
        {
                if ( _screen != null )
                {
                        return _screen ;
                }
                else
                {
                        alert("ERROR : TelosysEnv.getCurrentScreen() : No current screen !");
                        return null ;
                }
        }
        //------------------------------------------------------------------------------
        /**
         * Returns the current 'Actions' instance 
         * Runtime error if not defined
         * @return Actions : the Actions instance ( or null after runtime error )
         */
        this.getCurrentActions = function () 
        {
                if ( _actions != null )
                {
                        return _actions ;
                }
                else
                {
                        alert("ERROR : TelosysEnv.getCurrentActions() : No current actions !");
                        return null ;
                }
        }
        //------------------------------------------------------------------------------
        /**
         * Create and return a new 'Screen' object for the given name and id
         * @param  String : Screen name
         * @param  int    : Screen context ID
         * @return Screen : the Screen instance ( or null if error )
         */
        this.getScreen = function (sScreenName, sContextId) 
        {
                if ( arguments.length < 2 )
                {
                        alert("ERROR : TelosysEnv.getScreen() : 2 arguments expected !");
                        return null ;
                }
                //--- Create a new Screen and return it
                return new Screen( sScreenName, _sAjaxUrl, sContextId ) ;
        }
        //------------------------------------------------------------------------------
        /**
         * Create and return a new 'Service' object
         * @param  String   : Service name
         * @param  Function : Callback function to call to process the service response
         * @return Service  : the Service instance ( or null if error )
         */
        this.getService = function ( sServiceName, callbackFunction ) 
        {
                if ( arguments.length < 2 )
                {
                        alert("ERROR : TelosysEnv.getService() : 2 arguments expected !");
                        return null ;
                }
                return new ScreenService( sServiceName, _sRootUrl, callbackFunction ) ;
        }
        //------------------------------------------------------------------------------
        /**
         * Create and return a new 'ScreenActions' object
         * 2 signatures :
         *  . 1 : getActions( ScreenObject )
         *  . 2 : getActions( ScreenName, ScreenID )
         * @param  arg1 : Screen object or Screen Name 
         * @param  arg2 : Screen Id  ( with arg1 = Screen Name )
         * @return ScreenActions : the ScreenActions instance ( or null if error )
         */
        this.getActions = function ( arg1, arg2 ) 
        {
                if ( arguments.length == 2 )
                {
                        if ( typeof arg1 == "string" && typeof arg2 == "string" )
                        {
                                return new ScreenActions( this.getScreen(arg1, arg2) );
                        }
                        else if ( typeof arg1 == "string" && typeof arg2 == "number" )
                        {
                                return new ScreenActions( this.getScreen(arg1, arg2) );
                        }
                        else
                        {
                                alert("ERROR : TelosysEnv.getActions() : invalid arguments type ! "
                                        + "\n . argument 1 : '" + ( typeof arg1 ) + "' ( string expected ) " 
                                        + "\n . argument 2 : '" + ( typeof arg2 ) + "' ( string or number expected ) " );
                                return null ;
                        }               
                }
                else if ( arguments.length == 1 )
                {
                        if ( typeof arg1 == "object" )
                        {
                                return new ScreenActions( arg1 );
                        }
                        else
                        {
                                alert("ERROR : TelosysEnv.getActions() : the argument is not an object !");
                                return null ;
                        }
                }
                else
                {
                        alert("ERROR : TelosysEnv.getActions() : " + arguments.length + " argument(s) ( 1 or 2 expected ) !");
                        return null ;
                }
        }
        //------------------------------------------------------------------------------
        this.getKeyboard = function () 
        {
                return _keyboard ;
        }
        //------------------------------------------------------------------------------
        this.getBrowser = function () 
        {
                return _browser ;
        }
        //------------------------------------------------------------------------------
        this.toString = function () 
        {
                return "Root URL='" + _sRootUrl 
                         + "' - ScreenMap URL='" + _sScreenMapUrl 
                         + "' - Ajax URL='" + _sAjaxUrl + "'" ;
        }       
        //------------------------------------------------------------------------------        
}
//------------------------------------------------------------------------------
//                               T H E      E N D 
//------------------------------------------------------------------------------

Generated by GNU enscript 1.6.4.