//Finally saves the selection in the correct order of the part ids and sets input HTML Tags accordingly function saveSelection(){ var table = document.getElementById("decision_table"); var rows = table.rows; var sorted_selection =[]; var sorted_weights = []; var sorted_value = []; var total_weight = 0; var total_value = 0; for(var i = 2; i < (rows.length - 3); i++){ var part_id = parseInt(rows[i].getElementsByTagName("TD")[5].innerHTML); //We get the real part id from a hidden column at the end of the table var weight = parseFloat(rows[i].getElementsByTagName("TD")[1].innerHTML); var value = parseFloat(rows[i].getElementsByTagName("TD")[2].innerHTML); var selected = document.getElementById('part_' + (part_id)).checked; total_weight += (weight*selected); total_value += (value*selected); sorted_weights[part_id-1] = weight; sorted_value[part_id-1] = value; sorted_selection[part_id-1] = selected; } console.log(sorted_weights); console.log(sorted_value); console.log(sorted_selection); console.log('Total Weight: ' + total_weight); console.log('Total Value: ' + total_value); document.getElementById("id_r_weight").value = sorted_weights; document.getElementById("id_r_value").value = sorted_value; document.getElementById("id_sel").value = sorted_selection; document.getElementById("id_total_weight").value = total_weight; document.getElementById("id_total_value").value = total_value; //Ensure that all click_hsitory fields are filled so that no error is shown if(document.getElementById("id_click_history").value == ''){ document.getElementById("id_click_history").value = 'neither selected nor sorted'; } } function fixButtons(key, recommendation_decision){ console.log("Fix buttons, selected: " + recommendation_decision) var color_deactivated; var treatment = document.getElementById("id_treatment").name; if (key == 'disabled'){ // 2 buttons disablen document.getElementById("decision_heur").disabled = true; document.getElementById("decision_opt").disabled = true; // colour von einem Button auf grau setzen } color_deactivated = 'grey'; color_activated = '#007BFF'; if (recommendation_decision == 'opt_sol'){ document.getElementById("id_click_history").value += "opt_"; changeButtons("decision_opt", color_activated); if (treatment == 'opt_heur_dec_c' || treatment == 'opt_heur_dec' && document.title == 'Task Description'){ changeButtons("decision_heur", color_deactivated); } else if (treatment == 'decide_three_sol_c'){ changeButtons("decision_second", color_deactivated); changeButtons("decision_third", color_deactivated); } } else if (recommendation_decision == 'second_sol'){ document.getElementById("id_click_history").value += "second_"; changeButtons("decision_opt", color_deactivated); changeButtons("decision_second", color_activated); changeButtons("decision_third", color_deactivated); } else if (recommendation_decision == 'third_sol'){ document.getElementById("id_click_history").value += "third_"; changeButtons("decision_opt", color_deactivated); changeButtons("decision_second", color_deactivated); changeButtons("decision_third", color_activated); } else if (recommendation_decision == 'heur_sol'){ document.getElementById("id_click_history").value += "heur_"; changeButtons("decision_opt", color_deactivated); changeButtons("decision_heur", color_activated); } //if next_button == False: btn_class = 'type="button" name="offer_accepted" value="False" class="btn btn-primary btn-large"' } function changeButtons(name, color){ console.log(name) document.getElementById(name).style.backgroundColor = color; document.getElementById(name).style.borderColor = color; } function setRecommendationRequest(recommendation_requested){ if (document.title != 'Task Description'){ document.getElementById("reco_decision_yes_id").disabled = true; document.getElementById("reco_decision_no_id").disabled = true; } color_deactivated = 'grey'; color_activated = '#007BFF'; if (recommendation_requested){ document.getElementById("id_first_sel").value = 'optimal_solution_requested'; document.getElementById("reco_decision_yes_id").style.backgroundColor = color_activated; document.getElementById("reco_decision_yes_id").style.borderColor = color_activated; document.getElementById("reco_decision_no_id").style.backgroundColor = color_deactivated; document.getElementById("reco_decision_no_id").style.borderColor = color_deactivated; } else { document.getElementById("id_first_sel").value = 'optimal_solution_rejected'; document.getElementById("reco_decision_yes_id").style.backgroundColor = color_deactivated; document.getElementById("reco_decision_yes_id").style.borderColor = color_deactivated; document.getElementById("reco_decision_no_id").style.backgroundColor = color_activated; document.getElementById("reco_decision_no_id").style.borderColor = color_activated; } createDecisionTable(); $(".gurke").click(function(){ save_selection_clicks(current_selection); computeWeight(); }) computeWeight(); }