eLabSDK.Page.Experiment
Functions
| Name | Description |
|---|---|
| registerEvent(eventType, fn) | Register a callback to listen for experiment-specific events. |
This allows you to subscribe to important experiment lifecycle events and respond to them
with custom logic. Currently supports the 'finalSignature' event, which fires when an
experiment receives its final signature (locking it for editing). The callback receives
an event object containing details about the experiment. Use this to trigger custom
workflows, notifications, or integrations when experiments are signed.
addButtonToBrowser(btn) | Add a custom button to the experiment browser page.
This inserts a custom button into the experiment browser interface, positioning it before
the default "Add Experiment" button. The button is rendered and inserted automatically.
Use this to add custom actions accessible from the experiment list/browser view, such as
bulk operations, custom exports, or specialized experiment creation workflows.
getExperimentID() | Get the ID of the currently displayed experiment.
This retrieves the experiment ID from the current experiment page context. Returns the
numeric ID of the experiment being viewed or edited. Use this to reference the current
experiment in API calls, custom actions, or when building URLs. Only works when called
on an experiment page (not on the experiment browser).
addBulkSampleAction(actionTitle, callback) | Allows the creation of bulk sample actions in the sample list or experiment sample sections
getExperimentObject() | Get an eLabSDK.Experiment object for the currently displayed experiment.
This creates and returns an eLabSDK.Experiment object pre-initialized with the data from
the current experiment page. The experiment object provides access to experiment properties,
sections, and manipulation methods. Only call this after the experiment page is ready
(in onReady callback). For loading experiments outside the experiment page context, use
new eLabSDK.Experiment({ experimentID: id }) directly instead.
getExperimentData() | Get the raw data object for the currently displayed experiment.
This retrieves the complete experiment data structure from the current experiment page,
including all header information, sections, metadata, and settings. Returns null if no
experiment data is available. Use this when you need direct access to the raw experiment
data structure without the wrapper methods provided by eLabSDK.Experiment. For most cases,
prefer using getExperimentObject() which provides a cleaner API.
registerAction(menuConfig) | Registers a new menu item in a section
registerEvent(eventType, fn)
Register a callback to listen for experiment-specific events.
This allows you to subscribe to important experiment lifecycle events and respond to them
with custom logic. Currently supports the 'finalSignature' event, which fires when an
experiment receives its final signature (locking it for editing). The callback receives
an event object containing details about the experiment. Use this to trigger custom
workflows, notifications, or integrations when experiments are signed.
Kind: global function
| Param | Type | Description |
|---|---|---|
| eventType | string | The type of event to listen for. Currently supported: 'finalSignature' |
| fn | function | Callback function to execute when the event fires. Receives event object as parameter. |
| fn.ev | Object | Event object containing experiment details |
| fn.ev.experimentID | number | The ID of the experiment that was signed |
Example
// Listen for final signature event
var experimentPage = new eLabSDK.Page.Experiment();
experimentPage.registerEvent('finalSignature', function(ev) {
console.log('Experiment ' + ev.experimentID + ' has been finally signed');
alert('Experiment is now locked and read-only');
});
Example
// Trigger custom workflow on signature
var experimentPage = new eLabSDK.Page.Experiment();
experimentPage.registerEvent('finalSignature', function(ev) {
// Send notification to team
$.post('/api/notifications/send', {
message: 'Experiment ' + ev.experimentID + ' has been signed',
recipients: ['[email protected]']
});
// Archive experiment data
archiveExperiment(ev.experimentID);
});
Example
// Log signature events for audit
var experimentPage = new eLabSDK.Page.Experiment();
experimentPage.registerEvent('finalSignature', function(ev) {
var logEntry = {
experimentID: ev.experimentID,
timestamp: new Date().toISOString(),
action: 'final_signature',
user: eLabSDK.User.getUserFullname()
};
// Send to audit system
$.post('/api/audit/log', logEntry);
});
addButtonToBrowser(btn)
Add a custom button to the experiment browser page.
This inserts a custom button into the experiment browser interface, positioning it before
the default "Add Experiment" button. The button is rendered and inserted automatically.
Use this to add custom actions accessible from the experiment list/browser view, such as
bulk operations, custom exports, or specialized experiment creation workflows.
Kind: global function
| Param | Type | Description |
|---|---|---|
| btn | eLabSDK.GUI.Button | An eLabSDK.GUI.Button instance to add to the browser |
Example
// Add custom export button to experiment browser
eLabSDK.ready(function() {
var experimentPage = new eLabSDK.Page.Experiment();
var exportBtn = new eLabSDK.GUI.Button({
label: 'Export All',
icon: 'fa-download',
type: 'success',
action: function() {
exportAllExperiments();
}
});
experimentPage.addButtonToBrowser(exportBtn);
});
Example
// Add template creation button
eLabSDK.ready(function() {
var experimentPage = new eLabSDK.Page.Experiment();
var templateBtn = new eLabSDK.GUI.Button({
label: 'Create from Template',
icon: 'fa-file',
action: function() {
openTemplateSelector();
}
});
experimentPage.addButtonToBrowser(templateBtn);
});
getExperimentID()
Get the ID of the currently displayed experiment.
This retrieves the experiment ID from the current experiment page context. Returns the
numeric ID of the experiment being viewed or edited. Use this to reference the current
experiment in API calls, custom actions, or when building URLs. Only works when called
on an experiment page (not on the experiment browser).
Kind: global function
Returns: number - The numeric ID of the current experiment
Example
// Get current experiment ID
eLabSDK.ready(function() {
var experimentPage = new eLabSDK.Page.Experiment({
onReady: function() {
var expId = experimentPage.getExperimentID();
console.log('Current experiment ID: ' + expId);
}
});
});
Example
// Use in custom action button
eLabSDK.ready(function() {
var experimentPage = new eLabSDK.Page.Experiment({
onReady: function() {
var exportBtn = new eLabSDK.GUI.Button({
label: 'Custom Export',
action: function() {
var expId = experimentPage.getExperimentID();
window.open('/custom/export?experimentID=' + expId);
}
});
experimentPage.addButtonToExperimentTopToolbar(exportBtn);
}
});
});
Example
// Load additional data for current experiment
eLabSDK.ready(function() {
var experimentPage = new eLabSDK.Page.Experiment({
onReady: function() {
var expId = experimentPage.getExperimentID();
$.get('/api/v1/experiments/' + expId + '/metadata', function(data) {
displayMetadata(data);
});
}
});
});
addBulkSampleAction(actionTitle, callback)
Allows the creation of bulk sample actions in the sample list or experiment sample sections
Kind: global function
Response: in callback{json}
{
sampleIDs: [],
seriesIDs: [],
sampleIDsIncludingSeriesClicked: [],
sampleCount: 0,
archivedSamples: 0
}
| Param | Type | Description |
|---|---|---|
| actionTitle | string | : name of the action displayed in the selector |
| callback | function | : function to execute when the action is selected. Provide information on the chosen samples. |
getExperimentObject()
Get an eLabSDK.Experiment object for the currently displayed experiment.
This creates and returns an eLabSDK.Experiment object pre-initialized with the data from
the current experiment page. The experiment object provides access to experiment properties,
sections, and manipulation methods. Only call this after the experiment page is ready
(in onReady callback). For loading experiments outside the experiment page context, use
new eLabSDK.Experiment({ experimentID: id }) directly instead.
Kind: global function
Returns: eLabSDK.Experiment - An initialized Experiment object for the current experiment
Example
// Get experiment object and access its data
eLabSDK.ready(function() {
var experimentPage = new eLabSDK.Page.Experiment({
onReady: function() {
var exp = this.getExperimentObject();
console.log('Experiment ID: ' + exp.getExperimentID());
console.log('Study ID: ' + exp.getStudyID());
console.log('Number of sections: ' + exp.sections.length);
}
});
});
Example
// Add section to current experiment
eLabSDK.ready(function() {
var experimentPage = new eLabSDK.Page.Experiment({
onReady: function() {
var exp = this.getExperimentObject();
exp.addSection({
sectionHeader: 'Additional Notes',
sectionType: 'PARAGRAPH',
onCreated: function() {
console.log('Section added successfully');
}
});
}
});
});
Example
// Get specific section from experiment
eLabSDK.ready(function() {
var experimentPage = new eLabSDK.Page.Experiment({
onReady: function() {
var exp = this.getExperimentObject();
var firstSection = exp.sections[0];
if (firstSection) {
console.log('First section type: ' + firstSection.data.sectionType);
}
}
});
});
getExperimentData()
Get the raw data object for the currently displayed experiment.
This retrieves the complete experiment data structure from the current experiment page,
including all header information, sections, metadata, and settings. Returns null if no
experiment data is available. Use this when you need direct access to the raw experiment
data structure without the wrapper methods provided by eLabSDK.Experiment. For most cases,
prefer using getExperimentObject() which provides a cleaner API.
Kind: global function
Returns: Object ⎮ null - The raw experiment data object, or null if not availableObject - returns.headerinfo - Experiment header information (name, study, dates, etc.)Array - returns.data - Array of section data objectsArray - returns.meta - Array of experiment metadata fields
Example
// Get raw experiment data
eLabSDK.ready(function() {
var experimentPage = new eLabSDK.Page.Experiment({
onReady: function() {
var data = this.getExperimentData();
if (data) {
console.log('Experiment name: ' + data.headerinfo.experimentName);
console.log('Study ID: ' + data.headerinfo.studyID);
console.log('Created: ' + data.headerinfo.creationDate);
console.log('Sections: ' + data.data.length);
}
}
});
});
Example
// Access section data directly
eLabSDK.ready(function() {
var experimentPage = new eLabSDK.Page.Experiment({
onReady: function() {
var data = this.getExperimentData();
if (data && data.data) {
data.data.forEach(function(section, index) {
console.log('Section ' + (index + 1) + ': ' + section.sectionType);
console.log(' Header: ' + section.header);
});
}
}
});
});
Example
// Check if data is available before proceeding
eLabSDK.ready(function() {
var experimentPage = new eLabSDK.Page.Experiment({
onReady: function() {
var data = this.getExperimentData();
if (data === null) {
console.log('Experiment data not available');
return;
}
// Process data
processExperimentData(data);
}
});
});
registerAction(menuConfig)
Registers a new menu item in a section
Kind: global function
| Param | Type | Description |
|---|---|---|
| menuConfig | object | |
| menuConfig.showOnSigned | bool | Show this menu item when the experiment is signed (default = true) |
| menuConfig.showOnNotSigned | bool | Show this menu item when the experiment is not signed (default = true) |
| menuConfig.label | string | Label to be displayed next to the icon |
© 2023 eLabNext
Updated about 3 hours ago