UB

UB

The UB namespace (global object) encapsulates some classes, singletons, and utility methods provided by UnityBase server.

Namespaces

virtualStores

Members

isServer static readonly

If we are in UnityBase server scripting (both -f or server thread) this property is true, if in browser - undefined or false. Use it for check execution context in scripts, shared between client & server. To check we are in server thread use process.isServer.

Methods

UBAbort(messageopt) static

Server-side Abort exception. To be used in server-side logic in case of HANDLED exception. This errors logged using "Error" log level to prevent unnecessary EXC log entries.

  // UB client will show message inside <<<>>> to user (and translate it using UB.i18n)
  throw new UB.UBAbort('<<<textToDisplayForClient>>>');
  //for API methods we do not need <<<>>>
  throw new UB.UBAbort('wrongParameters');
Arguments:
  1. [message] (String)  Message

ns(namespacePath)Object static

Creates namespaces to be used for scoping variables and classes so that they are not global.

UB.ns('DOC.Report');
DOC.Report.myReport = function() { ... };
Arguments:
  1. namespacePath (String)

format(stringToFormat, …values)String static

Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each token must be unique, and must increment in the format {0}, {1}, etc.
Arguments:
  1. stringToFormat (String)  The string to be formatted.
  2. ...values (*)  The values to replace tokens {0}, {1}, etc in order.
Example
var s = UB.format('{1}/lang-{0}.js', 'en', 'locale');
    // s now contains the string: ''locale/lang-en.js''

Repository(entityName, cfgopt, connectionopt)ServerRepository static

Create new instance of ServerRepository
Arguments:
  1. entityName (String)
  2. [cfg] (Object)
  3. [connection] (UBConnection)  Pass in case of remote UnityBase server connection.

i18n(msg, langopt) static

Translate message specified language using global.i18nData translation table. To add model-depended values in your model create i18n.js file in the model folder and place where this script:

 _.merge(global.i18nData, {"en": {yourMessage: "yourTranslation", ...}, "ru": {yourMessage: "yourTranslation", ...}, ....}
Arguments:
  1. msg (String)  Message to translate
  2. [lang] (String)  language to translate to. if not passed - current user session language used, or default application language if not logged in