summary: Fill timestamp_* param values automatically

These exist because TAME is nondeterministic, so all state must be passed
into it.  But it's inconvenient to have users have to manually fill in
dates, so we derive them from the environment unless they are set.

* src/current/scripts/entry-form.js (fillTimeValues): New function.
  (rater): Use it.
master
Mike Gerwitz 2019-04-19 11:46:29 -04:00
parent f270220b11
commit 5706ab4bef
1 changed files with 42 additions and 0 deletions

View File

@ -615,6 +615,45 @@ var client = ( function()
}
/**
* Fill in missing timestamp values from the current time
*
* Any of the following missing, empty, or 0 will have their values set:
* timestamp_{current,year,month,day}. Each of these are params defined
* in core and expected to be set by the caller.
*
* @param {Object} args param data
*
* @return {Object} args
*/
function fillTimeValues( args )
{
const now = new Date();
if ( !+args.timestamp_current )
{
args.timestamp_current = [ Math.floor( now.getTime() / 1000 ) ];
}
if ( !+args.timestamp_year )
{
args.timestamp_year = [ now.getFullYear() ];
}
if ( !+args.timestamp_month )
{
args.timestamp_month = [ now.getMonth() + 1 ];
}
if ( !+args.timestamp_day )
{
args.timestamp_day = [ now.getDate() ];
}
return args;
}
function rate( args, showresults, exception )
{
showresults = ( showresults === undefined ) ? true : !!showresults;
@ -628,6 +667,9 @@ var client = ( function()
return;
}
// TODO: need a better way to handle values that are added automatically
fillTimeValues( args );
setWorkStatus( 'Performing rating...' );
try