diff --git a/vasl_templates/webapp/static/main.js b/vasl_templates/webapp/static/main.js index 0761a22..a0fcf69 100644 --- a/vasl_templates/webapp/static/main.js +++ b/vasl_templates/webapp/static/main.js @@ -689,11 +689,9 @@ function on_player_change_with_confirm( player_no ) } else { // yup - make it so ask( "Change player nationality", - "

Do you want to change this player's nationality?

You will lose changes made to their OB.", { + "

Do you want to change this player's nationality?

You will lose changes made to their OB.", { ok: function() { on_player_change( player_no ) ; }, - cancel: function() { - $select.val( $select.data("prev-val") ).trigger( "change" ) ; - }, + cancel: function() { $select.val( $select.data("prev-val") ).trigger( "change" ) ; }, } ) ; } } diff --git a/vasl_templates/webapp/static/scenario-upload.js b/vasl_templates/webapp/static/scenario-upload.js index d46ca01..3726498 100644 --- a/vasl_templates/webapp/static/scenario-upload.js +++ b/vasl_templates/webapp/static/scenario-upload.js @@ -44,8 +44,10 @@ window.uploadScenario = function() { if ( vsavDataDecoded.length <= 1024*maxBytes ) doSelectVsavData( fname, vsavData ) ; else { - ask( "VASL scenario", "VASL scenario files should be less than " + maxBytes + " KB.", { + ask( "ASL Scenario Archive upload", + "VASL scenario files should be less than " + maxBytes + " KB.", { ok: function() { doSelectVsavData( fname, vsavData ) ; }, + ok_caption: "Continue", } ) ; } } @@ -88,8 +90,10 @@ window.uploadScenario = function() { if ( imageDataDecoded.length <= 1024*maxBytes ) doSelectScreenshotFile() ; else { - ask( "VASL screenshot", "Screenshots should be less than " + maxBytes + " KB.", { - ok: doSelectScreenshotFile + ask( "ASL Scenario Archive upload", + "Screenshots should be less than " + maxBytes + " KB.", { + ok: doSelectScreenshotFile, + ok_caption: "Continue", } ) ; } } @@ -236,9 +240,10 @@ function uploadFiles( asaScenarioId ) doUploadFiles() ; } else { // nope - confirm with the user first - ask( "Incomplete upload", warningMsg, { + ask( "ASL Scenario Archive upload", warningMsg, { width: width, ok: doUploadFiles, + ok_caption: "Continue", } ) ; } diff --git a/vasl_templates/webapp/static/simple_notes.js b/vasl_templates/webapp/static/simple_notes.js index 924e465..bf2dadf 100644 --- a/vasl_templates/webapp/static/simple_notes.js +++ b/vasl_templates/webapp/static/simple_notes.js @@ -41,9 +41,9 @@ function _do_edit_simple_note( $sortable2, $entry, default_width ) }, open: function() { // initialize - on_dialog_open( $(this) ) ; - add_flag_to_dialog_titlebar( $(this), get_player_no_for_element($sortable2) ) ; $caption = $(this).children( "textarea" ) ; + on_dialog_open( $(this), $caption ) ; + add_flag_to_dialog_titlebar( $(this), get_player_no_for_element($sortable2) ) ; var $btn_pane = $(".ui-dialog.edit-simple_note .ui-dialog-buttonpane") ; $width = $btn_pane.children( "input[name='width']" ) ; if ( $width.length === 0 ) { diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js index 56d2201..1631b44 100644 --- a/vasl_templates/webapp/static/snippets.js +++ b/vasl_templates/webapp/static/snippets.js @@ -1481,10 +1481,10 @@ function on_load_scenario() do_on_load_scenario() ; else { // yup - confirm the operation - ask( "Load scenario", "

This scenario has been changed.

Do you want load another scenario, and lose your changes?", { + ask( "Load scenario", + "

This scenario has been changed.

Do you want to load another scenario, and lose your changes?", { width: 470, ok: do_on_load_scenario, - cancel: function() {}, } ) ; } @@ -1897,9 +1897,9 @@ function on_new_scenario() do_on_new_scenario( true ) ; else { // yup - confirm the operation - ask( "New scenario", "

This scenario has been changed.

Do you want to reset it, and lose your changes?", { + ask( "New scenario", + "

This scenario has been changed.

Do you want to reset it, and lose your changes?", { ok: function() { do_on_new_scenario( true ) ; }, - cancel: function() {}, } ) ; } } diff --git a/vasl_templates/webapp/static/sortable.js b/vasl_templates/webapp/static/sortable.js index 003d4e1..3d8e92e 100644 --- a/vasl_templates/webapp/static/sortable.js +++ b/vasl_templates/webapp/static/sortable.js @@ -172,7 +172,8 @@ $.fn.sortable2 = function( action, args ) caption, "" ] ; - ask( "Delete "+display_name[0], buf.join(""), { + ask( "Delete " + display_name[0], + buf.join(""), { width: 350, ok: do_delete_entry, close: function() { set_entry_colors( $entry, false ) ; }, diff --git a/vasl_templates/webapp/static/utils.js b/vasl_templates/webapp/static/utils.js index 84f4a5f..d3f75be 100644 --- a/vasl_templates/webapp/static/utils.js +++ b/vasl_templates/webapp/static/utils.js @@ -209,7 +209,7 @@ function init_dialog( $dlg, ok_button_text, auto_dismiss ) } } -function on_dialog_open( $dlg ) +function on_dialog_open( $dlg, $focus ) { // initialize the dialog var ok_button_text = $dlg.data( "ok-button-text" ) ; @@ -217,8 +217,11 @@ function on_dialog_open( $dlg ) $( ".ui-dialog-buttonpane button:contains(Cancel)" ).addClass( "cancel" ) ; // set initial focus - var $cancel = $( ".ui-dialog-buttonpane button:contains(Cancel)" ) ; - $cancel.focus() ; + if ( ! $focus ) + $focus = $( ".ui-dialog-buttonpane button:contains(Cancel)" ) ; + setTimeout( function() { + $focus.focus() ; + }, 20 ) ; } function auto_dismiss_dialog( $dlg, evt, btn_text ) @@ -242,10 +245,23 @@ function click_dialog_button( $dlg, btn_text ) function ask( title, msg, args ) { + // initialize + var $dlg = $( "#ask" ) ; + buttons = {} ; + var ok_caption = args.ok_caption || "OK" ; + buttons[ ok_caption ] = function() { + $dlg.dialog( "close" ) ; + if ( "ok" in args ) + args.ok() ; + } ; + buttons.Cancel = function() { + $dlg.dialog( "close" ) ; + if ( "cancel" in args ) + args.cancel() ; + } ; + // ask a question - var $dlg = $("#ask") ; - $dlg.html( msg ) ; - $dlg.dialog( { + $dlg.html( msg ).dialog( { dialogClass: "ask", modal: true, closeOnEscape: false, // nb: handle_escape() has a special case for this dialog @@ -253,6 +269,7 @@ function ask( title, msg, args ) width: args.width || 400, minWidth: 250, maxHeight: window.innerHeight, + buttons: buttons, create: function() { init_dialog( $(this), "OK", false ) ; // we handle ESCAPE ourself, to make it the same as clicking Cancel, not just closing the dialog @@ -264,27 +281,14 @@ function ask( title, msg, args ) } ) ; }, open: function() { + $(this).data( "ok-button-text", ok_caption ) ; on_dialog_open( $(this) ) ; }, - buttons: { - OK: function() { - $(this).dialog( "close" ) ; - if ( "ok" in args ) - args.ok() ; - }, - Cancel: function() { - $(this).dialog( "close" ) ; - if ( "cancel" in args ) - args.cancel() ; - }, - }, close: function() { if ( "close" in args ) args.close() ; }, } ) ; - - return false ; } function showMsgDialog( title, msg, width ) diff --git a/vasl_templates/webapp/static/vassal.js b/vasl_templates/webapp/static/vassal.js index b87e814..bc28840 100644 --- a/vasl_templates/webapp/static/vassal.js +++ b/vasl_templates/webapp/static/vassal.js @@ -312,7 +312,7 @@ function on_analyze_vsav() if ( voDefined1 || voDefined2 ) { // yup - confirm the operation ask( "Analyze VASL scenario", - "

There are some vehicles/ordnance already configured.

They will be replaced with those found in the analyzed VASL scenario.", { + "

There are some vehicles/ordnance already configured.

They will be replaced with those found in the analyzed VASL scenario.", { width: 520, ok: function() { _load_and_process_vsav( _do_analyze_vsav ) ; }, } ) ; diff --git a/vasl_templates/webapp/static/vo.js b/vasl_templates/webapp/static/vo.js index b8880f4..2b1954b 100644 --- a/vasl_templates/webapp/static/vo.js +++ b/vasl_templates/webapp/static/vo.js @@ -134,7 +134,8 @@ function add_vo( vo_type, player_no ) } if ( usedVoIds.indexOf( sel_entry.id ) !== -1 ) { var vo_type2 = SORTABLE_DISPLAY_NAMES[ "ob_" + vo_type ][0] ; - ask( "Add "+vo_type2, "

This "+vo_type2+" is already in the OB

Do you want to add it again?", { + ask( "Add " + vo_type2, + "

This " + vo_type2 + " is already in the OB.

Do you want to add it again?", { width: 300, ok: add_sel_entry, } ) ;