2020-11-17 21:40:49 +00:00
/* -------HTML structure------- */
2020-11-06 19:41:12 +00:00
function getChildElement ( elem ) {
// Get the element named in the given element's data-enables attribute.
2020-12-09 17:32:53 +00:00
return $ ( elem . data ( "enables" ) ) ;
2020-11-06 19:41:12 +00:00
}
2020-11-04 08:39:53 +00:00
2020-12-03 08:38:21 +00:00
function insertErrorFor ( referenceNode , text ) {
2020-11-17 17:50:16 +00:00
var element = document . createElement ( "span" ) ;
2020-12-03 08:38:21 +00:00
element . setAttribute ( "class" , "error_text" ) ;
2020-11-17 17:50:16 +00:00
element . classList . add ( "red_text" ) ;
2021-01-27 17:02:31 +00:00
element . innerHTML = " " + text ;
2020-11-17 17:50:16 +00:00
referenceNode . parentNode . insertBefore ( element , referenceNode . nextSibling ) ;
}
2020-12-03 08:38:21 +00:00
function removeErrorFor ( referenceNode ) {
$ ( referenceNode ) . next ( 'span.error_text' ) . remove ( ) ;
2020-12-02 20:18:03 +00:00
}
2020-11-04 08:39:53 +00:00
/* -------Required fields------- */
2020-11-07 10:31:40 +00:00
function require _fields ( obj ) {
2020-11-16 21:09:54 +00:00
switch ( $ ( obj ) . attr ( 'id' ) ) {
2021-02-18 10:33:37 +00:00
case "room_data_volume" :
2020-11-04 08:39:53 +00:00
require _room _volume ( true ) ;
require _room _dimensions ( false ) ;
break ;
2021-02-18 10:33:37 +00:00
case "room_data_dimensions" :
2020-11-04 08:39:53 +00:00
require _room _volume ( false ) ;
require _room _dimensions ( true ) ;
break ;
2021-02-18 10:33:37 +00:00
case "mechanical_ventilation" :
2020-11-04 08:39:53 +00:00
require _mechanical _ventilation ( true ) ;
require _natural _ventilation ( false ) ;
break ;
2021-02-18 10:33:37 +00:00
case "natural_ventilation" :
2020-11-04 08:39:53 +00:00
require _mechanical _ventilation ( false ) ;
require _natural _ventilation ( true ) ;
break ;
2020-11-25 18:51:32 +00:00
case "window_sliding" :
require _window _width ( false ) ;
break ;
case "window_hinged" :
require _window _width ( true ) ;
break ;
2021-02-18 10:33:37 +00:00
case "mech_type_air_changes" :
2020-11-04 08:39:53 +00:00
require _air _changes ( true ) ;
require _air _supply ( false ) ;
break ;
2021-02-18 10:33:37 +00:00
case "mech_type_air_supply" :
2020-11-04 08:39:53 +00:00
require _air _changes ( false ) ;
require _air _supply ( true ) ;
break ;
2021-02-18 10:33:37 +00:00
case "windows_open_periodically" :
2020-12-07 20:36:53 +00:00
require _venting ( true ) ;
break ;
2021-02-18 10:33:37 +00:00
case "windows_open_permanently" :
2020-12-07 20:36:53 +00:00
require _venting ( false ) ;
break ;
2020-11-18 19:53:27 +00:00
case "hepa_yes" :
require _hepa ( true ) ;
break ;
case "hepa_no" :
require _hepa ( false ) ;
break ;
2022-10-03 13:42:37 +00:00
case "p_probabilistic_exposure" :
2022-09-21 07:14:33 +00:00
require _population ( true ) ;
2022-10-03 15:49:54 +00:00
require _infected ( false ) ;
2022-09-21 07:14:33 +00:00
break ;
2022-10-03 13:42:37 +00:00
case "p_deterministic_exposure" :
2022-09-21 07:14:33 +00:00
require _population ( false ) ;
2022-10-03 15:49:54 +00:00
require _infected ( true ) ;
2022-09-21 07:14:33 +00:00
break ;
2020-11-18 19:53:27 +00:00
case "mask_on" :
require _mask ( true ) ;
break ;
case "mask_off" :
require _mask ( false ) ;
break ;
2021-02-10 10:17:48 +00:00
case "exposed_lunch_option_no" :
case "infected_lunch_option_no" :
require _lunch ( $ ( obj ) . attr ( 'id' ) , false ) ;
2020-11-05 10:36:36 +00:00
break ;
2021-02-10 10:17:48 +00:00
case "exposed_lunch_option_yes" :
case "infected_lunch_option_yes" :
require _lunch ( $ ( obj ) . attr ( 'id' ) , true ) ;
2020-11-04 08:39:53 +00:00
break ;
2020-11-05 10:36:36 +00:00
default :
break ;
2020-11-07 10:31:40 +00:00
}
}
2020-11-05 10:36:36 +00:00
2020-11-07 10:31:40 +00:00
function unrequire _fields ( obj ) {
switch ( obj . id ) {
2021-02-18 10:33:37 +00:00
case "mechanical_ventilation" :
2020-11-06 17:38:55 +00:00
require _mechanical _ventilation ( false ) ;
break ;
2021-02-18 10:33:37 +00:00
case "natural_ventilation" :
2020-11-06 17:38:55 +00:00
require _natural _ventilation ( false ) ;
break ;
default :
break ;
2020-11-07 10:31:40 +00:00
}
}
2020-11-06 17:38:55 +00:00
2020-11-04 08:39:53 +00:00
function require _room _volume ( option ) {
2020-11-17 21:51:31 +00:00
require _input _field ( "#room_volume" , option ) ;
2020-12-09 17:46:07 +00:00
set _disabled _status ( "#room_volume" , ! option ) ;
2020-11-04 08:39:53 +00:00
}
function require _room _dimensions ( option ) {
2020-11-17 21:51:31 +00:00
require _input _field ( "#floor_area" , option ) ;
require _input _field ( "#ceiling_height" , option ) ;
2020-12-09 17:46:07 +00:00
set _disabled _status ( "#floor_area" , ! option ) ;
set _disabled _status ( "#ceiling_height" , ! option ) ;
2020-11-04 08:39:53 +00:00
}
function require _mechanical _ventilation ( option ) {
2021-02-18 10:33:37 +00:00
$ ( "#mech_type_air_changes" ) . prop ( 'required' , option ) ;
$ ( "#mech_type_air_supply" ) . prop ( 'required' , option ) ;
2020-11-17 20:58:03 +00:00
if ( ! option ) {
2021-02-18 10:33:37 +00:00
require _input _field ( "#air_changes" , option ) ;
require _input _field ( "#air_supply" , option ) ;
2020-11-17 20:44:43 +00:00
}
2020-11-07 10:31:40 +00:00
}
2020-11-04 08:39:53 +00:00
function require _natural _ventilation ( option ) {
2020-11-17 21:51:31 +00:00
require _input _field ( "#windows_number" , option ) ;
require _input _field ( "#window_height" , option ) ;
require _input _field ( "#opening_distance" , option ) ;
2020-11-25 18:51:32 +00:00
$ ( "#window_sliding" ) . prop ( 'required' , option ) ;
$ ( "#window_hinged" ) . prop ( 'required' , option ) ;
2021-02-18 10:33:37 +00:00
$ ( "#windows_open_permanently" ) . prop ( 'required' , option ) ;
$ ( "#windows_open_periodically" ) . prop ( 'required' , option ) ;
if ( ! option ) {
require _input _field ( "#window_width" , option ) ;
require _input _field ( "#windows_duration" , option ) ;
2022-06-16 13:07:56 +00:00
require _input _field ( "#windows_frequency" , option ) ;
2021-02-18 10:33:37 +00:00
}
2020-11-06 08:32:52 +00:00
}
2020-11-04 08:39:53 +00:00
2020-11-25 18:51:32 +00:00
function require _window _width ( option ) {
require _input _field ( "#window_width" , option ) ;
2020-12-09 17:46:07 +00:00
set _disabled _status ( "#window_width" , ! option ) ;
2020-11-06 08:32:52 +00:00
}
2020-11-04 08:39:53 +00:00
function require _air _changes ( option ) {
2020-11-17 21:51:31 +00:00
require _input _field ( "#air_changes" , option ) ;
2020-12-09 17:46:07 +00:00
set _disabled _status ( "#air_changes" , ! option ) ;
2020-11-06 21:26:32 +00:00
}
2020-11-04 08:39:53 +00:00
function require _air _supply ( option ) {
2020-11-17 21:51:31 +00:00
require _input _field ( "#air_supply" , option ) ;
2020-12-09 17:46:07 +00:00
set _disabled _status ( "#air_supply" , ! option ) ;
2020-11-06 21:26:32 +00:00
}
2020-11-04 08:39:53 +00:00
2020-12-07 20:36:53 +00:00
function require _venting ( option ) {
require _input _field ( "#windows_duration" , option ) ;
2022-06-16 13:07:56 +00:00
require _input _field ( "#windows_frequency" , option ) ;
2020-12-07 20:36:53 +00:00
}
2021-02-10 10:17:48 +00:00
function require _lunch ( id , option ) {
var activity = $ ( document . getElementById ( id ) ) . data ( 'lunch-select' ) ;
var startObj = $ ( ".start_time[data-lunch-for='" + activity + "']" ) [ 0 ] ;
var startID = '#' + $ ( startObj ) . attr ( 'id' ) ;
var finishObj = $ ( ".finish_time[data-lunch-for='" + activity + "']" ) [ 0 ] ;
var finishID = '#' + $ ( finishObj ) . attr ( 'id' ) ;
2020-12-02 20:55:21 +00:00
2021-02-10 10:17:48 +00:00
require _input _field ( startID , option ) ;
require _input _field ( finishID , option ) ;
if ( ! option ) {
$ ( finishID ) . removeClass ( "red_border finish_time_error lunch_break_error" ) ;
removeErrorFor ( finishObj ) ;
2021-01-27 17:02:31 +00:00
}
2020-11-11 19:11:12 +00:00
else {
2021-02-10 10:17:48 +00:00
if ( startObj . value === "" && finishObj . value === "" ) {
startObj . value = "12:30" ;
finishObj . value = "13:30" ;
}
validateLunchBreak ( $ ( startObj ) . data ( 'time-group' ) ) ;
2020-11-11 19:11:12 +00:00
}
2020-11-04 08:39:53 +00:00
}
2022-09-21 07:14:33 +00:00
function require _population ( option ) {
require _input _field ( "#geographic_population" , option ) ;
require _input _field ( "#geographic_cases" , option ) ;
require _input _field ( "#ascertainment_bias" , option ) ;
}
2022-10-03 15:49:54 +00:00
function require _infected ( option ) {
require _input _field ( "#infected_people" , option ) ;
}
2020-11-11 19:02:30 +00:00
function require _mask ( option ) {
2021-02-18 10:33:37 +00:00
$ ( "#mask_type_1" ) . prop ( 'required' , option ) ;
$ ( "#mask_type_ffp2" ) . prop ( 'required' , option ) ;
2020-11-11 19:02:30 +00:00
}
2020-11-10 15:59:05 +00:00
function require _hepa ( option ) {
2020-11-17 21:51:31 +00:00
require _input _field ( "#hepa_amount" , option ) ;
2020-11-19 21:53:32 +00:00
}
function require _input _field ( id , option ) {
$ ( id ) . prop ( 'required' , option ) ;
2020-11-20 10:05:04 +00:00
if ( ! option ) {
2020-11-19 21:53:32 +00:00
removeInvalid ( id ) ;
2020-11-20 10:05:04 +00:00
}
2020-11-19 21:53:32 +00:00
}
2020-12-09 17:46:07 +00:00
function set _disabled _status ( id , option ) {
2020-11-19 21:53:32 +00:00
if ( option )
$ ( id ) . addClass ( "disabled" ) ;
2020-12-02 18:12:47 +00:00
else
$ ( id ) . removeClass ( "disabled" ) ;
2020-11-10 15:59:05 +00:00
}
2022-09-20 12:48:46 +00:00
function validateMaxInfectedPeople ( ) {
let infected _people = document . getElementById ( "infected_people" ) ;
removeErrorFor ( infected _people ) ;
$ ( infected _people ) . removeClass ( "red_border" ) ;
let infected = infected _people . valueAsNumber ;
let max = document . getElementById ( "total_people" ) . valueAsNumber ;
2020-11-13 15:30:35 +00:00
2022-09-20 12:48:46 +00:00
if ( $ ( "#activity_type" ) . val ( ) === "training" && infected > 1 ) {
insertErrorFor ( infected _people , "Conference/Training activities limited to 1 infected person." ) ;
$ ( infected _people ) . addClass ( "red_border" ) ;
return false ;
}
else if ( infected >= max ) {
insertErrorFor ( infected _people , "Value is equal or higher than the total number of occupants." ) ;
$ ( infected _people ) . addClass ( "red_border" ) ;
return false ;
2020-11-13 15:30:35 +00:00
}
2022-09-20 12:48:46 +00:00
return true ;
2020-11-06 20:48:09 +00:00
}
2020-11-17 20:12:01 +00:00
function removeInvalid ( id ) {
2020-11-17 21:51:31 +00:00
if ( $ ( id ) . hasClass ( "red_border" ) ) {
$ ( id ) . val ( "" ) ;
$ ( id ) . removeClass ( "red_border" ) ;
2020-12-03 08:38:21 +00:00
removeErrorFor ( id ) ;
2020-11-17 17:50:16 +00:00
}
}
2020-11-17 20:12:01 +00:00
function on _ventilation _type _change ( ) {
ventilation _types = $ ( 'input[type=radio][name=ventilation_type]' ) ;
ventilation _types . each ( function ( index ) {
if ( this . checked ) {
getChildElement ( $ ( this ) ) . show ( ) ;
require _fields ( this ) ;
} else {
getChildElement ( $ ( this ) ) . hide ( ) ;
unrequire _fields ( this ) ;
2020-12-08 09:32:39 +00:00
2021-02-18 10:33:37 +00:00
//Clear invalid inputs for this newly hidden child element
2021-03-01 15:19:15 +00:00
removeInvalid ( "#" + getChildElement ( $ ( this ) ) . find ( 'input' ) . not ( 'input[type=radio]' ) . attr ( 'id' ) ) ;
2020-11-17 20:12:01 +00:00
}
} ) ;
}
2022-08-24 10:33:02 +00:00
function on _window _opening _change ( ) {
opening _regime = $ ( 'input[type=radio][name=window_opening_regime]' )
opening _regime . each ( function ( index ) {
if ( this . checked ) {
getChildElement ( $ ( this ) ) . show ( ) ;
require _fields ( this ) ;
}
else {
getChildElement ( $ ( this ) ) . hide ( ) ;
require _fields ( this ) ;
}
} )
}
2022-06-10 14:08:07 +00:00
function on _hepa _option _change ( ) {
hepa _option = $ ( 'input[type=radio][name=hepa_option]' )
hepa _option . each ( function ( index ) {
if ( this . checked ) {
getChildElement ( $ ( this ) ) . show ( ) ;
require _fields ( this ) ;
}
else {
getChildElement ( $ ( this ) ) . hide ( ) ;
require _fields ( this ) ;
}
} )
}
2022-10-03 15:49:54 +00:00
function on _exposure _change ( ) {
2022-10-03 13:42:37 +00:00
p _recurrent = $ ( 'input[type=radio][name=exposure_option]' )
2022-09-21 07:14:33 +00:00
p _recurrent . each ( function ( index ) {
if ( this . checked ) {
getChildElement ( $ ( this ) ) . show ( ) ;
require _fields ( this ) ;
}
else {
getChildElement ( $ ( this ) ) . hide ( ) ;
unrequire _fields ( this ) ;
//Clear invalid inputs for this newly hidden child element
removeInvalid ( "#" + getChildElement ( $ ( this ) ) . find ( 'input' ) . not ( 'input[type=radio]' ) . attr ( 'id' ) ) ;
}
} )
}
2021-12-15 14:33:57 +00:00
function on _wearing _mask _change ( ) {
wearing _mask = $ ( 'input[type=radio][name=mask_wearing_option]' )
wearing _mask . each ( function ( index ) {
if ( this . checked ) {
getChildElement ( $ ( this ) ) . show ( ) ;
require _fields ( this ) ;
2022-03-23 12:44:55 +00:00
if ( this . id == "mask_on" ) {
$ ( '#short_range_no' ) . click ( ) ;
$ ( 'input[name="short_range_option"]' ) . attr ( 'disabled' , true ) ;
$ ( "#short_range_warning" ) . show ( ) ;
}
else {
$ ( 'input[name="short_range_option"]' ) . attr ( 'disabled' , false ) ;
$ ( "#short_range_warning" ) . hide ( ) ;
}
2021-12-15 14:33:57 +00:00
}
else {
getChildElement ( $ ( this ) ) . hide ( ) ;
require _fields ( this ) ;
}
} )
}
2022-09-22 09:37:31 +00:00
function update _booster _warning ( ) {
// Check if "Other" is selected
$ ( "#vaccine_booster_type" ) . find ( ":selected" ) . val ( ) == "Other" ? $ ( "#booster_warning" ) . show ( ) : $ ( "#booster_warning" ) . hide ( ) ;
}
function update _booster _dropdown ( url ) {
let primary _vaccine _option = $ ( "#vaccine_type" ) . find ( ":selected" ) . val ( ) ;
2022-10-07 08:51:05 +00:00
$ ( "#vaccine_booster_type option" ) . remove ( ) ;
vaccine _booster _host _immunity . forEach ( booster => {
if ( booster [ 'primary series vaccine' ] == primary _vaccine _option )
$ ( "#vaccine_booster_type" ) . append ( ` <option data-primary-vaccine= ${ primary _vaccine _option } value= ${ booster [ 'booster vaccine' ] } > ${ booster [ 'booster vaccine' ] . replaceAll ( '_' , ' ' ) } </option> ` ) ;
2022-09-22 09:37:31 +00:00
} ) ;
2022-10-07 08:51:05 +00:00
$ ( "#vaccine_booster_type" ) . append ( ` <option value='Other'>Other</option> ` ) ;
let booster _vaccine = url . searchParams . has ( 'vaccine_booster_type' ) ? url . searchParams . get ( 'vaccine_booster_type' ) : null ;
$ ( ` #vaccine_booster_type > option[value=" ${ booster _vaccine } " ` ) . attr ( 'selected' , true ) ;
2022-09-22 09:37:31 +00:00
update _booster _warning ( ) ;
}
function on _vaccination _change ( url ) {
2022-09-22 09:25:06 +00:00
vaccination _option = $ ( 'input[type=radio][name=vaccine_option]' ) ;
vaccination _option . each ( function ( index ) {
if ( this . checked ) {
getChildElement ( $ ( this ) ) . show ( ) ;
require _fields ( this ) ;
}
else {
getChildElement ( $ ( this ) ) . hide ( ) ;
require _fields ( this ) ;
}
2022-09-22 09:37:31 +00:00
} ) ;
update _booster _dropdown ( url ) ;
2022-09-22 09:25:06 +00:00
}
function on _vaccination _booster _change ( ) {
vaccination _booster _option = $ ( 'input[type=radio][name=vaccine_booster_option]' ) ;
vaccination _booster _option . each ( function ( index ) {
if ( this . checked ) getChildElement ( $ ( this ) ) . show ( ) ;
else getChildElement ( $ ( this ) ) . hide ( ) ;
2022-09-22 09:37:31 +00:00
} ) ;
2022-09-22 09:25:06 +00:00
}
2022-06-22 12:59:49 +00:00
function populate _temp _hum _values ( data , index ) {
2022-06-27 15:13:08 +00:00
$ ( "#sensor_temperature" ) . text ( Math . round ( data [ index ] . Details . T ) + '°C' ) ;
$ ( "#sensor_humidity" ) . text ( Math . round ( data [ index ] . Details . RH ) + '%' ) ;
2022-06-22 12:59:49 +00:00
$ ( "[name='inside_temp']" ) . val ( data [ index ] . Details . T + 273.15 ) ;
$ ( "[name='humidity']" ) . val ( data [ index ] . Details . RH / 100 ) ;
} ;
//Data from ARVE sensors
var DATA _FROM _SENSORS ;
function show _sensors _data ( url ) {
const HOTEL _ID = "CERN"
const FLOOR _ID = "1"
if ( $ ( '#sensors > option' ) . length == 0 ) {
$ . ajax ( {
url : ` ${ $ ( '#url_prefix' ) . data ( ) . calculator _prefix } /api/arve/v1/ ${ HOTEL _ID } / ${ FLOOR _ID } ` ,
type : 'GET' ,
success : function ( result ) {
DATA _FROM _SENSORS = result ;
result . map ( room => {
2022-09-22 08:39:30 +00:00
if ( room [ 'Details' ] [ 'Online' ] == false ) return ; // If the sensor is offline, it should not be added to the list.
2022-06-22 12:59:49 +00:00
$ ( "#sensors" ) . append ( ` <option id= ${ room . RoomId } value= ${ room . RoomId } >Sensor ${ room . RoomId } </option> ` ) ;
} ) ;
2022-09-22 08:39:30 +00:00
if ( $ ( '#sensors > option' ) . length == 0 ) {
$ ( '#offline_sensors' ) . show ( ) ;
$ ( '#DIVsensors_data' ) . hide ( ) ;
$ ( '#arve_sensor_yes' ) . prop ( 'disabled' , true )
return ; // All sensors are offline
}
2022-06-22 12:59:49 +00:00
populate _temp _hum _values ( result , 0 ) ;
if ( url . searchParams . has ( 'sensor_in_use' ) ) {
$ ( "#sensors" ) . val ( url . searchParams . get ( 'sensor_in_use' ) ) ;
populate _temp _hum _values ( result , result . findIndex ( function ( sensor ) {
return sensor . RoomId == url . searchParams . get ( 'sensor_in_use' ) ;
} ) ) ;
}
} ,
2022-09-22 13:40:05 +00:00
error : function ( _ , _ , errorThrown ) {
2022-09-28 09:18:34 +00:00
$ ( "#arve_api_error_message" ) . val ( errorThrown ) . show ( ) ;
$ ( '#DIVsensors_data' ) . hide ( ) ;
$ ( '#arve_sensor_yes' ) . prop ( 'disabled' , true )
2022-09-22 13:40:05 +00:00
}
2022-06-22 12:59:49 +00:00
} ) ;
}
} ;
2022-10-12 14:49:42 +00:00
function geographic _cases ( location _country _name ) {
$ . ajax ( {
url : ` ${ $ ( '#url_prefix' ) . data ( ) . calculator _prefix } /cases/ ${ location _country _name } ` ,
type : 'GET' ,
success : function ( result ) {
$ ( '#geographic_cases' ) . val ( result ) ;
2022-11-18 10:39:20 +00:00
result != '' ? $ ( '#source_geographic_cases' ) . show ( ) : $ ( '#source_geographic_cases' ) . hide ( ) ;
2022-10-12 14:49:42 +00:00
} ,
error : function ( _ , _ , errorThrown ) {
console . log ( errorThrown ) ;
}
} ) ;
}
2022-06-22 12:59:49 +00:00
$ ( "#sensors" ) . change ( function ( el ) {
sensor _id = DATA _FROM _SENSORS . findIndex ( function ( sensor ) {
return sensor . RoomId == el . target . value
} ) ;
populate _temp _hum _values ( DATA _FROM _SENSORS , sensor _id ) ;
} ) ;
function on _use _sensors _data _change ( url ) {
sensor _data = $ ( 'input[type=radio][name=arve_sensors_option]' )
sensor _data . each ( function ( index ) {
if ( this . checked ) {
getChildElement ( $ ( this ) ) . show ( ) ;
show _sensors _data ( url ) ;
}
else {
getChildElement ( $ ( this ) ) . hide ( ) ;
}
} )
}
2022-01-21 16:32:17 +00:00
function on _short _range _option _change ( ) {
short _range = $ ( 'input[type=radio][name=short_range_option]' )
short _range . each ( function ( index ) {
if ( this . checked ) {
getChildElement ( $ ( this ) ) . show ( ) ;
require _fields ( this ) ;
}
else {
getChildElement ( $ ( this ) ) . hide ( ) ;
require _fields ( this ) ;
}
} )
}
2022-07-29 09:49:06 +00:00
function on _lunch _break _option _change ( ) {
all _lunch _breaks = [ $ ( 'input[type=radio][name=exposed_lunch_option]' ) , $ ( 'input[type=radio][name=infected_lunch_option]' ) ] ;
for ( lunch _break of all _lunch _breaks ) {
lunch _break . each ( function ( ) {
children = getChildElement ( $ ( this ) ) ;
this . checked ? children . show ( ) : children . hide ( ) ;
require _fields ( this ) ;
} )
}
}
2022-07-28 09:41:18 +00:00
function on _coffee _break _option _change ( ) {
all _coffee _breaks = [ $ ( 'input[type=radio][name=exposed_coffee_break_option]' ) , $ ( 'input[type=radio][name=infected_coffee_break_option]' ) ] ;
for ( coffee _breaks of all _coffee _breaks ) {
coffee _breaks . each ( function ( ) {
children = getChildElement ( $ ( this ) ) ;
if ( this . checked && children . length ) {
children . show ( ) ;
return false ;
}
else {
children . hide ( ) ;
}
} )
}
}
2020-11-04 08:39:53 +00:00
/* -------UI------- */
2020-11-05 13:03:15 +00:00
function show _disclaimer ( ) {
var dots = document . getElementById ( "dots" ) ;
var moreText = document . getElementById ( "more" ) ;
var btnText = document . getElementById ( "myBtn" ) ;
if ( dots . style . display === "none" ) {
dots . style . display = "inline" ;
btnText . innerHTML = "Read more" ;
moreText . style . display = "none" ;
} else {
dots . style . display = "none" ;
btnText . innerHTML = "Read less" ;
moreText . style . display = "inline" ;
2020-11-07 10:31:40 +00:00
}
}
2020-11-06 14:53:42 +00:00
2020-12-09 17:32:53 +00:00
$ ( "[data-has-radio]" ) . on ( 'click' , function ( event ) {
$ ( $ ( this ) . data ( "has-radio" ) ) . click ( ) ;
2020-11-18 19:53:27 +00:00
} ) ;
2020-12-09 17:32:53 +00:00
$ ( "[data-has-radio]" ) . on ( 'change' , function ( event ) {
$ ( $ ( this ) . data ( "has-radio" ) ) . click ( ) ;
2020-11-18 19:53:27 +00:00
} ) ;
2021-02-10 10:17:48 +00:00
function toggle _split _breaks ( ) {
$ ( "#DIVinfected_breaks" ) . toggle ( this . checked ) ;
$ ( "#exposed_break_title" ) . toggle ( this . checked ) ;
require _lunch ( "infected_lunch_option_yes" , document . getElementById ( "infected_dont_have_breaks_with_exposed" ) . checked ) ;
}
2020-11-06 19:06:29 +00:00
/* -------Form validation------- */
function validate _form ( form ) {
var submit = true ;
2020-12-07 21:59:30 +00:00
// Activity times and lunch break times are co-dependent
// -> So if 1 fails it doesn't make sense to check the rest
//Validate all finish times
$ ( "input[required].finish_time" ) . each ( function ( ) {
2021-03-19 15:38:27 +00:00
var activity = $ ( this ) . data ( 'lunch-for' ) ;
if ( document . getElementById ( "infected_dont_have_breaks_with_exposed" ) . checked || activity != "infected" ) {
if ( ! validateFinishTime ( this ) ) {
submit = false ;
}
2020-11-27 12:12:55 +00:00
}
2020-11-17 20:58:03 +00:00
} ) ;
2020-11-26 14:52:11 +00:00
//Validate all lunch breaks
if ( submit ) {
2020-12-14 14:10:13 +00:00
$ ( "input[required].start_time[data-lunch-for]" ) . each ( function ( ) {
2021-03-19 15:38:27 +00:00
var activity = $ ( this ) . data ( 'lunch-for' ) ;
if ( document . getElementById ( "infected_dont_have_breaks_with_exposed" ) . checked || activity != "infected" ) {
if ( ! validateLunchBreak ( $ ( this ) . data ( 'time-group' ) ) ) {
submit = false ;
}
2020-11-27 12:12:55 +00:00
}
2020-11-26 14:52:11 +00:00
} ) ;
2020-11-18 22:20:05 +00:00
}
2021-02-10 10:17:48 +00:00
//Check if breaks length >= activity length
2021-03-19 15:38:27 +00:00
if ( submit ) {
$ ( "[data-lunch-for]" ) . each ( function ( ) {
var activity = $ ( this ) . data ( 'lunch-for' ) ;
if ( document . getElementById ( "infected_dont_have_breaks_with_exposed" ) . checked || activity != "infected" ) {
var activityBreaksObj = document . getElementById ( "activity_breaks" ) ;
removeErrorFor ( activityBreaksObj ) ;
var lunch _mins = 0 ;
if ( document . getElementById ( activity + "_lunch_option_yes" ) . checked ) {
var lunch _start = document . getElementById ( activity + "_lunch_start" ) ;
var lunch _finish = document . getElementById ( activity + "_lunch_finish" ) ;
lunch _mins = parseTimeToMins ( lunch _finish . value ) - parseTimeToMins ( lunch _start . value ) ;
}
2021-09-02 09:58:32 +00:00
2021-03-19 15:38:27 +00:00
var coffee _breaks = parseInt ( document . querySelector ( 'input[name="' + activity + '_coffee_break_option"]:checked' ) . value ) ;
var coffee _duration = parseInt ( document . getElementById ( activity + "_coffee_duration" ) . value ) ;
var coffee _mins = coffee _breaks * coffee _duration ;
var activity _start = document . getElementById ( activity + "_start" ) ;
var activity _finish = document . getElementById ( activity + "_finish" ) ;
var activity _mins = parseTimeToMins ( activity _finish . value ) - parseTimeToMins ( activity _start . value ) ;
if ( ( lunch _mins + coffee _mins ) >= activity _mins ) {
insertErrorFor ( activityBreaksObj , "Length of breaks >= Length of " + activity + " presence" ) ;
submit = false ;
}
2021-02-10 10:17:48 +00:00
}
2021-03-19 15:38:27 +00:00
} ) ;
}
2020-11-18 22:20:05 +00:00
2022-07-12 09:47:01 +00:00
// Logic for the API requests. Always set humity input as the empty string so that we can profit from the "room_heating_option default" values for humidity.
if ( $ ( "#arve_sensor_no" ) . prop ( 'checked' ) ) {
$ ( "[name='humidity']" ) . val ( '' ) ;
}
2021-09-02 09:58:32 +00:00
// Validate location input.
if ( submit ) {
// We make the non-visible location inputs mandatory, without marking them as "required" inputs.
// See https://stackoverflow.com/q/22148080/741316 for motivation.
var locationSelectObj = document . getElementById ( "location_select" ) ;
removeErrorFor ( locationSelectObj ) ;
$ ( "input[name*='location']" ) . each ( function ( ) {
el = $ ( this ) ;
if ( $ . trim ( el . val ( ) ) == '' ) {
submit = false ;
}
} ) ;
if ( ! submit ) {
insertErrorFor ( locationSelectObj , "Please select a location" ) ;
}
}
2022-09-20 12:48:46 +00:00
//Validate number of infected people
if ( ! validateMaxInfectedPeople ( ) ) submit = false ;
2020-12-07 21:59:30 +00:00
//Validate all non zero values
$ ( "input[required].non_zero" ) . each ( function ( ) {
if ( ! validateValue ( this ) ) {
submit = false ;
}
} ) ;
2020-12-07 21:55:41 +00:00
2022-06-16 13:07:56 +00:00
//Validate window venting duration < venting frequency
2022-08-24 10:33:02 +00:00
if ( $ ( "#windows_open_periodically" ) . prop ( 'checked' ) ) {
2020-12-07 21:55:41 +00:00
var windowsDurationObj = document . getElementById ( "windows_duration" ) ;
2022-06-16 13:07:56 +00:00
var windowsFrequencyObj = document . getElementById ( "windows_frequency" ) ;
removeErrorFor ( windowsFrequencyObj ) ;
2020-12-07 21:55:41 +00:00
2022-06-16 13:07:56 +00:00
if ( parseInt ( windowsDurationObj . value ) >= parseInt ( windowsFrequencyObj . value ) ) {
insertErrorFor ( windowsFrequencyObj , "Duration >= Frequency" ) ;
2020-12-07 21:55:41 +00:00
submit = false ;
}
}
2022-09-21 07:14:33 +00:00
// Validate cases < population
2022-10-03 13:42:37 +00:00
if ( $ ( "#p_probabilistic_exposure" ) . prop ( 'checked' ) ) {
2022-10-03 15:49:54 +00:00
// Set number of infected people as 1
$ ( "#infected_people" ) . val ( 1 ) ;
2022-09-21 07:14:33 +00:00
var geographicPopulationObj = document . getElementById ( "geographic_population" ) ;
var geographicCasesObj = document . getElementById ( "geographic_cases" ) ;
removeErrorFor ( geographicCasesObj ) ;
if ( parseInt ( geographicPopulationObj . value ) < parseInt ( geographicCasesObj . value ) ) {
insertErrorFor ( geographicCasesObj , "Cases > Population" ) ;
submit = false ;
}
}
2022-03-24 10:18:08 +00:00
// Generate the short-range interactions list
2022-03-18 11:53:01 +00:00
var short _range _interactions = [ ] ;
2022-01-28 11:08:28 +00:00
$ ( ".form_field_outer_row" ) . each ( function ( index , element ) {
2022-01-21 16:32:17 +00:00
let obj = { } ;
2022-03-18 14:47:12 +00:00
const $element = $ ( element ) ;
2022-03-28 13:41:55 +00:00
obj . expiration = $element . find ( "[name='short_range_expiration']" ) . val ( ) ;
2022-03-18 14:47:12 +00:00
obj . start _time = $element . find ( "[name='short_range_start_time']" ) . val ( ) ;
obj . duration = $element . find ( "[name='short_range_duration']" ) . val ( ) ;
2022-01-21 16:32:17 +00:00
short _range _interactions . push ( JSON . stringify ( obj ) ) ;
} ) ;
2022-03-18 11:53:01 +00:00
// Sort list by time
short _range _interactions . sort ( function ( a , b ) {
return JSON . parse ( a ) . start _time . localeCompare ( JSON . parse ( b ) . start _time ) ;
} ) ;
2022-01-21 16:32:17 +00:00
$ ( "input[type=text][name=short_range_interactions]" ) . val ( '[' + short _range _interactions + ']' ) ;
2022-02-08 09:57:37 +00:00
if ( short _range _interactions . length == 0 ) {
$ ( "input[type=radio][id=short_range_no]" ) . prop ( "checked" , true ) ;
on _short _range _option _change ( ) ;
}
2022-01-21 16:32:17 +00:00
2021-12-15 14:33:57 +00:00
if ( submit ) {
$ ( "#generate_report" ) . prop ( "disabled" , true ) ;
//Add spinner to button
$ ( "#generate_report" ) . html (
` <span id="loading_spinner" class="spinner-border spinner-border-sm mr-2" role="status" aria-hidden="true"></span>Loading... `
) ;
}
2020-11-06 19:06:29 +00:00
return submit ;
}
2020-11-17 20:58:03 +00:00
function validateValue ( obj ) {
2020-11-17 18:10:13 +00:00
$ ( obj ) . removeClass ( "red_border" ) ;
2020-12-03 08:38:21 +00:00
removeErrorFor ( obj ) ;
2020-11-17 18:10:13 +00:00
2020-11-25 18:51:32 +00:00
if ( ! isLessThanZeroOrEmpty ( $ ( obj ) . val ( ) ) ) {
2020-11-17 18:10:13 +00:00
$ ( obj ) . addClass ( "red_border" ) ;
2020-12-03 08:38:21 +00:00
insertErrorFor ( obj , "Value must be > 0" ) ;
2020-11-17 18:10:13 +00:00
return false ;
}
return true ;
}
2020-11-17 17:50:16 +00:00
2020-11-25 18:51:32 +00:00
function isLessThanZeroOrEmpty ( value ) {
2020-11-17 20:58:03 +00:00
if ( value === "" ) return true ;
2021-01-27 17:02:31 +00:00
if ( value <= 0 )
2020-11-17 20:58:03 +00:00
return false ;
return true ;
}
2020-11-16 20:59:38 +00:00
function validateDate ( obj ) {
$ ( obj ) . removeClass ( "red_border" ) ;
2020-12-03 08:38:21 +00:00
removeErrorFor ( obj ) ;
2020-11-14 15:30:20 +00:00
2020-11-17 17:50:16 +00:00
if ( ! isValidDateOrEmpty ( $ ( obj ) . val ( ) ) ) {
2020-11-16 20:59:38 +00:00
$ ( obj ) . addClass ( "red_border" ) ;
2020-12-03 08:38:21 +00:00
insertErrorFor ( obj , "Incorrect date format" ) ;
2020-11-16 20:59:38 +00:00
return false ;
2020-11-14 15:30:20 +00:00
}
2020-11-16 20:59:38 +00:00
return true ;
2020-11-14 15:30:20 +00:00
}
2020-11-17 20:58:03 +00:00
function isValidDateOrEmpty ( date ) {
if ( date === "" ) return true ;
var matches = /^(\d+)[-\/](\d+)[-\/](\d+)$/ . exec ( date ) ;
if ( matches == null ) return false ;
var d = matches [ 1 ] ;
var m = matches [ 2 ] ;
var y = matches [ 3 ] ;
if ( y > 2100 || y < 1900 ) return false ;
var composedDate = new Date ( y + '/' + m + '/' + d ) ;
return composedDate . getDate ( ) == d && composedDate . getMonth ( ) + 1 == m && composedDate . getFullYear ( ) == y ;
}
2020-11-16 20:59:38 +00:00
function validateFinishTime ( obj ) {
2020-11-27 15:50:01 +00:00
var groupID = $ ( obj ) . data ( 'time-group' ) ;
var startObj = $ ( ".start_time[data-time-group='" + groupID + "']" ) [ 0 ] ;
var finishObj = $ ( ".finish_time[data-time-group='" + groupID + "']" ) [ 0 ] ;
if ( $ ( finishObj ) . hasClass ( "finish_time_error" ) ) {
$ ( finishObj ) . removeClass ( "red_border finish_time_error" ) ;
2020-12-03 08:38:21 +00:00
removeErrorFor ( finishObj ) ;
2020-11-26 14:52:11 +00:00
}
2020-11-14 15:30:20 +00:00
2020-12-02 20:18:03 +00:00
//Check if finish time error (takes precedence over lunch break error)
2020-11-27 15:50:01 +00:00
var startTime = parseValToNumber ( startObj . value ) ;
var finishTime = parseValToNumber ( finishObj . value ) ;
2020-12-02 20:18:03 +00:00
if ( startTime >= finishTime ) {
2020-12-01 08:56:47 +00:00
$ ( finishObj ) . addClass ( "red_border finish_time_error" ) ;
2020-12-03 08:38:21 +00:00
removeErrorFor ( finishObj ) ;
insertErrorFor ( finishObj , "Finish time must be after start" ) ;
2020-11-16 20:59:38 +00:00
return false ;
2020-11-14 15:30:20 +00:00
}
2020-11-26 14:52:11 +00:00
return true ;
}
2020-12-02 20:18:03 +00:00
function validateLunchBreak ( lunchGroup ) {
2021-02-10 10:17:48 +00:00
//Valid if lunch break not selected
if ( document . getElementById ( lunchGroup + "_option_no" ) . checked )
return true ;
2020-12-02 20:18:03 +00:00
var lunchStartObj = $ ( ".start_time[data-time-group='" + lunchGroup + "']" ) [ 0 ] ;
var lunchFinishObj = $ ( ".finish_time[data-time-group='" + lunchGroup + "']" ) [ 0 ] ;
2020-11-26 14:52:11 +00:00
2020-12-02 20:18:03 +00:00
//Skip if finish time error present (it takes precedence over lunch break error)
if ( $ ( lunchStartObj ) . hasClass ( "finish_time_error" ) || $ ( lunchFinishObj ) . hasClass ( "finish_time_error" ) )
2020-12-03 08:38:21 +00:00
return false ;
2020-11-27 15:50:01 +00:00
2020-12-03 08:38:21 +00:00
removeErrorFor ( lunchFinishObj ) ;
2020-12-02 20:18:03 +00:00
var valid = validateLunchTime ( lunchStartObj ) & validateLunchTime ( lunchFinishObj ) ;
if ( ! valid ) {
2021-02-10 10:17:48 +00:00
insertErrorFor ( lunchFinishObj , "Lunch break must be within presence times" ) ;
2020-11-26 14:52:11 +00:00
}
2020-12-02 20:18:03 +00:00
return valid ;
}
//Check if exposed/infected lunch time within exposed/infected presence times
function validateLunchTime ( obj ) {
var activityGroup = $ ( obj ) . data ( 'lunch-for' ) ;
var activityStart = parseValToNumber ( $ ( ".start_time[data-time-group='" + activityGroup + "']" ) [ 0 ] . value ) ;
var activityFinish = parseValToNumber ( $ ( ".finish_time[data-time-group='" + activityGroup + "']" ) [ 0 ] . value ) ;
2020-11-26 14:52:11 +00:00
2020-12-02 20:18:03 +00:00
var time = parseValToNumber ( obj . value ) ;
$ ( obj ) . removeClass ( "red_border lunch_break_error" ) ;
2020-12-02 10:42:50 +00:00
if ( ( time < activityStart ) || ( time > activityFinish ) ) {
2020-11-26 15:14:54 +00:00
$ ( obj ) . addClass ( "red_border lunch_break_error" ) ;
2020-11-26 14:52:11 +00:00
return false ;
}
2020-11-16 20:59:38 +00:00
return true ;
2020-11-14 15:30:20 +00:00
}
2022-01-21 16:32:17 +00:00
function overlapped _times ( obj , start _time , finish _time ) {
2022-03-03 10:55:32 +00:00
removeErrorFor ( $ ( obj ) ) ;
$ ( obj ) . removeClass ( "red_border" ) ;
2022-04-04 14:33:13 +00:00
let parameter = document . getElementById ( $ ( obj ) . attr ( 'id' ) ) ;
if ( $ ( obj ) . attr ( 'name' ) == "short_range_duration" && parseFloat ( $ ( obj ) . val ( ) ) < 15.0 ) {
if ( ! $ ( obj ) . hasClass ( "red_border" ) ) $ ( parameter ) . addClass ( "red_border" ) ; //Adds the red border and error message.
2022-04-04 15:18:00 +00:00
insertErrorFor ( parameter , "Must be ≥ 15 min." )
2022-04-04 14:33:13 +00:00
return false ;
}
2022-01-26 14:15:30 +00:00
2022-01-25 16:12:24 +00:00
let simulation _start = parseTimeToMins ( $ ( "#exposed_start" ) . val ( ) )
let simulation _finish = parseTimeToMins ( $ ( "#exposed_finish" ) . val ( ) )
2022-03-10 11:36:10 +00:00
var simulation _lunch _start , simulation _lunch _finish ;
if ( $ ( 'input[name=exposed_lunch_option]:checked' ) . val ( ) == 1 ) {
simulation _lunch _start = parseTimeToMins ( $ ( "#exposed_lunch_start" ) . val ( ) )
simulation _lunch _finish = parseTimeToMins ( $ ( "#exposed_lunch_finish" ) . val ( ) )
} else {
simulation _lunch _start = 0
simulation _lunch _finish = 0
}
2022-01-25 16:12:24 +00:00
if ( start _time < simulation _start || start _time > simulation _finish ||
finish _time < simulation _start || finish _time > simulation _finish ||
start _time >= simulation _lunch _start && start _time <= simulation _lunch _finish ||
finish _time >= simulation _lunch _start && finish _time <= simulation _lunch _finish ) { //If start and finish inputs are out of the simulation period
2022-01-26 14:15:30 +00:00
//Adds the red border and error message.
if ( ! $ ( obj ) . hasClass ( "red_border" ) ) $ ( parameter ) . addClass ( "red_border" ) ;
2022-03-24 12:58:55 +00:00
insertErrorFor ( parameter , "Out of event time." ) ;
2022-02-24 15:33:35 +00:00
return false ;
2022-01-25 16:12:24 +00:00
}
let current _interaction = $ ( obj ) . closest ( ".form_field_outer_row" ) ;
2022-02-24 15:33:35 +00:00
var toReturn = true ;
$ ( ".form_field_outer_row.row_validated" ) . not ( current _interaction ) . each ( function ( index , el ) {
let current _start _el = $ ( el ) . find ( "input[name='short_range_start_time']" ) ;
let current _duration _el = $ ( el ) . find ( "input[name='short_range_duration']" )
start _time _2 = parseTimeToMins ( current _start _el . val ( ) )
finish _time _2 = parseTimeToMins ( current _start _el . val ( ) ) + parseInt ( current _duration _el . val ( ) ) ;
2022-03-14 15:28:04 +00:00
if ( ( start _time > start _time _2 && start _time < finish _time _2 ) || ( //If hour input is within other time range
finish _time > start _time _2 && finish _time < finish _time _2 ) || //If finish time input is within other time range
2022-01-25 16:12:24 +00:00
( start _time <= start _time _2 && finish _time >= finish _time _2 ) || //If start and finish inputs encompass other time range
start _time == start _time _2 ) {
if ( ! $ ( obj ) . hasClass ( "red_border" ) ) $ ( parameter ) . addClass ( "red_border" ) ; //Adds the red border and error message.
2022-03-14 11:12:44 +00:00
insertErrorFor ( parameter , "Time overlap." )
2022-02-24 15:33:35 +00:00
toReturn = false ;
2022-01-25 16:12:24 +00:00
return false ;
}
} ) ;
2022-02-24 15:33:35 +00:00
return toReturn ;
2022-01-21 16:32:17 +00:00
}
function validate _sr _time ( obj ) {
2022-01-25 16:12:24 +00:00
let obj _id = $ ( obj ) . attr ( 'id' ) . split ( '_' ) . slice ( - 1 ) [ 0 ] ;
2022-01-26 14:15:30 +00:00
var start _time , finish _time ;
if ( $ ( obj ) . val ( ) != "" ) {
2022-04-04 14:33:13 +00:00
if ( $ ( '#sr_start_no_' + String ( obj _id ) ) . val ( ) ) start _time = parseTimeToMins ( $ ( '#sr_start_no_' + String ( obj _id ) ) . val ( ) ) ;
else start = 0.
2022-01-26 14:15:30 +00:00
finish _time = start _time + parseInt ( $ ( '#sr_duration_no_' + String ( obj _id ) ) . val ( ) ) ;
}
2022-02-24 15:33:35 +00:00
return overlapped _times ( obj , start _time , finish _time ) ;
2022-01-21 16:32:17 +00:00
} ;
2022-03-24 10:18:08 +00:00
// Check if short-range durations are filled, and if there is no repetitions
2022-01-21 16:32:17 +00:00
function validate _sr _parameter ( obj , error _message ) {
2022-01-25 16:12:24 +00:00
if ( $ ( obj ) . val ( ) == "" || $ ( obj ) . val ( ) == null ) {
2022-01-26 14:15:30 +00:00
if ( ! $ ( obj ) . hasClass ( "red_border" ) && ! $ ( obj ) . prop ( "disabled" ) ) {
2022-01-25 16:12:24 +00:00
var parameter = document . getElementById ( $ ( obj ) . attr ( 'id' ) ) ;
insertErrorFor ( parameter , error _message )
$ ( parameter ) . addClass ( "red_border" ) ;
2022-01-21 16:32:17 +00:00
}
2022-01-25 16:12:24 +00:00
return false ;
} else {
removeErrorFor ( $ ( obj ) ) ;
$ ( obj ) . removeClass ( "red_border" ) ;
return true ;
}
2022-01-21 16:32:17 +00:00
}
2020-11-16 20:59:38 +00:00
function parseValToNumber ( val ) {
2020-11-17 20:58:03 +00:00
return parseInt ( val . replace ( ':' , '' ) , 10 ) ;
2020-11-09 18:55:06 +00:00
}
2020-11-19 18:57:23 +00:00
function parseTimeToMins ( cTime ) {
2020-11-20 10:05:04 +00:00
var time = cTime . match ( /(\d+):(\d+)/ ) ;
return parseInt ( time [ 1 ] * 60 ) + parseInt ( time [ 2 ] ) ;
2020-11-18 22:20:05 +00:00
}
2021-12-15 14:33:57 +00:00
// Prevent spinner when clicking on back button
window . onpagehide = function ( ) {
$ ( 'loading_spinner' ) . remove ( ) ;
$ ( "#generate_report" ) . prop ( "disabled" , false ) . html ( ` Generate report ` ) ;
} ;
2020-11-10 15:32:34 +00:00
/* -------On Load------- */
2020-11-07 10:31:40 +00:00
$ ( document ) . ready ( function ( ) {
2021-09-02 09:58:32 +00:00
var url = new URL ( decodeURIComponent ( window . location . href ) ) ;
2021-03-01 15:19:15 +00:00
//Pre-fill form with known values
2022-09-22 09:37:31 +00:00
2021-09-02 09:58:32 +00:00
url . searchParams . forEach ( ( value , name ) => {
2021-03-01 15:19:15 +00:00
//If element exists
if ( document . getElementsByName ( name ) . length > 0 ) {
var elemObj = document . getElementsByName ( name ) [ 0 ] ;
//Pre-select checked radios
if ( elemObj . type === 'radio' ) {
2021-04-21 14:07:50 +00:00
// Calculator <= 1.5.0 used to send not-applicable in the URL for radios that
// weren't set. Now those are not sent at all, but we keep the behaviour for compatibility.
2021-03-01 15:19:15 +00:00
if ( value !== 'not-applicable' ) {
$ ( '[name="' + name + '"][value="' + value + '"]' ) . prop ( 'checked' , true ) ;
}
}
//Pre-select checkboxes
else if ( elemObj . type === 'checkbox' ) {
elemObj . checked = ( value == 1 ) ;
}
2021-09-02 09:58:32 +00:00
2022-03-24 10:18:08 +00:00
// Read short-range from URL
2022-01-21 16:32:17 +00:00
else if ( name == 'short_range_interactions' ) {
let index = 1 ;
for ( const interaction of JSON . parse ( value ) ) {
2022-03-01 09:31:43 +00:00
$ ( "#dialog_sr" ) . append ( inject _sr _interaction ( index , value = interaction , is _validated = "row_validated" ) )
2022-03-28 13:41:55 +00:00
$ ( '#sr_expiration_no_' + String ( index ) ) . val ( interaction . expiration ) . change ( ) ;
document . getElementById ( 'sr_expiration_no_' + String ( index ) ) . disabled = true ;
2022-01-21 16:32:17 +00:00
document . getElementById ( 'sr_start_no_' + String ( index ) ) . disabled = true ;
document . getElementById ( 'sr_duration_no_' + String ( index ) ) . disabled = true ;
2022-02-24 15:33:35 +00:00
document . getElementById ( 'edit_row_no_' + String ( index ) ) . style . cssText = 'display:inline !important' ;
document . getElementById ( 'validate_row_no_' + String ( index ) ) . style . cssText = 'display: none !important' ;
2022-01-21 16:32:17 +00:00
index ++ ;
}
$ ( "#sr_interactions" ) . text ( index - 1 ) ;
}
2022-10-07 08:51:05 +00:00
else if ( name == 'sensor_in_use' || name == 'vaccine_type' || name == 'vaccine_booster_type' ) {
2022-09-27 16:10:07 +00:00
// Validation after
2022-06-22 12:59:49 +00:00
}
2021-03-01 15:19:15 +00:00
//Ignore 0 (default) values from server side
else if ( ! ( elemObj . classList . contains ( "non_zero" ) || elemObj . classList . contains ( "remove_zero" ) ) || ( value != "0.0" && value != "0" ) ) {
elemObj . value = value ;
validateValue ( elemObj ) ;
}
}
} ) ;
2022-10-07 08:51:05 +00:00
// Handle default URL values if they are not explicitly defined.
// Populate primary vaccine dropdown
$ ( "#vaccine_type option" ) . remove ( ) ;
2022-09-27 16:10:07 +00:00
let primary _vaccine = url . searchParams . has ( 'vaccine_type' ) ? url . searchParams . get ( 'vaccine_type' ) : null ;
2022-10-07 08:51:05 +00:00
vaccine _primary _host _immunity . forEach ( vaccine => $ ( "#vaccine_type" ) . append ( ` <option value= ${ vaccine } > ${ vaccine . replaceAll ( '_' , ' ' ) } </option> ` ) ) ;
$ ( ` #vaccine_type > option[value=" ${ primary _vaccine } "] ` ) . attr ( 'selected' , true ) ;
2022-09-27 16:10:07 +00:00
2022-10-07 08:51:05 +00:00
// Handle geographic location input
2021-09-02 09:58:32 +00:00
if ( Array . from ( url . searchParams ) . length > 0 ) {
if ( ! url . searchParams . has ( 'location_name' ) ) {
$ ( '[name="location_name"]' ) . val ( 'Geneva' )
$ ( '[name="location_select"]' ) . val ( 'Geneva' )
}
if ( ! url . searchParams . has ( 'location_latitude' ) ) {
$ ( '[name="location_latitude"]' ) . val ( '46.20833' )
}
if ( ! url . searchParams . has ( 'location_longitude' ) ) {
$ ( '[name="location_longitude"]' ) . val ( '6.14275' )
}
}
2022-10-12 14:49:42 +00:00
// Update geographic_cases
geographic _cases ( 'CHE' ) ;
2022-11-29 15:50:54 +00:00
// Handle WHO source message if geographic_cases pre-defined value is modified by user
$ ( '#geographic_cases' ) . change ( ( ) => $ ( '#source_geographic_cases' ) . hide ( ) ) ;
2022-10-12 14:49:42 +00:00
2020-11-06 19:41:12 +00:00
// When the document is ready, deal with the fact that we may be here
// as a result of a forward/back browser action. If that is the case, update
// the visibility of some of our inputs.
2021-02-10 10:17:48 +00:00
// Chrome fix - on back button infected break DIV not shown
if ( document . getElementById ( "infected_dont_have_breaks_with_exposed" ) . checked ) {
$ ( "#DIVinfected_breaks" ) . show ( ) ;
$ ( "#exposed_break_title" ) . show ( ) ;
require _lunch ( "infected_lunch_option_yes" , true ) ;
}
2020-12-09 20:46:15 +00:00
//Check all radio buttons previously selected
$ ( "input[type=radio]:checked" ) . each ( function ( ) { require _fields ( this ) } ) ;
2020-11-06 21:26:32 +00:00
2022-07-12 09:59:12 +00:00
// On CERN theme, when the arve_sensors_option changes we want to make its respective
2022-06-22 12:59:49 +00:00
// children show/hide.
2022-07-12 09:47:01 +00:00
if ( $ ( "input[type=radio][name=arve_sensors_option]" ) . length > 0 ) {
$ ( "input[type=radio][name=arve_sensors_option]" ) . change ( on _use _sensors _data _change ) ;
// Call the function now to handle forward/back button presses in the browser.
on _use _sensors _data _change ( url ) ;
}
2022-06-22 12:59:49 +00:00
2021-03-12 13:33:35 +00:00
// When the ventilation_type changes we want to make its respective
// children show/hide.
$ ( "input[type=radio][name=ventilation_type]" ) . change ( on _ventilation _type _change ) ;
// Call the function now to handle forward/back button presses in the browser.
on _ventilation _type _change ( ) ;
2022-08-24 10:33:02 +00:00
// When the window_opening_regime changes we want to make its respective
// children show/hide.
$ ( "input[type=radio][name=window_opening_regime]" ) . change ( on _window _opening _change ) ;
// Call the function now to handle forward/back button presses in the browser.
on _window _opening _change ( ) ;
2022-06-10 14:08:07 +00:00
// When the hepa filtration option changes we want to make its respective
// children show/hide.
$ ( "input[type=radio][name=hepa_option]" ) . change ( on _hepa _option _change ) ;
// Call the function now to handle forward/back button presses in the browser.
on _hepa _option _change ( ) ;
2022-10-03 13:42:37 +00:00
// When the exposure_option changes we want to make its respective
2022-09-21 07:14:33 +00:00
// children show/hide.
2022-10-03 15:49:54 +00:00
$ ( "input[type=radio][name=exposure_option]" ) . change ( on _exposure _change ) ;
2022-09-21 07:14:33 +00:00
// Call the function now to handle forward/back button presses in the browser.
2022-10-03 15:49:54 +00:00
on _exposure _change ( ) ;
2022-09-21 07:14:33 +00:00
2021-12-15 14:33:57 +00:00
// When the mask_wearing_option changes we want to make its respective
// children show/hide.
$ ( "input[type=radio][name=mask_wearing_option]" ) . change ( on _wearing _mask _change ) ;
// Call the function now to handle forward/back button presses in the browser.
on _wearing _mask _change ( ) ;
2022-09-22 09:25:06 +00:00
// When the vaccinated_option_option changes we want to make its respective
// children show/hide.
2022-09-22 09:37:31 +00:00
$ ( "input[type=radio][name=vaccine_option]" ) . change ( ( ) => on _vaccination _change ( url ) ) ;
2022-09-22 09:25:06 +00:00
// Call the function now to handle forward/back button presses in the browser.
2022-09-22 09:37:31 +00:00
on _vaccination _change ( url ) ;
// When the vaccine_type dropdown selected option changes we want to update
// the booster vaccine dropdown.
$ ( "#vaccine_type" ) . change ( ( ) => update _booster _dropdown ( url ) ) ;
$ ( "#vaccine_booster_type" ) . change ( update _booster _warning ) ;
2022-09-22 09:25:06 +00:00
// When the vaccinated_booster_option changes we want to make its respective
// children show/hide.
$ ( "input[type=radio][name=vaccine_booster_option]" ) . change ( on _vaccination _booster _change ) ;
// Call the function now to handle forward/back button presses in the browser.
on _vaccination _booster _change ( ) ;
2022-01-21 16:32:17 +00:00
// When the short_range_option changes we want to make its respective
// children show/hide.
$ ( "input[type=radio][name=short_range_option]" ) . change ( on _short _range _option _change ) ;
// Call the function now to handle forward/back button presses in the browser.
on _short _range _option _change ( ) ;
2022-07-29 09:49:06 +00:00
// When a lunch_option changes we want to make its respective children
// to show/hide
$ ( "input[type=radio][name=exposed_lunch_option]" ) . change ( on _lunch _break _option _change ) ;
$ ( "input[type=radio][name=infected_lunch_option]" ) . change ( on _lunch _break _option _change ) ;
// Call the function now to handle forward/back button presses in the browser.
on _lunch _break _option _change ( ) ;
2022-07-28 09:41:18 +00:00
// When the coffee_break_option changes we want to make its respective
// children show/hide
$ ( "input[type=radio][name=exposed_coffee_break_option]" ) . change ( on _coffee _break _option _change ) ;
$ ( "input[type=radio][name=infected_coffee_break_option]" ) . change ( on _coffee _break _option _change ) ;
// Call the function now to handle forward/back button presses in the browser.
on _coffee _break _option _change ( ) ;
2020-11-06 20:48:09 +00:00
// Setup the maximum number of people at page load (to handle back/forward),
// and update it when total people is changed.
2022-09-20 12:48:46 +00:00
validateMaxInfectedPeople ( ) ;
$ ( "#total_people" ) . change ( validateMaxInfectedPeople ) ;
$ ( "#activity_type" ) . change ( validateMaxInfectedPeople ) ;
$ ( "#total_people" ) . change ( validateMaxInfectedPeople ) ;
$ ( "#infected_people" ) . change ( validateMaxInfectedPeople ) ;
2020-11-13 15:30:35 +00:00
2020-11-17 20:58:03 +00:00
//Validate all non zero values
$ ( "input[required].non_zero" ) . each ( function ( ) { validateValue ( this ) } ) ;
$ ( ".non_zero" ) . change ( function ( ) { validateValue ( this ) } ) ;
2020-11-17 18:10:13 +00:00
2020-11-16 20:59:38 +00:00
//Validate all finish times
$ ( "input[required].finish_time" ) . each ( function ( ) { validateFinishTime ( this ) } ) ;
$ ( ".finish_time" ) . change ( function ( ) { validateFinishTime ( this ) } ) ;
2020-11-27 15:50:01 +00:00
$ ( ".start_time" ) . change ( function ( ) { validateFinishTime ( this ) } ) ;
2020-11-14 15:30:20 +00:00
2020-11-26 14:52:11 +00:00
//Validate lunch times
2020-12-02 20:18:03 +00:00
$ ( ".start_time[data-lunch-for]" ) . each ( function ( ) { validateLunchBreak ( $ ( this ) . data ( 'time-group' ) ) } ) ;
$ ( "[data-lunch-for]" ) . change ( function ( ) { validateLunchBreak ( $ ( this ) . data ( 'time-group' ) ) } ) ;
$ ( "[data-lunch-break]" ) . change ( function ( ) { validateLunchBreak ( $ ( this ) . data ( 'lunch-break' ) ) } ) ;
2021-09-02 09:58:32 +00:00
$ ( "#location_select" ) . select2 ( {
ajax : {
// Docs for the geocoding service at:
// https://developers.arcgis.com/rest/geocode/api-reference/geocoding-service-output.htm
url : "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest" ,
dataType : 'json' ,
delay : 250 ,
data : function ( params ) {
return {
text : params . term , // search term
f : 'json' ,
page : params . page ,
maxSuggestions : 20 ,
} ;
} ,
processResults : function ( data , params ) {
// Enable infinite scrolling
params . page = params . page || 1 ;
return {
results : data . suggestions . map ( function ( suggestion ) {
return {
id : suggestion . magicKey , // The unique reference to this result.
text : suggestion . text ,
magicKey : suggestion . magicKey
}
} ) ,
pagination : {
more : ( params . page * 10 ) < data . suggestions . length
}
} ;
} ,
cache : true
} ,
2021-12-15 14:33:57 +00:00
placeholder : 'Geneva, CHE' ,
2021-09-02 09:58:32 +00:00
minimumInputLength : 1 ,
templateResult : formatlocation ,
templateSelection : formatLocationSelection
} ) ;
function formatlocation ( suggestedLocation ) {
// Function is called for each location from the geocoding API.
if ( suggestedLocation . loading ) {
// Update the first message in the search results to show the
// "Searching..." message.
return suggestedLocation . text ;
}
// Create a container for this location (to be added to the DOM by the select2
// library when returned).
// This will become one of many search results in the dropdown.
var $container = $ (
"<div class='select2-result-location clearfix'>" +
"<div class='select2-result-location__meta'>" +
"<div class='select2-result-location__title'>" + suggestedLocation . text + "</div>" +
"</div>" +
"</div>"
) ;
return $container ;
}
function formatLocationSelection ( selectedSuggestion ) {
// Function is called when a selection is made in the search result dropdown.
// ID may be empty, for example when the page is refreshed or back button pressed.
if ( selectedSuggestion . id != "" ) {
// Turn the suggestion into a proper location (so that we can get its latitude & longitude).
$ . ajax ( {
dataType : "json" ,
url : 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates' ,
data : {
magicKey : selectedSuggestion . magicKey ,
outFields : 'country, location' ,
f : "json"
} ,
success : function ( locations ) {
// If there isn't precisely one result something is very wrong.
geocoded _loc = locations . candidates [ 0 ] ;
2022-10-12 14:49:42 +00:00
2021-09-02 09:58:32 +00:00
$ ( 'input[name="location_name"]' ) . val ( selectedSuggestion . text ) ;
$ ( 'input[name="location_latitude"]' ) . val ( geocoded _loc . location . y . toPrecision ( 7 ) ) ;
$ ( 'input[name="location_longitude"]' ) . val ( geocoded _loc . location . x . toPrecision ( 7 ) ) ;
2022-10-12 14:49:42 +00:00
// Update geographic_cases
geographic _cases ( geocoded _loc . attributes [ 'country' ] ) ;
2021-09-02 09:58:32 +00:00
}
} ) ;
} else if ( $ ( 'input[name="location_name"]' ) . val ( ) != "" ) {
// If we have no selection AND the location_name is available, use that in the search bar.
// This means that we preserve the location through refresh/back button.
return $ ( 'input[name="location_name"]' ) . val ( ) ;
}
return selectedSuggestion . text ;
}
2022-01-21 16:32:17 +00:00
2022-03-01 09:31:43 +00:00
function inject _sr _interaction ( index , value , is _validated ) {
2022-01-21 16:32:17 +00:00
return ` <div class="col-md-12 form_field_outer p-0">
2022-03-28 13:41:55 +00:00
< div class = "form_field_outer_row ${is_validated} split" >
2022-03-14 11:12:44 +00:00
< div class = 'form-group row' >
2022-03-28 13:41:55 +00:00
< div class = "col-sm-4" > < label class = "col-form-label col-form-label-sm" > Expiration : < / l a b e l > < b r > < / d i v >
< div class = "col-sm-8" > < select id = "sr_expiration_no_${index}" name = "short_range_expiration" class = "form-control form-control-sm" onchange = "validate_sr_parameter(this)" form = "not-submitted" >
2022-01-21 16:32:17 +00:00
< option value = "" selected disabled > Select type < / o p t i o n >
< option value = "Breathing" > Breathing < / o p t i o n >
< option value = "Speaking" > Speaking < / o p t i o n >
2022-06-13 15:19:05 +00:00
< option value = "Shouting" > Shouting / Singing < / o p t i o n >
2022-03-28 13:41:55 +00:00
< / s e l e c t > < b r >
2022-03-14 11:12:44 +00:00
< / d i v >
2022-01-21 16:32:17 +00:00
< / d i v >
2022-03-28 13:41:55 +00:00
< div class = 'form-group row' >
< div class = "col-sm-4" > < label class = "col-form-label col-form-label-sm" > Start : < / l a b e l > < / d i v >
< div class = "col-sm-8" > < input type = "time" class = "form-control form-control-sm short_range_option" name = "short_range_start_time" id = "sr_start_no_${index}" value = "${value.start_time}" onchange = "validate_sr_time(this)" form = "not-submitted" > < br > < / d i v >
2022-01-21 16:32:17 +00:00
< / d i v >
2022-03-28 13:41:55 +00:00
< div class = 'form-group row' >
2022-06-10 14:08:07 +00:00
< div class = "col-sm-6" > < label class = "col-form-label col-form-label-sm" > Duration ( min ) : < / l a b e l > < / d i v >
< div class = "col-sm-6" > < input type = "number" id = "sr_duration_no_${index}" value = "${value.duration}" class = "form-control form-control-sm short_range_option" name = "short_range_duration" min = 1 placeholder = "Minutes" onchange = "validate_sr_time(this)" form = "not-submitted" > < br > < / d i v >
2022-03-28 13:41:55 +00:00
< / d i v >
< div class = "form-group" style = "max-width: 8rem" >
2022-02-24 15:33:35 +00:00
< button type = "button" id = "edit_row_no_${index}" class = "edit_node_btn_frm_field btn btn-success btn-sm d-none" > Edit < / b u t t o n >
< button type = "button" id = "validate_row_no_${index}" class = "validate_node_btn_frm_field btn btn-success btn-sm" > Save < / b u t t o n >
< button type = "button" class = "remove_node_btn_frm_field btn btn-danger btn-sm" > Delete < / b u t t o n >
2022-01-21 16:32:17 +00:00
< / d i v >
< / d i v >
< / d i v > `
}
2022-03-14 15:28:04 +00:00
// Add one empty row if none.
$ ( "#set_interactions_button" ) . on ( "click" , e => {
if ( $ ( ".form_field_outer" ) . find ( ".form_field_outer_row" ) . length == 0 ) $ ( ".add_node_btn_frm_field" ) . click ( ) ;
} ) ;
2022-01-21 16:32:17 +00:00
// When short_range_yes option is selected, we want to inject rows for each expiractory activity, start_time and duration.
$ ( "body" ) . on ( "click" , ".add_node_btn_frm_field" , function ( e ) {
2022-03-21 10:51:38 +00:00
let last _row = $ ( ".form_field_outer" ) . find ( ".form_field_outer_row" ) ;
2022-04-04 14:33:13 +00:00
if ( last _row . length == 0 ) $ ( "#dialog_sr" ) . append ( inject _sr _interaction ( 1 , value = { activity : "" , start _time : "" , duration : "15" } ) ) ;
2022-01-25 16:12:24 +00:00
else {
2022-03-21 10:51:38 +00:00
last _index = last _row . last ( ) . find ( ".short_range_option" ) . prop ( "id" ) . split ( "_" ) . slice ( - 1 ) [ 0 ] ;
index = parseInt ( last _index ) + 1 ;
2022-04-04 14:33:13 +00:00
$ ( "#dialog_sr" ) . append ( inject _sr _interaction ( index , value = { activity : "" , start _time : "" , duration : "15" } ) ) ;
2022-02-24 15:33:35 +00:00
}
} ) ;
// Validate row button (Save button)
2022-03-03 10:55:32 +00:00
$ ( "body" ) . on ( "click" , ".validate_node_btn_frm_field" , function ( ) {
2022-03-15 16:37:44 +00:00
var index = $ ( this ) . attr ( 'id' ) . split ( '_' ) . slice ( - 1 ) [ 0 ] ;
2022-03-28 13:41:55 +00:00
let activity = validate _sr _parameter ( '#sr_expiration_no_' + String ( index ) [ 0 ] , "Required input." ) ;
2022-03-14 11:12:44 +00:00
let start = validate _sr _parameter ( '#sr_start_no_' + String ( index ) [ 0 ] , "Required input." ) ;
let duration = validate _sr _parameter ( '#sr_duration_no_' + String ( index ) [ 0 ] , "Required input." ) ;
2022-02-24 15:33:35 +00:00
if ( activity && start && duration ) {
2022-04-04 14:33:13 +00:00
if ( validate _sr _time ( '#sr_start_no_' + String ( index ) ) && validate _sr _time ( '#sr_duration_no_' + String ( index ) ) ) {
2022-03-28 13:41:55 +00:00
document . getElementById ( 'sr_expiration_no_' + String ( index ) ) . disabled = true ;
2022-01-21 16:32:17 +00:00
document . getElementById ( 'sr_start_no_' + String ( index ) ) . disabled = true ;
document . getElementById ( 'sr_duration_no_' + String ( index ) ) . disabled = true ;
2022-02-24 15:33:35 +00:00
document . getElementById ( 'edit_row_no_' + String ( index ) ) . style . cssText = 'display:inline !important' ;
2022-03-01 09:31:43 +00:00
$ ( this ) . closest ( ".form_field_outer_row" ) . addClass ( "row_validated" ) ;
2022-02-24 15:33:35 +00:00
$ ( this ) . hide ( ) ;
2022-01-25 16:12:24 +00:00
index = index + 1 ;
2022-01-21 16:32:17 +00:00
}
2022-01-25 16:12:24 +00:00
}
2022-03-21 10:51:38 +00:00
// On save, check open/unvalidated rows.
2022-03-15 16:37:44 +00:00
$ ( ".validate_node_btn_frm_field" ) . not ( ".row_validated" ) . not ( this ) . each ( function ( index ) {
index = $ ( this ) . attr ( 'id' ) . split ( '_' ) . slice ( - 1 ) [ 0 ] ;
2022-04-04 15:18:00 +00:00
if ( $ ( '#sr_start_no_' + String ( index ) [ 0 ] ) . val ( ) != "" ) {
validate _sr _parameter ( '#sr_start_no_' + String ( index ) [ 0 ] , "Required input." )
validate _sr _time ( '#sr_start_no_' + String ( index ) ) ;
} ;
if ( $ ( '#sr_duration_no_' + String ( index ) [ 0 ] ) . val ( ) != "" ) {
validate _sr _parameter ( '#sr_duration_no_' + String ( index ) [ 0 ] , "Required input." ) ;
validate _sr _time ( '#sr_duration_no_' + String ( index ) ) ;
}
2022-03-15 16:37:44 +00:00
} ) ;
2022-01-21 16:32:17 +00:00
} ) ;
2022-03-24 10:18:08 +00:00
//Edit short-range activity type
2022-02-24 15:33:35 +00:00
$ ( "body" ) . on ( "click" , ".edit_node_btn_frm_field" , function ( ) {
2022-04-04 14:33:13 +00:00
$ ( this ) . closest ( ".form_field_outer_row" ) . removeClass ( "row_validated" ) ;
2022-02-24 15:33:35 +00:00
$ ( this ) . hide ( ) ;
let id = $ ( this ) . attr ( 'id' ) . split ( '_' ) . slice ( - 1 ) [ 0 ] ;
2022-03-28 13:41:55 +00:00
document . getElementById ( 'sr_expiration_no_' + String ( id ) ) . disabled = false ;
2022-02-24 15:33:35 +00:00
document . getElementById ( 'sr_start_no_' + String ( id ) ) . disabled = false ;
document . getElementById ( 'sr_duration_no_' + String ( id ) ) . disabled = false ;
document . getElementById ( 'validate_row_no_' + String ( id ) ) . style . cssText = 'display:inline !important' ;
} )
2022-03-24 10:18:08 +00:00
//Remove short-range interaction (modal field row).
2022-01-21 16:32:17 +00:00
$ ( "body" ) . on ( "click" , ".remove_node_btn_frm_field" , function ( ) {
$ ( this ) . closest ( ".form_field_outer_row" ) . remove ( ) ;
2022-03-21 10:51:38 +00:00
// On delete, check open/unvalidated rows.
$ ( ".validate_node_btn_frm_field" ) . not ( ".row_validated" ) . not ( this ) . each ( function ( index ) {
index = $ ( this ) . attr ( 'id' ) . split ( '_' ) . slice ( - 1 ) [ 0 ] ;
2022-04-04 15:18:00 +00:00
if ( $ ( '#sr_start_no_' + String ( index ) [ 0 ] ) . val ( ) != "" ) {
validate _sr _parameter ( '#sr_start_no_' + String ( index ) [ 0 ] , "Required input." )
validate _sr _time ( '#sr_start_no_' + String ( index ) ) ;
} ;
if ( $ ( '#sr_duration_no_' + String ( index ) [ 0 ] ) . val ( ) != "" ) {
validate _sr _parameter ( '#sr_duration_no_' + String ( index ) [ 0 ] , "Required input." ) ;
validate _sr _time ( '#sr_duration_no_' + String ( index ) ) ;
}
2022-03-21 10:51:38 +00:00
} ) ;
2022-01-21 16:32:17 +00:00
} ) ;
2022-03-24 10:18:08 +00:00
//Short-range modal - close and save button
2022-02-24 15:33:35 +00:00
$ ( "body" ) . on ( "click" , ".close_btn_frm_field" , function ( ) {
2022-03-03 10:55:32 +00:00
$ ( ".validate_node_btn_frm_field" ) . click ( ) ;
if ( $ ( ".form_field_outer" ) . find ( ".form_field_outer_row.row_validated" ) . length == $ ( ".form_field_outer" ) . find ( ".form_field_outer_row" ) . length ) {
$ ( "#sr_interactions" ) . text ( $ ( ".form_field_outer" ) . find ( ".form_field_outer_row.row_validated" ) . length ) ;
$ ( ".form_field_outer_row" ) . not ( ".row_validated" ) . remove ( ) ;
$ ( '#short_range_dialog' ) . modal ( 'hide' ) ;
}
2022-01-21 16:32:17 +00:00
} ) ;
2022-03-24 10:18:08 +00:00
//Short-range modal - reset button
2022-01-21 16:32:17 +00:00
$ ( "body" ) . on ( "click" , ".dismiss_btn_frm_field" , function ( ) {
$ ( ".form_field_outer_row" ) . remove ( ) ;
$ ( "#sr_interactions" ) . text ( 0 ) ;
2022-02-08 09:57:37 +00:00
$ ( 'input[type=radio][id=short_range_no]' ) . prop ( "checked" , true ) ;
on _short _range _option _change ( ) ;
2022-01-21 16:32:17 +00:00
} ) ;
2020-11-07 10:52:01 +00:00
} ) ;
2021-09-02 09:58:32 +00:00
2020-11-07 10:52:01 +00:00
/* -------Debugging------- */
function debug _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 ) ;
2020-11-16 20:59:38 +00:00
2020-11-07 10:52:01 +00:00
return false ; //don't submit
}
function objectifyForm ( formArray ) {
var returnArray = { } ;
for ( var i = 0 ; i < formArray . length ; i ++ )
returnArray [ formArray [ i ] [ 'name' ] ] = formArray [ i ] [ 'value' ] ;
return returnArray ;
2021-01-27 17:02:31 +00:00
}
2022-10-07 08:51:05 +00:00
// ------- VACCINATION DATA -------
// From data available in Results of COVID-19 Vaccine Effectiveness
// Studies: An Ongoing Systematic Review - Updated September 8, 2022.
// https://view-hub.org/resources
vaccine _primary _host _immunity = [
'AZD1222_(AstraZeneca)' ,
'AZD1222_(AstraZeneca)_and_BNT162b2_(Pfizer)' ,
'AZD1222_(AstraZeneca)_and_any_mRNA_-_heterologous' ,
'Ad26.COV2.S_(Janssen)' ,
'Any_mRNA_-_heterologous' ,
'BBIBP-CorV_(Beijing_CNBG)' ,
'BNT162b2_(Pfizer)' ,
'BNT162b2_(Pfizer)_and_mRNA-1273_(Moderna)' ,
'CoronaVac_(Sinovac)' ,
'CoronaVac_(Sinovac)_and_AZD1222_(AstraZeneca)' ,
'CoronaVac_(Sinovac)_and_AZD1222_(AstraZeneca)_-_heterologous' ,
'CoronaVac_(Sinovac)_and_BNT162b2_(Pfizer)' ,
'Covishield' ,
'Sputnik_V_(Gamaleya)' ,
'mRNA-1273_(Moderna)' ,
]
vaccine _booster _host _immunity = [
2022-11-10 10:25:16 +00:00
{ 'primary series vaccine' : 'AZD1222_(AstraZeneca)' , 'booster vaccine' : 'AZD1222_(AstraZeneca)' , } ,
2022-10-07 08:51:05 +00:00
{ 'primary series vaccine' : 'AZD1222_(AstraZeneca)' , 'booster vaccine' : 'BNT162b2_(Pfizer)' , } ,
{ 'primary series vaccine' : 'AZD1222_(AstraZeneca)' , 'booster vaccine' : 'BNT162b2_(Pfizer)_or_mRNA-1273_(Moderna)' , } ,
{ 'primary series vaccine' : 'AZD1222_(AstraZeneca)' , 'booster vaccine' : 'mRNA-1273_(Moderna)' , } ,
{ 'primary series vaccine' : 'Ad26.COV2.S_(Janssen)' , 'booster vaccine' : 'Ad26.COV2.S_(Janssen)' , } ,
{ 'primary series vaccine' : 'Ad26.COV2.S_(Janssen)' , 'booster vaccine' : 'BNT162b2_(Pfizer)_or_mRNA-1273_(Moderna)' , } ,
{ 'primary series vaccine' : 'BNT162b2_(Pfizer)' , 'booster vaccine' : 'AZD1222_(AstraZeneca)' , } ,
{ 'primary series vaccine' : 'BNT162b2_(Pfizer)' , 'booster vaccine' : 'BNT162b2_(Pfizer)' , } ,
{ 'primary series vaccine' : 'BNT162b2_(Pfizer)' , 'booster vaccine' : 'BNT162b2_(Pfizer)_or_mRNA-1273_(Moderna)' , } ,
{ 'primary series vaccine' : 'BNT162b2_(Pfizer)' , 'booster vaccine' : 'mRNA-1273_(Moderna)' , } ,
{ 'primary series vaccine' : 'BNT162b2_(Pfizer)_and_mRNA-1273_(Moderna)' , 'booster vaccine' : 'BNT162b2_(Pfizer)_and_mRNA-1273_(Moderna)' , } ,
{ 'primary series vaccine' : 'BNT162b2_(Pfizer)_(3_doses)' , 'booster vaccine' : 'BNT162b2_(Pfizer)_(4th_dose)' , } ,
{ 'primary series vaccine' : 'CoronaVac_(Sinovac)' , 'booster vaccine' : 'AZD1222_(AstraZeneca)' , } ,
{ 'primary series vaccine' : 'CoronaVac_(Sinovac)' , 'booster vaccine' : 'BNT162b2_(Pfizer)' , } ,
{ 'primary series vaccine' : 'CoronaVac_(Sinovac)' , 'booster vaccine' : 'CoronaVac_(Sinovac)' , } ,
{ 'primary series vaccine' : 'mRNA-1273_(Moderna)' , 'booster vaccine' : 'BNT162b2_(Pfizer)' , } ,
{ 'primary series vaccine' : 'mRNA-1273_(Moderna)' , 'booster vaccine' : 'BNT162b2_(Pfizer)_or_mRNA-1273_(Moderna)' , } ,
{ 'primary series vaccine' : 'mRNA-1273_(Moderna)' , 'booster vaccine' : 'mRNA-1273_(Moderna)' , }
]