The main entry point for most operation is UBConnection
for communication with UnityBase server.
Members
userAgent: String
static
isChrome: Boolean
static
isWebKit: Boolean
static
isGecko: Boolean
static
isOpera: Boolean
static
isMac: Boolean
static
isSecureBrowser: Boolean
static
appConfig
static
Properties:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
appConfig |
Object | UnityBase application parameter. All this parameters can be configured in ubConfig.uiSettings.adminUI section of application configuration file. Properties
|
onError: UB-onError static
onShowLoginWindow static
UB.appConfig
- it is initialized before login call
Properties:
Type | Description |
---|---|
function |
xhrDefaults static
UB.xhr
Properties:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
xhrDefaults |
Object |
Properties
|
interceptors: Array.<Object> protected static
pendingRequests: Array.<Object> protected static
Methods
apply(objectTo, …objectsFrom) → Object
static
Copies all the properties of one or several objectsFrom to the specified objectTo.
Non-simple type copied by reference!
Arguments:
-
objectTo
(Object)
 The receiver of the properties
-
...objectsFrom
(Object)
 The source(s) of the properties
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. Example usage:
var s = UB.format('{1}/ext-lang-{0}.js', 'en', 'locale');
// s now contains the string: ''locale/ext-lang-en.js''
Arguments:
-
stringToFormat
(String)
 The string to be formatted.
-
...values
(*)
 The values to replace tokens {0}
, {1}
, etc in order.
ns(namespacePath) → Object
static
Creates namespaces to be used for scoping variables and classes so that they are not global.
Arguments:
-
namespacePath
(String)
Example
UB.ns('DOC.Report');
DOC.Report.myReport = function() { ... };
iso8601Parse(value) → Date
static
Convert UnityBase server dateTime response to Date object
Arguments:
-
value
iso8601ParseAsDate(value) → Date
static
Convert UnityBase server date response to Date object.
date response is a day with 00 time (2015-07-17T00:00Z), to get a real date we must add current timezone shift
Arguments:
-
value
booleanParse(v) → Boolean|null
static
Convert UnityBase server Boolean response to Boolean (0 = false & 1 = trhe)
Arguments:
-
v
 Value to convert
i18n(localeString) → *
static
Return locale-specific resource from it identifier.
localeString must be previously defideb dy call to UB#i18nExtend
Arguments:
-
localeString
(String)
i18nExtend(localizationObject)
static
Merge localizationObject to UB.i18n. Usually called form modelPublic/locale/lang-*.js scripts
Arguments:
-
localizationObject
(Object)
base64FromAny(data) → Promise
static
Fast async transformation of data to base64 string
Arguments:
-
data
(File|ArrayBuffer|String|Blob|Array)
base64toArrayBuffer(base64) → ArrayBuffer
static
Convert base54 encoded string to decoded array buffer
Arguments:
-
base64
(String)
log(…msg)
static
Log message to console (if console available)
Arguments:
-
...msg
(*)
logError(…msg)
static
Log error message to console (if console available)
Arguments:
-
...msg
(*)
logWarn(…msg)
static
Log warning message to console (if console available)
Arguments:
-
...msg
(*)
logDebug(…msg)
static
Log debug message to console.
Since it binded to console, can also be used to debug Promise resolving in this way:
UB.get('timeStamp').done(UB.logDebug);
Arguments:
-
...msg
(*)
doOnProcessError(errMsg, errCodeopt) → function
static
Arguments:
getResourceVersion(uri) → String
static
Search for resource version in the window.__ubVersion global const
IF any, return 'ver=version' else ''
Arguments:
-
uri
(String)
addResourceVersion(uri) → String
static
Exec UB.getResourceVersion and if any - add ?ver to resource and return resource with ?ver
Arguments:
-
uri
(String)
inject(url, charsetopt) → Promise
static
Inject external script or css to DOM and return a promise to be resolved when script is loaded.
Implement single load mode (if script successfully loaded using UB.inject
it not loaded anymore.
Arguments:
Example
//Load script.js:
UB.inject('jslibs/script.js').done();
//Load several script at once and error handling:
Q.all([UB.inject('jslibs/script.js'), UB.inject('script2.js')])
.fail(function(err){
console.log('Oh! error occurred: ' + err) ;
});
//Load one script and then load other
UB.inject('jslibs/js_beautify.js')
.then(function(){
console.log('first script loaded. Continue to load second');
return UB.inject('jslibs/js_beautify1.js');
}).done();
//Load couple of resources:
Q.all([UB.inject('css/first.css'), UB.inject('css/second.css')]).done();
xhr(requestConfig) → Promise
static
Promise of perform an asynchronous HTTP request
Returns a promise
object with the
standard Promise methods (reference).
The then
method takes two arguments a success and an error callback which will be called with a
response object. The arguments passed into these functions are destructured representation of the response object passed into the
then
method. The response object has these properties:
- data –
{string|Object}
– The response body transformed with the transform
functions. Default transform check response content-type is application/json and if so - convert data to Object
- status –
{number}
– HTTP status code of the response.
- headers –
{function([headerName])}
– Header getter function.
- config –
{Object}
– The configuration object that was used to generate the request.
Arguments:
-
requestConfig
(Object)
 Object describing the request to be made and how it should be
processed. The object has following properties:
Properties
-
url
(String)
 Absolute or relative URL of the resource that is being requested
-
[method]
(String)
 HTTP method (e.g. 'GET', 'POST', etc). Default is GET
-
[params]
(Object.<(string|Object)>)
 Map of strings or objects which will be turned
to ?key1=value1&key2=value2
after the url. If the value is not a string, it will be JSONified
-
[data]
(String|Object)
 Data to be sent as the request message data
-
[headers]
(Object)
 Map of strings or functions which return strings representing
HTTP headers to send to the server. If the return value of a function is null, the
header will not be sent. Merged with UB.xhrDefaults.headers
-
[transformRequest]
(function|Array.<function(data, function())>)
 Transform function or an array of such functions. The transform function takes the http
request body and headers and returns its transformed (typically serialized) version.
-
[transformResponse]
(function|Array.<function(data, function())>)
 Transform function or an array of such functions. The transform function takes the http
response body and headers and returns its transformed (typically deserialized) version.
-
[timeout]
(Number|Promise)
 timeout in milliseconds, or promise
that should abort the request when resolved. Default to {UB.xhrDefaults.timeout}
-
[withCredentials]
(Boolean)
 whether to to set the withCredentials
flag on the
XHR object. See requests with credentials
for more information.
-
[responseType]
(String)
 see responseType.
Example
//Get some data from server:
UB.xhr({url: 'getAppInfo'}).done(function(resp) {
console.log('this is appInfo: %o', resp.data)
});
//The same, but in more short form via UB.get
shorthand:
UB.get('getAppInfo').done(function(resp) {
console.log('this is appInfo: %o', resp.data)
});
//Run POST method:
UB.post('ubql', [
{entity: 'uba_user', method: 'select', fieldList: ['*']}
]).then(function(resp) {
console.log('success!');
}, function(resp) {
console.log('request failed with status' + resp.status);
});
//retrieve binary data as ArrayBuffer
UB.get('downloads/cert/ACSK(old).cer', {responseType: 'arraybuffer'})
.done(function(res){
console.log('Got Arrray of %d length', res.data.byteLength);
});
get(url, configopt) → Promise
static
Shortcut for UB.xhr
to perform a GET
request.
Arguments:
-
url
(string)
 Relative or absolute URL specifying the destination of the request
-
[config]
(Object)
 Optional configuration object as in UB.xhr
post(url, data, configopt) → Promise
static
Shortcut for UB.xhr
to perform a POST
request.
Arguments:
-
url
(string)
 Relative or absolute URL specifying the destination of the request
-
data
(*)
 Request content
-
[config]
(Object)
 Optional configuration object as in UB.xhr
put(url, data, configopt) → Promise
static
Shortcut for UB.xhr
to perform a PUT
request.
Arguments:
-
url
(string)
 Relative or absolute URL specifying the destination of the request
-
data
(*)
 Request content
-
[config]
(Object)
 Optional configuration object as in UB.xhr
patch(url, data, configopt) → Promise
static
Shortcut for UB.xhr
to perform a PATCH
request.
Arguments:
-
url
(string)
 Relative or absolute URL specifying the destination of the request
-
data
(*)
 Request content
-
[config]
(Object)
 Optional configuration object as in UB.xhr
UBError(message, detailopt, codeopt)
static
UnityBase client-side exception.
Such exceptions are will not be showed as unknown error in UB#showErrorWindow
message Can be either localized message or locale identifier - in this case UB#showErrorWindow translate message using UB#i18n
Arguments:
-
message
(String)
 Message
-
[detail]
(String)
 Error details
-
[code]
(Number)
 Error code (for server-side errors)
Example
throw new UB.UBError('lockedBy'); // will show message box "Record was locked by other user. It\'s read-only for you now"
UBAbortError(messageopt, detailopt)
static
UnityBase still error. Global error handler does not show this error for user. Use it for still reject promise.
Arguments:
Repository(entityName) → ClientRepository
static
Construct new ClientRepository object using Core.connection as connection parameter value.
Warning - method added after UBCore.initialize() is resolved.
Arguments:
-
entityName
(String)
objectTo
(Object)
 The receiver of the properties
...objectsFrom
(Object)
 The source(s) of the properties
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. Example usage:
var s = UB.format('{1}/ext-lang-{0}.js', 'en', 'locale');
// s now contains the string: ''locale/ext-lang-en.js''
stringToFormat
(String)
 The string to be formatted.
...values
(*)
 The values to replace tokens {0}
, {1}
, etc in order.
namespacePath
(String)
UB.ns('DOC.Report');
DOC.Report.myReport = function() { ... };
value
value
v
 Value to convert
UB#i18nExtend
localeString
(String)
localizationObject
(Object)
data
(File|ArrayBuffer|String|Blob|Array)
base64
(String)
...msg
(*)
...msg
(*)
...msg
(*)
Log debug message to console. Since it binded to console, can also be used to debug Promise resolving in this way:
UB.get('timeStamp').done(UB.logDebug);
...msg
(*)
uri
(String)
uri
(String)
Implement single load mode (if script successfully loaded using UB.inject
it not loaded anymore.
//Load script.js:
UB.inject('jslibs/script.js').done();
//Load several script at once and error handling:
Q.all([UB.inject('jslibs/script.js'), UB.inject('script2.js')])
.fail(function(err){
console.log('Oh! error occurred: ' + err) ;
});
//Load one script and then load other
UB.inject('jslibs/js_beautify.js')
.then(function(){
console.log('first script loaded. Continue to load second');
return UB.inject('jslibs/js_beautify1.js');
}).done();
//Load couple of resources:
Q.all([UB.inject('css/first.css'), UB.inject('css/second.css')]).done();
Promise of perform an asynchronous HTTP request
Returns a promise
object with the
standard Promise methods (reference).
The then
method takes two arguments a success and an error callback which will be called with a
response object. The arguments passed into these functions are destructured representation of the response object passed into the
then
method. The response object has these properties:
- data –
{string|Object}
– The response body transformed with the transform functions. Default transform check response content-type is application/json and if so - convert data to Object - status –
{number}
– HTTP status code of the response. - headers –
{function([headerName])}
– Header getter function. - config –
{Object}
– The configuration object that was used to generate the request.
requestConfig
(Object)
 Object describing the request to be made and how it should be
processed. The object has following properties:
Properties
-
url
(String)
 Absolute or relative URL of the resource that is being requested -
[method]
(String)
 HTTP method (e.g. 'GET', 'POST', etc). Default is GET -
[params]
(Object.<(string|Object)>)
 Map of strings or objects which will be turned to?key1=value1&key2=value2
after the url. If the value is not a string, it will be JSONified -
[data]
(String|Object)
 Data to be sent as the request message data -
[headers]
(Object)
 Map of strings or functions which return strings representing HTTP headers to send to the server. If the return value of a function is null, the header will not be sent. Merged withUB.xhrDefaults.headers
-
[transformRequest]
(function|Array.<function(data, function())>)
 Transform function or an array of such functions. The transform function takes the http request body and headers and returns its transformed (typically serialized) version. -
[transformResponse]
(function|Array.<function(data, function())>)
 Transform function or an array of such functions. The transform function takes the http response body and headers and returns its transformed (typically deserialized) version. -
[timeout]
(Number|Promise)
 timeout in milliseconds, orpromise
that should abort the request when resolved. Default to {UB.xhrDefaults.timeout} -
[withCredentials]
(Boolean)
 whether to to set thewithCredentials
flag on the XHR object. See requests with credentials for more information. -
[responseType]
(String)
 see responseType.
//Get some data from server:
UB.xhr({url: 'getAppInfo'}).done(function(resp) {
console.log('this is appInfo: %o', resp.data)
});
//The same, but in more short form via UB.get
shorthand:
UB.get('getAppInfo').done(function(resp) {
console.log('this is appInfo: %o', resp.data)
});
//Run POST method:
UB.post('ubql', [
{entity: 'uba_user', method: 'select', fieldList: ['*']}
]).then(function(resp) {
console.log('success!');
}, function(resp) {
console.log('request failed with status' + resp.status);
});
//retrieve binary data as ArrayBuffer
UB.get('downloads/cert/ACSK(old).cer', {responseType: 'arraybuffer'})
.done(function(res){
console.log('Got Arrray of %d length', res.data.byteLength);
});
UB.xhr
to perform a GET
request.
url
(string)
 Relative or absolute URL specifying the destination of the request
[config]
(Object)
 Optional configuration object as in UB.xhr
UB.xhr
to perform a POST
request.
url
(string)
 Relative or absolute URL specifying the destination of the request
data
(*)
 Request content
[config]
(Object)
 Optional configuration object as in UB.xhr
UB.xhr
to perform a PUT
request.
url
(string)
 Relative or absolute URL specifying the destination of the request
data
(*)
 Request content
[config]
(Object)
 Optional configuration object as in UB.xhr
UB.xhr
to perform a PATCH
request.
url
(string)
 Relative or absolute URL specifying the destination of the request
data
(*)
 Request content
[config]
(Object)
 Optional configuration object as in UB.xhr
UB#showErrorWindow
message Can be either localized message or locale identifier - in this case UB#showErrorWindow translate message using UB#i18n
message
(String)
 Message
[detail]
(String)
 Error details
[code]
(Number)
 Error code (for server-side errors)
throw new UB.UBError('lockedBy'); // will show message box "Record was locked by other user. It\'s read-only for you now"
Warning - method added after UBCore.initialize() is resolved.
entityName
(String)