Skip to content
Snippets Groups Projects
Commit 0e7fa478 authored by juanf's avatar juanf
Browse files

SSDM-227: ELN UI - Children Wizard - Client Side

SVN: 31495
parent 448a5130
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,47 @@ var FormUtil = new function() { ...@@ -5,6 +5,47 @@ var FormUtil = new function() {
// Standard Form Fields // Standard Form Fields
// //
this.getSampleTypeDropdown = function(id, isRequired) {
var sampleTypes = this.profile.getAllSampleTypes();
var $component = $("<select>", {"id" : id});
if (isRequired) {
$component.attr('required', '');
}
$component.append($("<option>").attr('value', '').attr('selected', '').text(''));
for(var i = 0; i < sampleTypes.length; i++) {
var sampleType = sampleTypes[i];
var label = Util.getEmptyIfNull(sampleType.description);
if(label === "") {
label = sampleType.code;
}
$component.append($("<option>").attr('value',sampleType.code).text(label));
}
return $component;
}
this.getFieldForComponentWithLabel = function($component, label) {
var $fieldset = $('<fieldset>');
var $controlGroup = $('<div>', {class : 'control-group'});
var $controlLabel = $('<label>', {class : 'control-label'}).text(label + ":");
var $controls = $('<div>', {class : 'controls'});
$controlGroup.append($controlLabel);
$controlGroup.append($controls);
$fieldset.append($controlGroup);
$controls.append($component);
if($component.attr('required')) {
$controls.append(' (Required)')
}
return $fieldset;
}
this.getFieldForPropertyTypeWithLabel = function(propertyType) { this.getFieldForPropertyTypeWithLabel = function(propertyType) {
var $fieldset = $('<fieldset>'); var $fieldset = $('<fieldset>');
......
...@@ -31,7 +31,7 @@ var Util = new function() { ...@@ -31,7 +31,7 @@ var Util = new function() {
$.blockUI({ message: '', css: { width: '0px' } }); $.blockUI({ message: '', css: { width: '0px' } });
} }
this.blockUI = function(message) { this.blockUI = function(message, extraCSS) {
this.unblockUI(); this.unblockUI();
BlockScrollUtil.disable_scroll(); BlockScrollUtil.disable_scroll();
...@@ -45,6 +45,13 @@ var Util = new function() { ...@@ -45,6 +45,13 @@ var Util = new function() {
'cursor' : 'default' 'cursor' : 'default'
}; };
if(extraCSS) {
for(extraCSSProperty in extraCSS) {
var extraCSSValue = extraCSS[extraCSSProperty];
css[extraCSSProperty] = extraCSSValue;
}
}
$('#navbar').block({ message: '', css: { width: '0px' } }); $('#navbar').block({ message: '', css: { width: '0px' } });
if(message) { if(message) {
$.blockUI({ message: message, css: css}); $.blockUI({ message: message, css: css});
...@@ -68,13 +75,17 @@ var Util = new function() { ...@@ -68,13 +75,17 @@ var Util = new function() {
// //
// Methods to show messages as pop ups // Methods to show messages as pop ups
// //
this.showError = function(withHTML, andCallback) {
this.showError = function(withHTML, andCallback, noBlock) {
var isiPad = navigator.userAgent.match(/iPad/i) != null; var isiPad = navigator.userAgent.match(/iPad/i) != null;
if(!isiPad) { if(!isiPad) {
withHTML = withHTML + "<br>" + "<a class='btn'>Accept</a>"; withHTML = withHTML + "<br>" + "<a class='btn'>Accept</a>";
} }
this.blockUINoMessage(); if(!noBlock) {
this.blockUINoMessage();
}
var localReference = this; var localReference = this;
jError( jError(
withHTML, withHTML,
......
...@@ -420,6 +420,21 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod ...@@ -420,6 +420,21 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod
var sampleChildrenLinks = (this.sample)?this.sample.children:null; var sampleChildrenLinks = (this.sample)?this.sample.children:null;
this.sampleLinksChildren = new SampleLinksWidget(sampleChildrenWidgetId, this.profile, this.serverFacade, "Children", requiredChildren, isDisabled, sampleChildrenLinks); this.sampleLinksChildren = new SampleLinksWidget(sampleChildrenWidgetId, this.profile, this.serverFacade, "Children", requiredChildren, isDisabled, sampleChildrenLinks);
//
// GENERATE CHILDREN
//
if(!(this.mode === SampleFormMode.VIEW)) {
component += "<fieldset>";
component += "<div class='control-group'>";
component += "<div class='controls'>";
component += "<a class='btn' id='generate_children'>Generate Children</a>";
component += "</div>";
component += "</div>";
component += "</fieldset>";
}
// //
// SAMPLE TYPE FIELDS // SAMPLE TYPE FIELDS
// //
...@@ -529,6 +544,12 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod ...@@ -529,6 +544,12 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod
this.enableEditButtonEvent(); this.enableEditButtonEvent();
} }
if(!(this.mode === SampleFormMode.VIEW)) {
$("#generate_children").click(function(event) {
localInstance._generateChildren();
});
}
//Events to take care of a dirty form //Events to take care of a dirty form
$("#sampleSpaceProject").change(function(event) { $("#sampleSpaceProject").change(function(event) {
localInstance.isFormDirty = true; localInstance.isFormDirty = true;
...@@ -776,4 +797,146 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod ...@@ -776,4 +797,146 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod
this.serverFacade.searchDataSetsWithTypeForSamples("ELN_PREVIEW", [this.sample.permId], previewCallback); this.serverFacade.searchDataSetsWithTypeForSamples("ELN_PREVIEW", [this.sample.permId], previewCallback);
} }
this._generateChildren = function() {
// Buttons
var getGeneratedChildrenCodes = function() {
//Get selected parents
var $parentsFields = $("#parentsToGenerateChildren").find("input:checked");
//Group parents by type - this structure helps the create children algorithm
var selectedParentsByType = {};
for(var i = 0; i < $parentsFields.length; i++) {
var parentIdentifier = $parentsFields[i].id;
var parent = parentsByIdentifier[parentIdentifier];
var typeList = selectedParentsByType[parent.sampleTypeCode];
if(!typeList) {
typeList = [];
selectedParentsByType[parent.sampleTypeCode] = typeList;
}
typeList.push(parent);
}
//Generate Children from parents
var generatedChildren = [];
var parentSampleCode = $("#sampleCode").val();
for(var sampleTypeCode in selectedParentsByType) {
var parentsOfType = selectedParentsByType[sampleTypeCode];
var newGeneratedChildren = [];
for(var i = 0; i < parentsOfType.length; i++) {
var parentOfType = parentsOfType[i];
if(generatedChildren.length === 0) {
newGeneratedChildren.push(parentSampleCode + "_" + parentOfType.code);
} else {
for(var k = 0; k < generatedChildren.length; k++) {
newGeneratedChildren.push(generatedChildren[k] + "_" + parentOfType.code);
}
}
}
generatedChildren = newGeneratedChildren;
}
return generatedChildren;
}
var $previewButton = $("<a>", { "class" : "btn" }).append("<i class='icon-repeat'></i>");
$previewButton.click(function(event) {
var generatedChildren = getGeneratedChildrenCodes();
//Show generated children
$("#previewChildrenGenerator").empty();
for(var i = 0; i < generatedChildren.length; i++) {
$("#previewChildrenGenerator").append(generatedChildren[i] + "<br />");
}
});
var _this = this;
var $generateButton = $("<a>", { "class" : "btn" }).append("Generate!");
$generateButton.click(function(event) {
var generatedChildrenSpace = null;
if(_this.isELNExperiment) {
generatedChildrenSpace = $("#sampleSpaceProject")[0].value.split("/")[1];
} else {
generatedChildrenSpace = $("#sampleSpaceProject").val();
}
var generatedChildrenCodes = getGeneratedChildrenCodes();
var generatedChildrenType = $("#childrenTypeSelector").val();
if(generatedChildrenType === "") {
Util.showError("Please select the children type.", function() {}, true);
} else {
for(var i = 0; i < generatedChildrenCodes.length; i++) {
var virtualSample = new Object();
virtualSample.code = generatedChildrenCodes[i];
virtualSample.identifier = "/" + generatedChildrenSpace + "/" + virtualSample.code;
virtualSample.sampleTypeCode = generatedChildrenType;
_this.sampleLinksChildren.addSample(virtualSample);
}
Util.unblockUI();
}
});
var $cancelButton = $("<a>", { "class" : "btn" }).append("<i class='icon-remove'></i>");
$cancelButton.click(function(event) {
Util.unblockUI();
});
// Parents
var $parents = $("<div>");
var parentsIdentifiers = this.sampleLinksParents.getSamplesIdentifiers();
var parentsByType = {};
var parentsByIdentifier = {};
for(var i = 0; i < parentsIdentifiers.length; i++) {
var parent = this.sampleLinksParents.getSampleByIdentifier(parentsIdentifiers[i]);
var typeList = parentsByType[parent.sampleTypeCode];
if(!typeList) {
typeList = [];
parentsByType[parent.sampleTypeCode] = typeList;
}
typeList.push(parent);
parentsByIdentifier[parent.identifier] = parent;
}
for(var parentTypeCode in parentsByType) {
$parents.append(parentTypeCode + ":").append($("<br>"));
var parentsOfType = parentsByType[parentTypeCode];
for(var i = 0; i < parentsOfType.length; i++) {
var parent = parentsOfType[i];
var parentProperty = new Object();
parentProperty.code = parent.identifier;
parentProperty.description = parent.identifier;
parentProperty.label = parent.code;
parentProperty.dataType = "BOOLEAN";
$parents.append(FormUtil.getFieldForPropertyTypeWithLabel(parentProperty));
}
}
var $parentsComponent = $("<fieldset id='parentsToGenerateChildren'>");
$parentsComponent.append($("<legend>").text("Parents"))
$parentsComponent.append($parents);
// Children
var $childrenTypeDropdown = FormUtil.getSampleTypeDropdown('childrenTypeSelector', true);
var $childrenTypeDropdownWithLabel = FormUtil.getFieldForComponentWithLabel($childrenTypeDropdown, 'Type');
var $childrenComponent = $("<fieldset>");
$childrenComponent.append($("<legend>").text("Children"))
$childrenComponent.append($childrenTypeDropdownWithLabel);
// Preview
var $previewComponent = $("<fieldset>");
$previewComponent.append($("<legend>").append("Preview ").append($previewButton));
$previewComponent.append($("<div>", {"id" : "previewChildrenGenerator"}));
// Mounting the widget with the components
var $childrenGenerator = $("<form>", { "class" : "form-horizontal"})
.append($("<div>", {"style" : "text-align:right;"}).append($cancelButton))
.append($("<h1>").append("Children Generator"))
.append($parentsComponent)
.append($childrenComponent)
.append($previewComponent)
.append($("<br>")).append($generateButton);
// Show Widget
Util.blockUI($childrenGenerator, {'text-align' : 'left', 'top' : '10%'});
}
} }
\ No newline at end of file
...@@ -513,6 +513,16 @@ function SampleLinksWidget(containerId, profile, serverFacade, title, sampleType ...@@ -513,6 +513,16 @@ function SampleLinksWidget(containerId, profile, serverFacade, title, sampleType
return sampleIdentifiers; return sampleIdentifiers;
} }
this.getSampleByIdentifier = function(identifier) {
for(sampleObjKey in this.samples) {
var sampleObj = this.samples[sampleObjKey];
if(sampleObj !== null && sampleObj.identifier === identifier) {
return sampleObj;
}
}
return null;
}
this.getSamplesRemovedIdentifiers = function() { this.getSamplesRemovedIdentifiers = function() {
var sampleIdentifiers = new Array(); var sampleIdentifiers = new Array();
for(sampleObjKey in this.samplesRemoved) { for(sampleObjKey in this.samplesRemoved) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment