Represents application's current user object.
The user object contains settings that are fetched from the server
and whatever settings the application wants to store.
// Sample user object that is fetched from the server:
{
id: "1",
full_name: "Administrator",
user_name: "admin",
preferences: {
timezone: "America\/Los_Angeles",
datepref: "m\/d\/Y",
timepref: "h:ia"
}
}
// Use it like this:
const User = require('core/user');
var userId = User.get('id');
// Set app specific settings
User.set('sortBy:Cases', 'case_number');
// Bind event handlers if necessary
User.on('change', function() {
// Do your thing
});
Members
Methods
#
(inner) getAcls() → {Object}
Gets ACLs.
Precondition: either the user is logged in or an _reset
call has
set the user manually.
#
(inner) getCurrency() → {Object}
Returns an object with all the user's currency preferences.
If the user hasn't specified any preferences,
these default to system currency preferences.
Returns:
The user's currency preferences.
-
Type
-
Object
#
(inner) getLanguage() → {string}
Retrieves the current user's preferred language.
Returns:
The current user's preferred language.
-
Type
-
string
#
(inner) getPreference(name) → {*}
Gets a preference by name.
Parameters:
Name |
Type |
Description |
name |
string
|
The preference name. |
- To Do:
-
- support category parameter for preferences.
Returns:
The value of the user preference, or name
if no
corresponding preference value exists.
-
Type
-
*
#
(inner) hasLicense(licenseType, hasAll) → {boolean}
Checks if the user has one or more licenses.
Parameters:
Name |
Type |
Description |
licenseType |
string
|
Array
|
one or more licenses to check |
hasAll |
boolean
|
if true, the user must have all the provided licenses |
Returns:
true if the user's licenses match the criteria, false otherwise
-
Type
-
boolean
#
(inner) hasSellLicense() → {boolean}
Checks if the user has a Sell license.
#
(inner) hasSellServeLicense(hasBoth) → {boolean}
Checks if the user has a Sell/Serve license. If hasBoth is true, then the user must
have both licenses. If hasBoth is false (default), then having at least one license is enough.
Parameters:
Name |
Type |
Description |
hasBoth |
boolean
|
|
#
(inner) hasServeLicense() → {boolean}
Checks if the user has a Serve license.
#
(inner) isSetupCompleted() → {boolean}
Checks if the user has completed their set up steps
#
(inner) load(callbackopt)
Retrieves and sets the user preferences.
Parameters:
Name |
Type |
Attributes |
Description |
callback |
function
|
<optional>
|
Callback called when update completes. |
#
(inner) loadLocale(callbackopt)
Loads the current user's locale.
Parameters:
Name |
Type |
Attributes |
Description |
callback |
function
|
<optional>
|
Called when loading the locale completes. |
#
(inner) setPreference(name, value) → {Object}
Set preference by name. Will only be stored locally.
Parameters:
Name |
Type |
Description |
name |
string
|
The preference name. |
value |
*
|
The new preference value. |
- To Do:
-
- support category parameter for preferences.
- support save preferences on server.
Returns:
The instance of this user.
-
Type
-
Object
#
(inner) update(method, payload, callback)
Parameters:
Name |
Type |
Description |
method |
string
|
Operation type: either 'read', 'update',
'create', or 'delete'. {@see SUGAR.Api#me}. |
payload |
Object
|
An object literal with payload. |
callback |
Object
|
Callback called when update completes. In
case of error, App.error.handleHttpError will be called here. |
#
(inner) updateLanguage(language, callbackopt)
Updates the user's preferred language.
Parameters:
Name |
Type |
Attributes |
Description |
language |
string
|
|
Language key. |
callback |
function
|
<optional>
|
Callback called when update completes. |
#
(inner) updatePreferences(attributes, callbackopt)
Updates the user's preferences.
Parameters:
Name |
Type |
Attributes |
Description |
attributes |
Object
|
|
The attributes to update for user. |
callback |
function
|
<optional>
|
Callback called when update completes. |
#
(inner) updateProfile(attributes, callbackopt)
Updates the user's profile.
Parameters:
Name |
Type |
Attributes |
Description |
attributes |
Object
|
|
The model attributes to update for user. |
callback |
function
|
<optional>
|
Callback called when update completes. |