Core

Core

Initialize all necessary data structures for a communication with the UnityBase server

Example:

 var $core = new Core({
    host: window.location.origin,
    path: window.location.pathname,
    onCredentialRequired: function(conn, isRepeat){
        if (isRepeat){
            throw new UB.UBAbortError('invalid')
        } else {
            return Q.resolve({authSchema: 'UB', login: 'admin', password: 'admin'})
        }
    },
    onAuthorizationFail:  function(reason){
        alert(reason);
    }
});

 $core.initialize().then(function($core){
    $core.connection.get('stat').done(function(statResp){
        document.getElementById('ubstat').innerText = JSON.stringify(statResp.data, null, '\t');
    });

    UB.Repository('ubm_navshortcut').attrs(['ID', 'code', 'caption']).selectAsArray().done(function(data){
        var tmpl = _.template(document.getElementById('repo-template').innerHTML);
        var result = tmpl(data.resultData);
        // document.getElementById('ubnav').innerText = JSON.stringify(data.resultData);
        document.getElementById('ubnav').innerHTML = result;
    });
});

Constructor

new Core(cfg)

Arguments:
  1. cfg
    Properties
    1. host (string)  Server host
    2. [path] (string)  API path - the same as in Server config httpServer.path
    3. onCredentialRequired   Callback for requesting a user creadentials. See UBConnection constructor requestAuthParams parameter description
    4. [onAuthorizationFail]   Callback for authorization failure. See authorizationFail event.
    5. [onNeedChangePassword]   Callback for a password exparition. See passwordExpired event
    6. [onGotApplicationConfig]
    7. [onGotApplicationDomain]
Mixes In:

Members

connection: UBConnection

Connection to the server

ubNotifier: UBNotifierWSProtocol

WebSocket ubNotifier protocol instance

appConfig: Object

Application settings transferred form a server

preferredLocale: string

The preferred (used in previous user session if any or a default for application) locale

domain: UBDomain

The application domain

Methods

initialize() → Promise

Initialize a Core. Return a promise, resolved to {Core} instance

listenerCount(emitter, type)Number

Return the number of listeners for a given event.
Arguments:
  1. emitter (EventEmitter)
  2. type (String)
Mixes In: