Allow user settings to be confirmed before updating a scenario.

master
Pacman Ghost 4 years ago
parent fbd07607de
commit e48ed5431f
  1. 3
      vasl_templates/webapp/static/css/user-settings-dialog.css
  2. 4
      vasl_templates/webapp/static/main.js
  3. 56
      vasl_templates/webapp/static/user_settings.js
  4. 13
      vasl_templates/webapp/static/vassal.js
  5. 9
      vasl_templates/webapp/templates/user-settings-dialog.html

@ -6,6 +6,9 @@
.ui-dialog.user-settings fieldset { margin: 0.5em 0 0 0 ; padding-top: 0.5em ; border-radius: 0 ; }
.ui-dialog.user-settings .select2 { margin-top: -4px ; }
.ui-dialog.user-settings .inactive { color: #888 ; }
.ui-dialog.user-settings .inactive .select2-selection__rendered { color: #888 !important ; }
.ui-dialog.user-settings img.need-localhost { display: inline-block ; height: 0.75em ; }
.ui-dialog.user-settings div.need-localhost { float: left ; width: 290px ; font-size: 80% ; font-style: italic ; color: #c02020 ; }
.ui-dialog.user-settings div.need-localhost img { float: left ; height: 1.5em ; margin-right: 0.25em ; }

@ -60,7 +60,9 @@ $(document).ready( function () {
analyze_vlog: { label: "Analyze log files", icon: imagesDir+"/lfa.png", action: on_analyze_vlog },
separator2: { type: "separator" },
template_pack: { label: "Load template pack", icon: imagesDir+"/template-pack.png", action: on_template_pack },
user_settings: { label: "Settings", icon: imagesDir+"/settings.png", action: user_settings },
user_settings: { label: "Settings", icon: imagesDir+"/settings.png", action: function() {
user_settings( null, null ) ;
} },
separator3: { type: "separator" },
show_help: { label: "Help", icon: imagesDir+"/help.png", action: show_help },
} ) ;

@ -4,29 +4,43 @@ SCENARIO_IMAGES_SOURCE_INTERNET = 2 ;
gUserSettings = Cookies.getJSON( "user-settings" ) || { "scenario-images-source": SCENARIO_IMAGES_SOURCE_INTERNET } ;
USER_SETTINGS = {
"vasl-username": "text",
"snippet-font-family": "text",
"snippet-font-size": "text",
"date-format": "droplist",
"scenario-images-source": "droplist",
"hide-unavailable-ma-notes": "checkbox",
"auto-create-national-capabilities-labels": "checkbox",
"include-vasl-images-in-snippets": "checkbox",
"include-flags-in-snippets": "checkbox",
"custom-list-bullets": "checkbox",
"vo-notes-as-images": "checkbox",
"vasl-username": { type: "text" },
"snippet-font-family": { type: "text", for_update_vsav: true },
"snippet-font-size": { type: "text", for_update_vsav: true },
"date-format": { type: "droplist" },
"scenario-images-source": { type: "droplist", for_update_vsav: true },
"hide-unavailable-ma-notes": { type: "checkbox", for_update_vsav: true },
"confirm-update-vsav-settings": { type: "checkbox", for_update_vsav: true },
"auto-create-national-capabilities-labels": { type: "checkbox", for_update_vsav: true },
"include-vasl-images-in-snippets": { type: "checkbox", for_update_vsav: true },
"include-flags-in-snippets": { type: "checkbox", for_update_vsav: true },
"custom-list-bullets": { type: "checkbox", for_update_vsav: true },
"vo-notes-as-images": { type: "checkbox", for_update_vsav: true },
} ;
// --------------------------------------------------------------------
function user_settings()
function user_settings( on_ok, caption )
{
function load_settings() {
// load each user setting
for ( var name in USER_SETTINGS ) {
var $elem = $( ".ui-dialog.user-settings [name='" + name + "']" ) ;
var func = handlers[ "load_" + USER_SETTINGS[name] ] ;
var func = handlers[ "load_" + USER_SETTINGS[name].type ] ;
func( $elem, gUserSettings[name] ) ;
// update the control (and associated label) for its active/inactive state
var $label = $( ".ui-dialog.user-settings label[for='" + name + "']" ) ;
if ( USER_SETTINGS[name].type == "droplist" )
$elem = $label.siblings( ".select2" ) ;
if ( on_ok && ! USER_SETTINGS[name].for_update_vsav ) {
// NOTE: It would be nice to also update the droplist items for select2's,
// but these are created dynamically and it's more trouble than it's worth :-/
$elem.addClass( "inactive" ) ;
$label.addClass( "inactive" ) ;
} else {
$elem.removeClass( "inactive" ) ;
$label.removeClass( "inactive" ) ;
}
}
update_ui() ;
}
@ -36,7 +50,7 @@ function user_settings()
var settings = {} ;
for ( var name in USER_SETTINGS ) {
var $elem = $( ".ui-dialog.user-settings [name='" + name + "']" ) ;
func = handlers[ "unload_" + USER_SETTINGS[name] ] ;
func = handlers[ "unload_" + USER_SETTINGS[name].type ] ;
gUserSettings[name] = func( $elem ) ;
}
return settings ;
@ -74,11 +88,11 @@ function user_settings()
// show the "user settings" dialog
$( "#user-settings" ).dialog( {
title: "User settings",
title: caption || "User settings",
dialogClass: "user-settings",
modal: true,
width: 460,
height: 375,
height: 400,
resizable: false,
create: function() {
init_dialog( $(this), "OK", true ) ;
@ -98,19 +112,19 @@ function user_settings()
// install handlers to keep the UI updated
for ( var name in USER_SETTINGS ) {
var $elem = $( ".ui-dialog.user-settings [name='" + name + "']" ) ;
if ( USER_SETTINGS[name] === "checkbox" )
if ( USER_SETTINGS[name].type === "checkbox" )
$elem.click( update_ui ) ;
else if ( USER_SETTINGS[name] === "droplist" )
else if ( USER_SETTINGS[name].type === "droplist" )
$elem.change( update_ui ) ;
}
},
open: function() {
on_dialog_open( $(this) ) ;
// load the current user settings
load_settings( $(this) ) ;
// FUDGE! Doing this in the "open" handler breaks loading the scenario-images-source droplist :shrug:
// FIXME! Using select2 breaks Ctrl-Enter handling :-(
$(this).find( "select" ).select2( { minimumResultsForSearch: -1 } ) ;
// load the current user settings
load_settings( $(this) ) ;
},
buttons: {
OK: function() {
@ -119,6 +133,8 @@ function user_settings()
save_user_settings() ;
apply_user_settings() ;
$(this).dialog( "close" ) ;
if ( on_ok )
setTimeout( on_ok, 50 ) ; // nb: work-around a timing issue in the PyQt app
},
Cancel: function() { $(this).dialog( "close" ) ; },
},

@ -2,7 +2,18 @@ gLoadVsavHandler = null ;
// --------------------------------------------------------------------
function on_update_vsav() { _load_and_process_vsav( _do_update_vsav ) ; }
function on_update_vsav() {
// check if we should ask the user to confirm the settings
if ( gUserSettings[ "confirm-update-vsav-settings" ] ) {
// yup - make it so
user_settings( function() {
_load_and_process_vsav( _do_update_vsav ) ;
}, "Confirm user settings" ) ;
} else {
// nope - just do it
_load_and_process_vsav( _do_update_vsav ) ;
}
}
function _do_update_vsav( vsav_data, fname )
{

@ -21,8 +21,13 @@
Hide unavailable multi-applicable notes
</div>
<div class="row">
<input type="checkbox" name="confirm-update-vsav-settings">
Confirm settings before updating scenarios
</div>
<div class="row" style="margin-top:0.25em;">
<label for="">Date format:</label>
<label for="date-format">Date format:</label>
<select name="date-format" style="width:9em;">
<option value="mm/dd/yy">MM/DD/YYYY</option>
<option value="dd/mm/yy">DD/MM/YYYY</option>
@ -31,7 +36,7 @@
</div>
<fieldset> <legend> Images in scenarios </legend>
Get images from:
<label for="scenario-images-source"> Get images from: </label>
<select name="scenario-images-source" style="width:7.5em;">
<option value="1">this program</option>
<option value="2">the internet</option>

Loading…
Cancel
Save