var gNationalities = {} ; var gDefaultTemplates = {} ; var _NATIONALITY_SPECIFIC_BUTTONS = { "russian": [ "mol", "mol-p" ], "german": [ "pf", "psk", "atmm" ], "american": [ "baz" ], "british": [ "piat" ], } ; // -------------------------------------------------------------------- $(document).ready( function () { // initialize $("#tabs").tabs( { heightStyle: "fill", } ).show() ; var navHeight = $("#tabs .ui-tabs-nav").height() ; $("input[name='scenario_name']").focus().focus() ; // initialize $("input[name='scenario_date']").datepicker( { showAnim: "slideDown", changeMonth: true, changeYear: true, defaultDate: "01/01/1940", } ) ; // initialize $("#ssr-sortable").sortable( { connectWith: "#ssr-trash", cursor: "move" } ) ; init_ssr( $("#ssr-sortable li") ) ; $("#add-ssr").click( add_ssr ) ; $("#ssr-trash").sortable( { receive: function( evt, ui ) { ui.item.remove() ; update_ssr_hint() ; } } ) ; $("#edit-ssr textarea").keydown( function(evt) { if ( evt.keyCode == 13 && evt.ctrlKey ) { $(".ui-dialog.edit-ssr button:contains('OK')").click() ; evt.preventDefault() ; } } ) ; // load the ELR's and SAN's var buf = [] ; for ( var i=0 ; i <= 5 ; ++i ) // nb: A19.1: ELR is 0-5 buf.push( "" ) ; buf = buf.join( "" ) ; $("select[name='player_1_elr']").html( buf ).val( 5 ) ; $("select[name='player_2_elr']").html( buf ).val( 5 ) ; buf = [ "" ] ; // nb: allow scenarios that have no SAN for ( i=2 ; i <= 7 ; ++i ) // nb: A14.1: SAN is 2-7 buf.push( "" ) ; buf = buf.join( "" ) ; $("select[name='player_1_san']").html( buf ).val( 2 ) ; $("select[name='player_2_san']").html( buf ).val( 2 ) ; // load the nationalities $.getJSON( gGetNationalitiesUrl, function(data) { gNationalities = data ; var buf = [] ; for ( var id in gNationalities ) buf.push( "" ) ; on_player_change( $("select[name='player_1']").html( buf ).val( "german" ) ) ; on_player_change( $("select[name='player_2']").html( buf ).val( "russian" ) ) ; } ).fail( function( xhr, status, errorMsg ) { showErrorMsg( "Can't get the nationalities:
" + escapeHTML(errorMsg) + "
" ) ; } ) ; // add handlers for player changes $("select[name='player_1']").change( function() { on_player_change($(this)) ; } ) ; $("select[name='player_2']").change( function() { on_player_change($(this)) ; } ) ; // get the default templates $.getJSON( gGetTemplatesUrl, function(data) { gDefaultTemplates = data ; } ).fail( function( xhr, status, errorMsg ) { showErrorMsg( "Can't get the default templates:
" + escapeHTML(errorMsg) + "
" ) ; } ) ; var prevHeight = [] ; $(window).resize( function() { // FUDGE! CSS grids don't seem to update their layout vertically when // inside a jQuery tab control - we do it manually :-/ $(".ui-tabs-panel").each( function() { $(this).css( "padding", "5px" ) ; // FUDGE! doesn't work when set in the CSS :-/ var id = $(this).attr( "id" ) ; var h = $(this).parent().innerHeight() - navHeight - 20 ; if ( h !== prevHeight[id] ) { $(this).css( "height", h+"px" ) ; prevHeight[id] = h ; } } ) ; // FUDGE! Some panels are rendering with the wrong width in IE :-/ if ( isIE() ) { var set_width = function($elem) { $elem.width( $elem.parent().width() ) ; } ; set_width( $("#panel-vc textarea") ) ; set_width( $("#panel-ssr .content") ) ; } } ) ; $(window).trigger( "resize" ) ; // handle requests to generate HTML snippets $("input[type='button'].generate").click( function() { generate_snippet( $(this) ) ; } ) ; } ) ; // -------------------------------------------------------------------- function on_player_change( $select ) { // figure out which player was changed var name = $select.attr( "name" ) ; var player_id = name.substring( name.length-1 ) ; // update the tab label var player_nat = $select.find( "option:selected" ).val() ; var $elem = $("#tabs .ui-tabs-nav a[href='#tabs-ob" + player_id + "']") ; $elem.text( gNationalities[player_nat].display_name + " OB" ) ; // show/hide the nationality-specific buttons for ( var nat in _NATIONALITY_SPECIFIC_BUTTONS ) { for ( var i=0 ; i < _NATIONALITY_SPECIFIC_BUTTONS[nat].length ; ++i ) { var button_id = _NATIONALITY_SPECIFIC_BUTTONS[nat][i] ; $elem = $( "#panel-obsetup" + player_id + " input[type='button'][data-id='" + button_id + "']" ) ; $elem.css( "display", nat == player_nat ? "block" : "none" ) ; } } }