Skip to content
Snippets Groups Projects
Commit 6e740515 authored by juanf's avatar juanf
Browse files

SSDM-504: Experiment Form Edit Mode, client side.

SVN: 31750
parent f8153b1e
No related branches found
No related tags found
No related merge requests found
...@@ -193,7 +193,15 @@ function MainController(profile) { ...@@ -193,7 +193,15 @@ function MainController(profile) {
var _this = this; var _this = this;
this.serverFacade.listExperimentsForIdentifiers([arg], function(data) { this.serverFacade.listExperimentsForIdentifiers([arg], function(data) {
document.title = "Experiment " + arg; 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); window.scrollTo(0,0);
}); });
break; break;
...@@ -357,9 +365,9 @@ function MainController(profile) { ...@@ -357,9 +365,9 @@ function MainController(profile) {
this.currentView = projectForm; this.currentView = projectForm;
} }
this._showExperimentPage = function(experiment) { this._showExperimentPage = function(experiment, mode) {
//Show Form //Show Form
var experimentForm = new ExperimentForm("mainContainer", this, experiment, FormMode.VIEW); var experimentForm = new ExperimentForm("mainContainer", this, experiment, mode);
experimentForm.init(); experimentForm.init();
this.currentView = experimentForm; this.currentView = experimentForm;
} }
......
...@@ -101,23 +101,24 @@ var FormUtil = new function() { ...@@ -101,23 +101,24 @@ var FormUtil = new function() {
} else { } else {
vocabulary = this.profile.getVocabularyById(propertyType.vocabulary); 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") { } 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") { } 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") { } 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") { } 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") { } 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") { } 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") { } 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") { } else if (propertyType.dataType === "XML") {
$component = this._getTextBox(propertyType.code, propertyType.description, propertyType.mandatory); $component = this._getTextBox(codeWithoutSimbols, propertyType.description, propertyType.mandatory);
} }
return $component; return $component;
......
...@@ -18,7 +18,11 @@ function ExperimentForm(containerId, mainController, experiment, mode) { ...@@ -18,7 +18,11 @@ function ExperimentForm(containerId, mainController, experiment, mode) {
this._mainController = mainController; this._mainController = mainController;
this._experiment = experiment; this._experiment = experiment;
this._mode = mode; this._mode = mode;
this.isFormDirty = false; this._isFormDirty = false;
this.isDirty = function() {
return this._isFormDirty;
}
this.init = function() { this.init = function() {
this.repaint(); this.repaint();
...@@ -70,6 +74,13 @@ function ExperimentForm(containerId, mainController, experiment, mode) { ...@@ -70,6 +74,13 @@ function ExperimentForm(containerId, mainController, experiment, mode) {
}); });
$formTitle.append(" "); $formTitle.append(" ");
$formTitle.append($createSubExpBtn); $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) { ...@@ -81,14 +92,24 @@ function ExperimentForm(containerId, mainController, experiment, mode) {
var identifierParts = this._experiment.identifier.split("/"); var identifierParts = this._experiment.identifier.split("/");
$formColumn.append(FormUtil.getFieldForLabelWithText("Type", this._experiment.experimentTypeCode)); $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) { if(this._mode === FormMode.VIEW || this._mode === FormMode.EDIT) {
$formColumn.append(FormUtil.getFieldForLabelWithText("Code", identifierParts[3])); $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("Registrator", this._experiment.registrationDetails.userId));
$formColumn.append(FormUtil.getFieldForLabelWithText("Registration Date", (new Date(this._experiment.registrationDetails.registrationDate)).toLocaleString())); $formColumn.append(FormUtil.getFieldForLabelWithText("Registration Date", (new Date(this._experiment.registrationDetails.registrationDate)).toLocaleString()));
} else if(this._mode === FormMode.CREATE){ } 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")); $formColumn.append(FormUtil.getFieldForComponentWithLabel($codeField, "Code"));
} }
...@@ -117,12 +138,26 @@ function ExperimentForm(containerId, mainController, experiment, mode) { ...@@ -117,12 +138,26 @@ function ExperimentForm(containerId, mainController, experiment, mode) {
var $controlGroup = null; 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]); $controlGroup = FormUtil.getFieldForLabelWithText(propertyType.label, this._experiment.properties[propertyType.code]);
} else { } else {
var $component = FormUtil.getFieldForPropertyType(propertyType); 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) { $component.change(function(event) {
localInstance.isFormDirty = true; _this._isFormDirty = true;
}); });
$controlGroup = FormUtil.getFieldForComponentWithLabel($component, propertyType.label); $controlGroup = FormUtil.getFieldForComponentWithLabel($component, propertyType.label);
} }
...@@ -133,6 +168,85 @@ function ExperimentForm(containerId, mainController, experiment, mode) { ...@@ -133,6 +168,85 @@ function ExperimentForm(containerId, mainController, experiment, mode) {
$formColumn.append($fieldset); $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._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
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