updated jquery methods namely on the finding mechanism
This commit is contained in:
parent
d377d6ae94
commit
f05d48221f
1 changed files with 36 additions and 34 deletions
|
|
@ -141,21 +141,20 @@ function generateJSONStructure(endpoint, jsonData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertErrorFor(referenceNode, text) {
|
function insertErrorFor(referenceNode, text) {
|
||||||
const element = $("<span></span>")
|
$(`<span class='error_text text-danger'>${text}</span>`).insertAfter(referenceNode)
|
||||||
.addClass("error_text text-danger")
|
|
||||||
.html(" " + text);
|
|
||||||
$(referenceNode).before(element);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateFormInputs(obj) {
|
function validateFormInputs(obj) {
|
||||||
$("span.error_text").remove();
|
$("#ventilation_data").find("span.error_text").remove(); // Remove all error spans
|
||||||
|
|
||||||
let submit = true;
|
let submit = true;
|
||||||
|
const $referenceNode = $("#DIVCO2_data_dialog");
|
||||||
for (let i = 0; i < CO2_data_form.length; i++) {
|
for (let i = 0; i < CO2_data_form.length; i++) {
|
||||||
const element = $(`[name=${CO2_data_form[i]}]`).first();
|
const $requiredElement = $(`[name=${CO2_data_form[i]}]`).first();
|
||||||
if (element.attr('name') !== "fitting_ventilation_states" && element.val() === "") {
|
if ($requiredElement.attr('name') !== "fitting_ventilation_states" && $requiredElement.val() === "") {
|
||||||
insertErrorFor(
|
insertErrorFor(
|
||||||
$("#DIVCO2_data_dialog"),
|
$referenceNode,
|
||||||
`'${element.attr('name')}' must be defined.<br />`
|
`'${$requiredElement.attr('name')}' must be defined.<br />`
|
||||||
);
|
);
|
||||||
submit = false;
|
submit = false;
|
||||||
}
|
}
|
||||||
|
|
@ -172,22 +171,24 @@ function validateCO2Form() {
|
||||||
let submit = true;
|
let submit = true;
|
||||||
if (validateFormInputs($("#button_fit_data"))) submit = true;
|
if (validateFormInputs($("#button_fit_data"))) submit = true;
|
||||||
|
|
||||||
|
const $fittingToSubmit = $('#DIVCO2_fitting_to_submit');
|
||||||
// Check if natural ventilation is selected
|
// Check if natural ventilation is selected
|
||||||
if (
|
if (
|
||||||
$('input[name="fitting_ventilation_type"]:checked').first().val() ==
|
$fittingToSubmit.find('input[name="fitting_ventilation_type"]:checked').val() ==
|
||||||
"fitting_natural_ventilation"
|
"fitting_natural_ventilation"
|
||||||
) {
|
) {
|
||||||
// Validate ventilation scheme
|
// Validate ventilation scheme
|
||||||
const element = $("[name=fitting_ventilation_states").first();
|
const $ventilationStates = $fittingToSubmit.find("input[name=fitting_ventilation_states]");
|
||||||
if (element.val() !== "") {
|
const $referenceNode = $("#DIVCO2_fitting_result");
|
||||||
|
if ($ventilationStates.val() !== "") {
|
||||||
// validate input format
|
// validate input format
|
||||||
try {
|
try {
|
||||||
const parsedValue = JSON.parse(element.val());
|
const parsedValue = JSON.parse($ventilationStates.val());
|
||||||
if (Array.isArray(parsedValue)) {
|
if (Array.isArray(parsedValue)) {
|
||||||
if (parsedValue.length <= 1) {
|
if (parsedValue.length <= 1) {
|
||||||
insertErrorFor(
|
insertErrorFor(
|
||||||
$("#DIVCO2_fitting_result"),
|
$referenceNode,
|
||||||
`'${element.attr('name')}' must have more than one element.<br />`
|
`'${$ventilationStates.attr('name')}' must have more than one $ventilationStates.<br />`
|
||||||
);
|
);
|
||||||
submit = false;
|
submit = false;
|
||||||
}
|
}
|
||||||
|
|
@ -206,7 +207,7 @@ function validateCO2Form() {
|
||||||
|
|
||||||
if (max_transition_time > max_presence_time) {
|
if (max_transition_time > max_presence_time) {
|
||||||
insertErrorFor(
|
insertErrorFor(
|
||||||
$("#DIVCO2_fitting_result"),
|
$referenceNode,
|
||||||
`The last transition time (${parsedValue[parsedValue.length - 1]}) should be before the last presence time (${max_presence_time / 60}).<br />`
|
`The last transition time (${parsedValue[parsedValue.length - 1]}) should be before the last presence time (${max_presence_time / 60}).<br />`
|
||||||
);
|
);
|
||||||
submit = false;
|
submit = false;
|
||||||
|
|
@ -215,22 +216,22 @@ function validateCO2Form() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
insertErrorFor(
|
insertErrorFor(
|
||||||
$("#DIVCO2_fitting_result"),
|
$referenceNode,
|
||||||
`'${element.attr('name')}' must be a list.</br>`
|
`'${$ventilationStates.attr('name')}' must be a list.</br>`
|
||||||
);
|
);
|
||||||
submit = false;
|
submit = false;
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
insertErrorFor(
|
insertErrorFor(
|
||||||
$("#DIVCO2_fitting_result"),
|
$referenceNode,
|
||||||
`'${element.attr('name')}' must be a list of numbers.</br>`
|
`'${$ventilationStates.attr('name')}' must be a list of numbers.</br>`
|
||||||
);
|
);
|
||||||
submit = false;
|
submit = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
insertErrorFor(
|
insertErrorFor(
|
||||||
$("#DIVCO2_fitting_result"),
|
$referenceNode,
|
||||||
`'${element.attr('name')}' must be defined.</br>`
|
`'${$ventilationStates.attr('name')}' must be defined.</br>`
|
||||||
);
|
);
|
||||||
submit = false;
|
submit = false;
|
||||||
}
|
}
|
||||||
|
|
@ -356,27 +357,28 @@ function submitFittingAlgorithm(url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearFittingResultComponent() {
|
function clearFittingResultComponent() {
|
||||||
|
const $referenceNode = $("#DIVCO2_data_dialog");
|
||||||
// Add the warning suggestion line
|
// Add the warning suggestion line
|
||||||
$("#suggestion_lines_txt").show();
|
$referenceNode.find("#suggestion_lines_txt").show();
|
||||||
// Remove all the previously generated fitting elements
|
// Remove all the previously generated fitting elements
|
||||||
$("#generate_fitting_data").prop("disabled", true);
|
$referenceNode.find("#generate_fitting_data").prop("disabled", true);
|
||||||
$("#CO2_fitting_result").val("");
|
$referenceNode.find("#CO2_fitting_result").val("");
|
||||||
$("#CO2_data").val("{}");
|
$referenceNode.find("#CO2_data").val("{}");
|
||||||
$("#fitting_ventilation_states").val("");
|
$referenceNode.find("#fitting_ventilation_states").val("");
|
||||||
$("span.error_text").remove();
|
$referenceNode.find("span.error_text").remove();
|
||||||
$("#DIVCO2_fitting_result, #CO2_input_data_div").hide();
|
$referenceNode.find("#DIVCO2_fitting_result, #CO2_input_data_div").hide();
|
||||||
$("#DIVCO2_fitting_to_submit").hide();
|
$referenceNode.find("#DIVCO2_fitting_to_submit").hide();
|
||||||
$("#CO2_data_plot").attr("src", "");
|
$referenceNode.find("#CO2_data_plot").attr("src", "");
|
||||||
|
|
||||||
// Update the ventilation scheme components
|
// Update the ventilation scheme components
|
||||||
$("#fitting_ventilation_states, [name=fitting_ventilation_type]").prop(
|
$referenceNode.find("#fitting_ventilation_states, [name=fitting_ventilation_type]").prop(
|
||||||
"disabled",
|
"disabled",
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update the bottom right buttons
|
// Update the bottom right buttons
|
||||||
$("#generate_fitting_data").show();
|
$referenceNode.find("#generate_fitting_data").show();
|
||||||
$("#save_and_dismiss_dialog").hide();
|
$referenceNode.find("#save_and_dismiss_dialog").hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
function disableFittingAlgorithm() {
|
function disableFittingAlgorithm() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue