eLabSDK.User

Functions

NameDescription
getUserRole()Get the role and role ID of the currently logged-in user.

This retrieves the user's role information from global variables set by the application.
The role determines the user's permissions and access levels within the system. Use this
to implement conditional logic based on user roles or display role-specific UI elements.
getUserFullname() | Get the full name (first name and last name) of the currently logged-in user.

This retrieves the user's complete name from a global variable set by the application.
Returns an empty string if the user's full name is not available. Use this to display
the user's name in the UI, personalize messages, or identify the current user in logs
and reports.
getDateFormat() | Get the date format configured for the currently logged-in user.

This retrieves the user's preferred date format (Moment.js format string) from global
variables set by the application. If no user-specific format is configured, returns the
default format 'YYYY-MM-DD'. Use this to format dates consistently according to the user's
locale and preferences throughout the application.

getUserRole()

Get the role and role ID of the currently logged-in user.

This retrieves the user's role information from global variables set by the application.
The role determines the user's permissions and access levels within the system. Use this
to implement conditional logic based on user roles or display role-specific UI elements.

Kind: global function
Returns: Object - An object containing the user's role informationstring - returns.role - The user's role name (e.g., 'Admin', 'Researcher', 'Guest')number - returns.roleID - The numeric ID of the user's role
Example

// Get current user's role
var user = new eLabSDK.User();
var roleInfo = user.getUserRole();
console.log('Role: ' + roleInfo.role);
console.log('Role ID: ' + roleInfo.roleID);

Example

// Conditional logic based on role
var user = new eLabSDK.User();
var roleInfo = user.getUserRole();
if (roleInfo.role === 'Admin') {
  // Show admin-only features
  showAdminPanel();
}

Example

// Check role ID for permissions
var user = new eLabSDK.User();
var roleInfo = user.getUserRole();
if (roleInfo.roleID >= 3) {
  enableAdvancedFeatures();
}

getUserFullname()

Get the full name (first name and last name) of the currently logged-in user.

This retrieves the user's complete name from a global variable set by the application.
Returns an empty string if the user's full name is not available. Use this to display
the user's name in the UI, personalize messages, or identify the current user in logs
and reports.

Kind: global function
Returns: string - The user's full name (e.g., 'John Doe'), or an empty string if not available
Example

// Display user's name
var user = new eLabSDK.User();
var fullName = user.getUserFullname();
console.log('Logged in as: ' + fullName);

Example

// Personalize greeting
var user = new eLabSDK.User();
var fullName = user.getUserFullname();
if (fullName) {
  document.getElementById('greeting').textContent = 'Welcome, ' + fullName + '!';
}

Example

// Use in form default values
var user = new eLabSDK.User();
var fullName = user.getUserFullname();
document.getElementById('created-by').value = fullName;

getDateFormat()

Get the date format configured for the currently logged-in user.

This retrieves the user's preferred date format (Moment.js format string) from global
variables set by the application. If no user-specific format is configured, returns the
default format 'YYYY-MM-DD'. Use this to format dates consistently according to the user's
locale and preferences throughout the application.

Kind: global function
Returns: string - The user's date format string in Moment.js format (e.g., 'YYYY-MM-DD', 'DD/MM/YYYY', 'MM/DD/YYYY')
Example

// Get user's date format
var user = new eLabSDK.User();
var format = user.getDateFormat();
console.log('User date format: ' + format); // Output: 'YYYY-MM-DD'

Example

// Format a date according to user preferences
var user = new eLabSDK.User();
var format = user.getDateFormat();
var formattedDate = moment(new Date()).format(format);
console.log('Formatted date: ' + formattedDate);

Example

// Use in date picker configuration
var user = new eLabSDK.User();
var format = user.getDateFormat();
$('#datepicker').datepicker({
  dateFormat: format,
  // other options...
});

© 2023 eLabNext