// NOTE: These fields aren't mandatory in the sense that snippet generation will fail // if they're not set, but they're really, really, really expected to be there. var _MANDATORY_PARAMS = { scenario: { "SCENARIO_NAME": "scenario name", "SCENARIO_DATE": "scenario date" }, } ; var _MONTH_NAMES = [ // nb: we assume English :-/ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ] ; // -------------------------------------------------------------------- function generate_snippet( $btn ) { // initialize storeMsgForTestSuite( "_last-info_", "" ) ; storeMsgForTestSuite( "_last-warning_", "" ) ; storeMsgForTestSuite( "_last-error_", "" ) ; // unload the template parameters var params = unload_params() ; var template_id = $btn.data( "id" ) ; if ( template_id === "ob_setup_1" ) { template_id = "ob_setup" ; params.OB_SETUP = params.OB_SETUP_1 ; params.OB_SETUP_COLOR = gNationalities[params.PLAYER_1].ob_colors[0] ; params.OB_SETUP_COLOR_2 = gNationalities[params.PLAYER_1].ob_colors[1] ; params.OB_SETUP_WIDTH = params.OB_SETUP_WIDTH_1 ; } else if ( template_id === "ob_setup_2" ) { template_id = "ob_setup" ; params.OB_SETUP = params.OB_SETUP_2 ; params.OB_SETUP_COLOR = gNationalities[params.PLAYER_2].ob_colors[0] ; params.OB_SETUP_COLOR_2 = gNationalities[params.PLAYER_2].ob_colors[1] ; params.OB_SETUP_WIDTH = params.OB_SETUP_WIDTH_2 ; } // extract the scenario date components var scenario_date = $("input[name='SCENARIO_DATE']").datepicker( "getDate" ) ; if ( scenario_date ) { params.SCENARIO_DAY_OF_MONTH = scenario_date.getDate() ; params.SCENARIO_MONTH = 1 + scenario_date.getMonth() ; params.SCENARIO_MONTH_NAME = _MONTH_NAMES[scenario_date.getMonth()] ; params.SCENARIO_YEAR = scenario_date.getFullYear() ; } // generate PF parameters if ( params.SCENARIO_YEAR < 1944 || (params.SCENARIO_YEAR == 1944 && params.SCENARIO_MONTH < 6) ) params.PF_RANGE = 1 ; else if ( params.SCENARIO_YEAR == 1944 ) params.PF_RANGE = 2 ; else params.PF_RANGE = 3 ; if ( params.SCENARIO_YEAR < 1943 || (params.SCENARIO_YEAR == 1943 && params.SCENARIO_MONTH <= 9) ) { params.PF_CHECK_DRM = "+1" ; params.PF_CHECK_DR = 4 ; } else if ( params.SCENARIO_YEAR >= 1945 ) { params.PF_CHECK_DRM = "-1" ; params.PF_CHECK_DR = 4 ; } else { params.PF_CHECK_DRM = "" ; params.PF_CHECK_DR = 3 ; } // generate BAZ parameters if ( params.SCENARIO_YEAR >= 1945 ) { params.BAZ_TYPE = 45 ; params.BAZ_BREAKDOWN = 11 ; params.BAZ_TOKILL = 16 ; params.BAZ_WP = 6 ; params.BAZ_RANGE = 5 ; } else if ( params.SCENARIO_YEAR >= 1944 ) { params.BAZ_TYPE = 44 ; params.BAZ_BREAKDOWN = 11 ; params.BAZ_TOKILL = 16 ; params.BAZ_RANGE = 4 ; } else if ( params.SCENARIO_YEAR == 1943 || (params.SCENARIO_YEAR == 1942 && params.SCENARIO_MONTH >= 11) ) { params.BAZ_TYPE = 43 ; params.BAZ_BREAKDOWN = 10 ; params.BAZ_TOKILL = 13 ; params.BAZ_RANGE = 4 ; } // check for mandatory parameters if ( template_id in _MANDATORY_PARAMS ) { var missing_params = [] ; for ( var param_id in _MANDATORY_PARAMS[template_id] ) { if ( ! (param_id in params && params[param_id].length > 0) ) missing_params.push( _MANDATORY_PARAMS[template_id][param_id] ) ; } if ( missing_params.length > 0 ) { var buf = [ "Missing parameters:
" + escapeHTML(ex) + "" ) ; return ; } // process the template try { val = func( params ) ; val = val.trim() ; } catch( ex ) { showErrorMsg( "Can't process template \"" + template_id + "\":
" + escapeHTML(ex) + "" ) ; return ; } try { copyToClipboard( val ) ; } catch( ex ) { showErrorMsg( "Can't copy to the clipboard:
" + escapeHTML(ex) + "" ) ; return ; } showInfoMsg( "The HTML snippet has been copied to the clipboard." ) ; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - function unload_params() { // collect all the template parameters var params = {} ; add_param = function($elem) { params[ $elem.attr("name") ] = $elem.val() ; } ; $("input[type='text'].param").each( function() { add_param($(this)) ; } ) ; $("textarea.param").each( function() { add_param($(this)) ; } ) ; $("select.param").each( function() { add_param($(this)) ; } ) ; // collect the SSR's params.SSR = [] ; $("#ssr-sortable li").each( function() { params.SSR.push( $(this).text() ) ; } ) ; return params ; } // -------------------------------------------------------------------- function on_load_scenario() { // FIXME! confirm this operation if the scenario is dirty // FOR TESTING PORPOISES! We can't control a file upload from Selenium (since // the browser will use native controls), so we store the result in a