diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/controllers/MainController.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/controllers/MainController.js index 10028f28c7f4eeb2bdcf4c7ff2c38a468ec61045..b1fd0124760056e0f300c46033d658f9016f3143 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/controllers/MainController.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/controllers/MainController.js @@ -193,7 +193,15 @@ function MainController(profile) { var _this = this; this.serverFacade.listExperimentsForIdentifiers([arg], function(data) { document.title = "Experiment " + arg; - _this._showExperimentPage(data.result[0]); + _this._showExperimentPage(data.result[0], FormMode.VIEW); + window.scrollTo(0,0); + }); + break; + case "showEditExperimentPageFromIdentifier": + var _this = this; + this.serverFacade.listExperimentsForIdentifiers([arg], function(data) { + document.title = "Experiment " + arg; + _this._showExperimentPage(data.result[0], FormMode.EDIT); window.scrollTo(0,0); }); break; @@ -357,9 +365,9 @@ function MainController(profile) { this.currentView = projectForm; } - this._showExperimentPage = function(experiment) { + this._showExperimentPage = function(experiment, mode) { //Show Form - var experimentForm = new ExperimentForm("mainContainer", this, experiment, FormMode.VIEW); + var experimentForm = new ExperimentForm("mainContainer", this, experiment, mode); experimentForm.init(); this.currentView = experimentForm; } 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 ba756edbfd91e0ebe24d3812faa1a4fa4f7a5bc0..3479279f552a7e91da676486a02ae0e8f62f6119 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 @@ -101,23 +101,24 @@ var FormUtil = new function() { } else { vocabulary = this.profile.getVocabularyById(propertyType.vocabulary); } - $component = this._getDropDownFieldForVocabulary(propertyType.code, vocabulary.terms, propertyType.description, propertyType.mandatory); + var codeWithoutSimbols = propertyType.code.replace('$','\\$').replace(/\./g,'\\.'); + $component = this._getDropDownFieldForVocabulary(codeWithoutSimbols, vocabulary.terms, propertyType.description, propertyType.mandatory); } else if (propertyType.dataType === "HYPERLINK") { - $component = this._getInputField("url", propertyType.code, propertyType.description, null, propertyType.mandatory); + $component = this._getInputField("url", codeWithoutSimbols, propertyType.description, null, propertyType.mandatory); } else if (propertyType.dataType === "INTEGER") { - $component = this._getInputField("number", propertyType.code, propertyType.description, '1', propertyType.mandatory); + $component = this._getInputField("number", codeWithoutSimbols, propertyType.description, '1', propertyType.mandatory); } else if (propertyType.dataType === "MATERIAL") { - $component = this._getInputField("text", propertyType.code, propertyType.description, null, propertyType.mandatory); + $component = this._getInputField("text", codeWithoutSimbols, propertyType.description, null, propertyType.mandatory); } else if (propertyType.dataType === "MULTILINE_VARCHAR") { - $component = this._getTextBox(propertyType.code, propertyType.description, propertyType.mandatory); + $component = this._getTextBox(codeWithoutSimbols, propertyType.description, propertyType.mandatory); } else if (propertyType.dataType === "REAL") { - $component = this._getInputField("number", propertyType.code, propertyType.description, 'any', propertyType.mandatory); + $component = this._getInputField("number", codeWithoutSimbols, propertyType.description, 'any', propertyType.mandatory); } else if (propertyType.dataType === "TIMESTAMP") { - $component = this._getDatePickerField(propertyType.code, propertyType.description, propertyType.mandatory); + $component = this._getDatePickerField(codeWithoutSimbols, propertyType.description, propertyType.mandatory); } else if (propertyType.dataType === "VARCHAR") { - $component = this._getInputField("text", propertyType.code, propertyType.description, null, propertyType.mandatory); + $component = this._getInputField("text", codeWithoutSimbols, propertyType.description, null, propertyType.mandatory); } else if (propertyType.dataType === "XML") { - $component = this._getTextBox(propertyType.code, propertyType.description, propertyType.mandatory); + $component = this._getTextBox(codeWithoutSimbols, propertyType.description, propertyType.mandatory); } return $component; diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/ExperimentForm.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/ExperimentForm.js index 6775421812a0fe54a5c767e9b495169f2298d377..49fd9a00b6c1bfd378bdf085863978562fc536f8 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/ExperimentForm.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/ExperimentForm.js @@ -18,7 +18,11 @@ function ExperimentForm(containerId, mainController, experiment, mode) { this._mainController = mainController; this._experiment = experiment; this._mode = mode; - this.isFormDirty = false; + this._isFormDirty = false; + + this.isDirty = function() { + return this._isFormDirty; + } this.init = function() { this.repaint(); @@ -70,6 +74,13 @@ function ExperimentForm(containerId, mainController, experiment, mode) { }); $formTitle.append(" "); $formTitle.append($createSubExpBtn); + + var $editBtn = $("<a>", { "class" : "btn btn-default"}).append("<span class='glyphicon glyphicon-edit'></span> Enable Editing"); + $editBtn.click(function() { + _this._mainController.changeView("showEditExperimentPageFromIdentifier", _this._experiment.identifier); + }); + $formTitle.append(" "); + $formTitle.append($editBtn); } // @@ -81,14 +92,24 @@ function ExperimentForm(containerId, mainController, experiment, mode) { var identifierParts = this._experiment.identifier.split("/"); $formColumn.append(FormUtil.getFieldForLabelWithText("Type", this._experiment.experimentTypeCode)); - $formColumn.append(FormUtil.getFieldForLabelWithText("Project", identifierParts[2])); + $formColumn.append(FormUtil.getFieldForLabelWithText("Project", identifierParts[0] + "/" + identifierParts[1] + "/" + identifierParts[2])); + var $projectField = FormUtil._getInputField("text", "PROJECT", "project", null, true); + $projectField.val(identifierParts[0] + "/" + identifierParts[1] + "/" + identifierParts[2]); + $projectField.hide(); + $formColumn.append($projectField); if(this._mode === FormMode.VIEW || this._mode === FormMode.EDIT) { $formColumn.append(FormUtil.getFieldForLabelWithText("Code", identifierParts[3])); + + var $codeField = FormUtil._getInputField("text", "CODE", "code", null, true); + $codeField.val(identifierParts[3]); + $codeField.hide(); + $formColumn.append($codeField); + $formColumn.append(FormUtil.getFieldForLabelWithText("Registrator", this._experiment.registrationDetails.userId)); $formColumn.append(FormUtil.getFieldForLabelWithText("Registration Date", (new Date(this._experiment.registrationDetails.registrationDate)).toLocaleString())); } else if(this._mode === FormMode.CREATE){ - var $codeField = FormUtil._getInputField("text", "code", "code", null, true); + var $codeField = FormUtil._getInputField("text", "CODE", "code", null, true); $formColumn.append(FormUtil.getFieldForComponentWithLabel($codeField, "Code")); } @@ -117,12 +138,26 @@ function ExperimentForm(containerId, mainController, experiment, mode) { var $controlGroup = null; - if(this._mode === FormMode.VIEW) { + if(this._mode === FormMode.VIEW) { //Show values without input boxes if the form is in view mode $controlGroup = FormUtil.getFieldForLabelWithText(propertyType.label, this._experiment.properties[propertyType.code]); } else { var $component = FormUtil.getFieldForPropertyType(propertyType); + + //Update values if is into edit mode + if(this._mode === FormMode.EDIT) { + if(propertyType.dataType === "BOOLEAN") { + $component.prop('checked', this._experiment.properties[propertyType.code] === "true"); + } else { + var value = this._experiment.properties[propertyType.code]; + if(!value && propertyType.code.charAt(0) === '$') { + value = this._experiment.properties[propertyType.code.substr(1)]; + } + $component.val(value); + } + } + $component.change(function(event) { - localInstance.isFormDirty = true; + _this._isFormDirty = true; }); $controlGroup = FormUtil.getFieldForComponentWithLabel($component, propertyType.label); } @@ -133,6 +168,85 @@ function ExperimentForm(containerId, mainController, experiment, mode) { $formColumn.append($fieldset); } + if(this._mode === FormMode.EDIT || this._mode === FormMode.CREATE) { + var label = ""; + + if(this._mode === FormMode.EDIT) { + label = "Update Experiment " + this._experiment.code; + } else if(this._mode === FormMode.CREATE) { + label = "Create Experiment"; + } + + var $submitButton = $('<fieldset>') + .append($('<div>', { class : "form-group"})) + .append($('<div>', {class: FormUtil.controlColumnClass}) + .append($('<input>', { class : 'btn btn-primary', 'type' : 'submit', 'value' : label}))); + + $submitButton.click(function() { + _this._updateExperiment(); + }); + $formColumn.append($submitButton); + } + $("#" + this._containerId).append($form); } + + this._updateExperiment = function() { + Util.blockUI(); + + var experimentType = this._mainController.profile.getExperimentTypeForExperimentTypeCode(this._experiment.experimentTypeCode); + + //Identification Info + var projectIdentifier = $("#PROJECT").val().split("/"); + var experimentSpace = projectIdentifier[1]; + var experimentProject = projectIdentifier[2]; + var experimentCode = $("#CODE").val(); + + //Properties + var properties = {}; + + for(var i = 0; i < experimentType.propertyTypeGroups.length; i++) { + var propertyTypeGroup = experimentType.propertyTypeGroups[i]; + for(var j = 0; j < propertyTypeGroup.propertyTypes.length; j++) { + var propertyType = propertyTypeGroup.propertyTypes[j]; + var value = null; + + if (propertyType.dataType === "BOOLEAN") { + value = $("#"+propertyType.code.replace('$','\\$').replace(/\./g,'\\.')+":checked").val() === "on"; + } else { + value = Util.getEmptyIfNull($("#"+propertyType.code.replace('$','\\$').replace(/\./g,'\\.')).val()); + } + + properties[propertyType.code] = value; + } + } + + var method = ""; + if(this._mode === FormMode.CREATE) { + method = "insertExperiment"; + } else if(this._mode === FormMode.EDIT) { + method = "updateExperiment"; + } + + var parameters = { + //API Method + "method" : method, + //Identification Info + "experimentSpace" : experimentSpace, + "experimentProject" : experimentProject, + "experimentCode" : experimentCode, + //Properties + "properties" : properties + }; + + var _this = this; + + if(this._mainController.profile.allDataStores.length > 0) { + this._mainController.serverFacade.createReportFromAggregationService(this._mainController.profile.allDataStores[0].code, parameters, function(response) { + Util.unblockUI(); + }); + } else { + Util.showError("No DSS available.", function() {Util.unblockUI();}); + } + } } \ No newline at end of file