diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/FormUtil.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/FormUtil.js index 52f46c035cbdbbcc50e5923c5aee552e2c2c9732..4e527bc2c293db079b130bcaf1a73309bf9b61ef 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/FormUtil.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/FormUtil.js @@ -5,6 +5,47 @@ var FormUtil = new function() { // 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) { var $fieldset = $('<fieldset>'); diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/Util.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/Util.js index 4a4e426ddb861c0c69350a218c22683a85cadf46..5bd5ec0f6c7dd8dfe5602db01c2d5b1a5a4c512e 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/Util.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/Util.js @@ -31,7 +31,7 @@ var Util = new function() { $.blockUI({ message: '', css: { width: '0px' } }); } - this.blockUI = function(message) { + this.blockUI = function(message, extraCSS) { this.unblockUI(); BlockScrollUtil.disable_scroll(); @@ -45,6 +45,13 @@ var Util = new function() { 'cursor' : 'default' }; + if(extraCSS) { + for(extraCSSProperty in extraCSS) { + var extraCSSValue = extraCSS[extraCSSProperty]; + css[extraCSSProperty] = extraCSSValue; + } + } + $('#navbar').block({ message: '', css: { width: '0px' } }); if(message) { $.blockUI({ message: message, css: css}); @@ -68,13 +75,17 @@ var Util = new function() { // // 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; if(!isiPad) { withHTML = withHTML + "<br>" + "<a class='btn'>Accept</a>"; } - this.blockUINoMessage(); + if(!noBlock) { + this.blockUINoMessage(); + } + var localReference = this; jError( withHTML, diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js index 0932bfb71b30a5882c2057e1feaa57229f47c419..a21a2b0d789ea59b16c94b22ec2951a1fed5a1e2 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js @@ -420,6 +420,21 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod var sampleChildrenLinks = (this.sample)?this.sample.children:null; 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 // @@ -529,6 +544,12 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod this.enableEditButtonEvent(); } + if(!(this.mode === SampleFormMode.VIEW)) { + $("#generate_children").click(function(event) { + localInstance._generateChildren(); + }); + } + //Events to take care of a dirty form $("#sampleSpaceProject").change(function(event) { localInstance.isFormDirty = true; @@ -776,4 +797,146 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod 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 diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/SampleLinksWidget.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/SampleLinksWidget.js index 98f1f2b74f46b3057bfc68743aa0d4211146785e..9fbeb8cf981160d18c35d970e989c7087e380ae7 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/SampleLinksWidget.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/widgets/SampleLinksWidget.js @@ -513,6 +513,16 @@ function SampleLinksWidget(containerId, profile, serverFacade, title, sampleType 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() { var sampleIdentifiers = new Array(); for(sampleObjKey in this.samplesRemoved) {