eLabSDK.Protocol
Functions
| Name | Description |
|---|---|
| getProtocolCategories(callback) | Retrieve all available protocol categories. |
This fetches the complete list of protocol categories from the system via the REST API.
Protocol categories are used to organize and classify protocols into groups (e.g.,
"Safety Procedures", "Standard Operating Procedures", "Analytical Methods"). The category
list is returned asynchronously via callback. Use this to populate category dropdowns,
display protocol organization, or filter protocols by category.
setDefaultProtocolCategory(categoryID) | Set the user's default protocol category preference.
This stores the specified category ID as the user's default protocol category in a browser
cookie. The default category is used to pre-select a category when creating new protocols
or filtering protocol lists, providing a personalized workflow. The preference persists
across browser sessions until changed. Use this to remember user preferences or set default
contexts for protocol operations.
getDefaultProtocolCategory() | Get the user's default protocol category preference.
This retrieves the category ID that was previously set as the user's default protocol
category using setDefaultProtocolCategory(). The value is stored in a browser cookie and
persists across sessions. Returns the category ID as a string, or undefined if no default
has been set. Use this to pre-select categories in forms, filter protocols by user preference,
or provide personalized protocol views.
getProtocolCategories(callback)
Retrieve all available protocol categories.
This fetches the complete list of protocol categories from the system via the REST API.
Protocol categories are used to organize and classify protocols into groups (e.g.,
"Safety Procedures", "Standard Operating Procedures", "Analytical Methods"). The category
list is returned asynchronously via callback. Use this to populate category dropdowns,
display protocol organization, or filter protocols by category.
Kind: global function
| Param | Type | Description |
|---|---|---|
| callback | function | Callback function executed with the category list |
| callback.categoryList | Array.<Object> | Array of protocol category objects |
Example
// Get and display all protocol categories
eLabSDK.ready(function() {
var protocol = new eLabSDK.Protocol();
protocol.getProtocolCategories(function(categories) {
console.log('Protocol Categories:', categories);
categories.forEach(function(category) {
console.log('- ' + category.name + ' (ID: ' + category.categoryID + ')');
});
});
});
Example
// Populate category dropdown
eLabSDK.ready(function() {
var protocol = new eLabSDK.Protocol();
protocol.getProtocolCategories(function(categories) {
var $select = $('#protocolCategorySelect');
categories.forEach(function(category) {
var $option = $('<option></option>')
.val(category.categoryID)
.text(category.name);
$select.append($option);
});
});
});
Example
// Filter protocols by category
eLabSDK.ready(function() {
var protocol = new eLabSDK.Protocol();
protocol.getProtocolCategories(function(categories) {
// Find specific category
var safetyCategory = categories.find(function(cat) {
return cat.name === 'Safety Procedures';
});
if (safetyCategory) {
console.log('Safety category ID: ' + safetyCategory.categoryID);
loadProtocolsByCategory(safetyCategory.categoryID);
}
});
});
setDefaultProtocolCategory(categoryID)
Set the user's default protocol category preference.
This stores the specified category ID as the user's default protocol category in a browser
cookie. The default category is used to pre-select a category when creating new protocols
or filtering protocol lists, providing a personalized workflow. The preference persists
across browser sessions until changed. Use this to remember user preferences or set default
contexts for protocol operations.
Kind: global function
| Param | Type | Description |
|---|---|---|
| categoryID | number | The numeric category ID to set as default |
Example
// Set default category when user selects it
eLabSDK.ready(function() {
var protocol = new eLabSDK.Protocol();
$('#protocolCategorySelect').on('change', function() {
var selectedCategoryID = parseInt($(this).val());
protocol.setDefaultProtocolCategory(selectedCategoryID);
console.log('Default protocol category saved: ' + selectedCategoryID);
});
});
Example
// Set default based on user's most-used category
eLabSDK.ready(function() {
var protocol = new eLabSDK.Protocol();
$.get('/api/v1/users/current/protocol-stats', function(stats) {
var mostUsedCategoryID = stats.mostUsedCategory;
protocol.setDefaultProtocolCategory(mostUsedCategoryID);
console.log('Set default to most-used category: ' + mostUsedCategoryID);
});
});
Example
// Let user set default category via button
eLabSDK.ready(function() {
var protocol = new eLabSDK.Protocol();
var setDefaultBtn = new eLabSDK.GUI.Button({
label: 'Set as Default',
icon: 'star',
action: function() {
var currentCategoryID = getCurrentlySelectedCategory();
protocol.setDefaultProtocolCategory(currentCategoryID);
alert('Default category updated');
}
});
});
getDefaultProtocolCategory()
Get the user's default protocol category preference.
This retrieves the category ID that was previously set as the user's default protocol
category using setDefaultProtocolCategory(). The value is stored in a browser cookie and
persists across sessions. Returns the category ID as a string, or undefined if no default
has been set. Use this to pre-select categories in forms, filter protocols by user preference,
or provide personalized protocol views.
Kind: global function
Returns: string ⎮ undefined - The default category ID as a string, or undefined if not set
Example
// Pre-select default category in dropdown
eLabSDK.ready(function() {
var protocol = new eLabSDK.Protocol();
protocol.getProtocolCategories(function(categories) {
var $select = $('#protocolCategorySelect');
// Populate dropdown
categories.forEach(function(category) {
var $option = $('<option></option>')
.val(category.categoryID)
.text(category.name);
$select.append($option);
});
// Pre-select default
var defaultCategoryID = protocol.getDefaultProtocolCategory();
if (defaultCategoryID) {
$select.val(defaultCategoryID);
console.log('Pre-selected default category: ' + defaultCategoryID);
}
});
});
Example
// Use default category for new protocol
eLabSDK.ready(function() {
var protocol = new eLabSDK.Protocol();
var createProtocolBtn = new eLabSDK.GUI.Button({
label: 'Create Protocol',
icon: 'plus',
action: function() {
var defaultCategory = protocol.getDefaultProtocolCategory();
if (defaultCategory) {
openProtocolCreationDialog({ categoryID: defaultCategory });
} else {
openProtocolCreationDialog();
}
}
});
});
Example
// Filter protocols by user's default category
eLabSDK.ready(function() {
var protocol = new eLabSDK.Protocol();
var defaultCategory = protocol.getDefaultProtocolCategory();
if (defaultCategory) {
console.log('Filtering by default category: ' + defaultCategory);
$.get('/api/v1/protocols?categoryID=' + defaultCategory, function(protocols) {
displayProtocols(protocols);
});
} else {
console.log('No default category set - showing all protocols');
loadAllProtocols();
}
});
© 2023 eLabNext
Updated about 18 hours ago