Connected result object to POST request and removed .DS_Store files
This commit is contained in:
parent
86333d7188
commit
5e5bc7ce5c
7 changed files with 29 additions and 44 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,7 +1,7 @@
|
|||
__pycache__
|
||||
.ipynb_checkpoints
|
||||
*.egg-info
|
||||
|
||||
*.DS_Store
|
||||
|
||||
# Editor stuff
|
||||
*.swp
|
||||
|
|
|
|||
BIN
cara/.DS_Store
vendored
BIN
cara/.DS_Store
vendored
Binary file not shown.
BIN
cara/apps/.DS_Store
vendored
BIN
cara/apps/.DS_Store
vendored
Binary file not shown.
BIN
cara/apps/calculator/.DS_Store
vendored
BIN
cara/apps/calculator/.DS_Store
vendored
Binary file not shown.
BIN
cara/apps/calculator/static/.DS_Store
vendored
BIN
cara/apps/calculator/static/.DS_Store
vendored
Binary file not shown.
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
<h1> <p><b>CARA</b> Covid Calculator </p></h1>
|
||||
|
||||
<form name="CARAinputs" onsubmit='return on_submit(this)'>
|
||||
<form id="covid_calculator" name="covid_calculator" onsubmit='return on_submit(this)'>
|
||||
<div style="width: 33%; float:left;">
|
||||
|
||||
<!-- General Options -->
|
||||
|
|
@ -180,29 +180,27 @@
|
|||
|
||||
<script>
|
||||
|
||||
// Contents from https://stackoverflow.com/a/5004276/741316
|
||||
|
||||
/* -------Submit form------- */
|
||||
|
||||
// Variable to hold request
|
||||
var request;
|
||||
|
||||
// Bind to the submit event of our form
|
||||
$("#covid-calculator").submit(function(event){
|
||||
// Bind to the submit event of our form - from https://stackoverflow.com/a/5004276/741316
|
||||
function on_submit(form){
|
||||
|
||||
// Prevent default posting of form - put here to work in case of errors
|
||||
event.preventDefault();
|
||||
|
||||
// Abort any pending request
|
||||
if (request) {
|
||||
if (request)
|
||||
request.abort();
|
||||
}
|
||||
// setup some local variables
|
||||
var $form = $(this);
|
||||
|
||||
// Let's select and cache all the fields
|
||||
var $inputs = $form.find("input, select, button, textarea");
|
||||
var $inputs = $(form).find("input, select, button, textarea");
|
||||
|
||||
// Serialize the data in the form
|
||||
var serializedData = objectifyForm($form.serializeArray());
|
||||
var serializedData = objectifyForm($(form).serializeArray());
|
||||
|
||||
console.log(['Sending over', JSON.stringify(serializedData)])
|
||||
|
||||
|
|
@ -227,7 +225,24 @@ $("#covid-calculator").submit(function(event){
|
|||
textStatus, errorThrown
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Convert all type int in form
|
||||
function objectifyForm(formArray) {
|
||||
returnArray = {};
|
||||
for (var i = 0; i < formArray.length; i++) {
|
||||
|
||||
var value = Number(formArray[i]['value']);
|
||||
|
||||
if (formArray[i]['name'] === "simulation_name")
|
||||
returnArray[formArray[i]['name']] = formArray[i]['value'].toString();
|
||||
else if(isNaN(value) || !formArray[i]['value'].trim())
|
||||
returnArray[formArray[i]['name']] = formArray[i]['value'];
|
||||
else
|
||||
returnArray[formArray[i]['name']] = value;
|
||||
}
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
|
||||
function build_report(report_data) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
function clear_form(){
|
||||
document.CARAinputs.reset();
|
||||
document.covid_calculator.reset();
|
||||
}
|
||||
|
||||
/* -------Show/Hide DIVs------- */
|
||||
|
|
@ -139,34 +139,4 @@ function require_coffee(option) {
|
|||
/* -------UI------- */
|
||||
$(function() {
|
||||
$("#datepicker").datepicker();
|
||||
});
|
||||
|
||||
/* -------Submit form------- */
|
||||
function on_submit(form){
|
||||
|
||||
//Prevent default posting of form - put here to work in case of errors
|
||||
event.preventDefault();
|
||||
|
||||
//Serialize the data in the form
|
||||
var serializedData = objectifyForm($(form).serializeArray());
|
||||
|
||||
console.log( serializedData );
|
||||
return false; //don't submit
|
||||
}
|
||||
|
||||
//Convert all type int in form
|
||||
function objectifyForm(formArray) {
|
||||
returnArray = {};
|
||||
for (var i = 0; i < formArray.length; i++) {
|
||||
|
||||
var value = Number(formArray[i]['value']);
|
||||
|
||||
if (formArray[i]['name'] === "simulation_name")
|
||||
returnArray[formArray[i]['name']] = formArray[i]['value'].toString();
|
||||
else if(isNaN(value) || !formArray[i]['value'].trim())
|
||||
returnArray[formArray[i]['name']] = formArray[i]['value'];
|
||||
else
|
||||
returnArray[formArray[i]['name']] = value;
|
||||
}
|
||||
return returnArray;
|
||||
}
|
||||
});
|
||||
Loading…
Reference in a new issue