Added a new template parameter for "day of month with postfix".

master
Pacman Ghost 6 years ago
parent f18ec59922
commit f75a81aa34
  1. 4
      vasl_templates/webapp/data/default-template-pack/scenario.j2
  2. 11
      vasl_templates/webapp/static/snippets.js

@ -15,10 +15,10 @@
</span>
{%if SCENARIO_LOCATION%} ({{SCENARIO_LOCATION}}) {%endif%}
{%if SCENARIO_DATE%}
<small><i>({{SCENARIO_MONTH_NAME}} {{SCENARIO_DAY_OF_MONTH}}, {{SCENARIO_YEAR}})</i></small>
<small><i>({{SCENARIO_MONTH_NAME}} {{SCENARIO_DAY_OF_MONTH_POSTFIX}}, {{SCENARIO_YEAR}})</i></small>
{%endif%}
</div>
</table>
</html>
</html>

@ -8,6 +8,11 @@ var _MONTH_NAMES = [ // nb: we assume English :-/
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
] ;
var _DAY_OF_MONTH_POSTFIXES = { // nb: we assume English :-/
0: "th",
1: "st", 2: "nd", 3: "rd", 4: "th", 5: "th", 6: "th", 7: "th", 8: "th", 9: "th", 10: "th",
11: "th", 12: "th", 13: "th"
} ;
// --------------------------------------------------------------------
@ -53,8 +58,14 @@ function generate_snippet( $btn )
// extract the scenario date components
var scenario_date = $("input[name='SCENARIO_DATE']").datepicker( "getDate" ) ;
var postfix ;
if ( scenario_date ) {
params.SCENARIO_DAY_OF_MONTH = scenario_date.getDate() ;
if ( params.SCENARIO_DAY_OF_MONTH in _DAY_OF_MONTH_POSTFIXES )
postfix = _DAY_OF_MONTH_POSTFIXES[ params.SCENARIO_DAY_OF_MONTH ] ;
else
postfix = _DAY_OF_MONTH_POSTFIXES[ params.SCENARIO_DAY_OF_MONTH % 10 ] ;
params.SCENARIO_DAY_OF_MONTH_POSTFIX = params.SCENARIO_DAY_OF_MONTH + postfix ;
params.SCENARIO_MONTH = 1 + scenario_date.getMonth() ;
params.SCENARIO_MONTH_NAME = _MONTH_NAMES[scenario_date.getMonth()] ;
params.SCENARIO_YEAR = scenario_date.getFullYear() ;

Loading…
Cancel
Save