diff --git a/vasl_templates/webapp/data/default-templates/ssr.j2 b/vasl_templates/webapp/data/default-templates/ssr.j2 new file mode 100644 index 0000000..70397de --- /dev/null +++ b/vasl_templates/webapp/data/default-templates/ssr.j2 @@ -0,0 +1,2 @@ +{% for ssr in SSR %}(*) [{{ssr}}] +{% endfor %} diff --git a/vasl_templates/webapp/static/css/main.css b/vasl_templates/webapp/static/css/main.css index d7c890f..4f3e7cb 100644 --- a/vasl_templates/webapp/static/css/main.css +++ b/vasl_templates/webapp/static/css/main.css @@ -108,6 +108,21 @@ input[type="text"] { margin-bottom: 0.25em ; } #panel-vc textarea[name="victory_conditions"] { width: calc(100% - 2px) ; height: calc(100% - 1.5em) ; resize: none ; } #panel-vc input[type="button"] { float: right ; } +#panel-ssr #ssr-sortable { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; } +#panel-ssr #ssr-sortable { list-style-type: none ; margin: 0 ; padding: 0 ; } +#panel-ssr #ssr-sortable li { + margin-bottom: 2px ; padding: 5px ; + border: 1px dotted #333 ; background: #eee ; +} +#panel-ssr #ssr-sortable li.highlighted { background: #48c8ff ; } +#panel-ssr #ssr-sortable li:hover { cursor: pointer ; } +#panel-ssr input#add-ssr { float: left ; } +#panel-ssr #ssr-trash { margin-left: 5px ; float: left ; height: 1.5em ; } +#panel-ssr input[data-id="ssr"] { float: right ; } + +#ssr-hint { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; font-style: italic ; } +#ssr-hint p { margin-bottom: 1em ; } + #panel-obsetup1 textarea[name="ob_setup_1"] { width: calc(100% - 2px) ; height: calc(100% - 1.5em) ; resize: none ; } #panel-obsetup1 input[type="button"] { float: right ; } @@ -116,5 +131,11 @@ input[type="text"] { margin-bottom: 0.25em ; } /* -------------------------------------------------------------------- */ +.ui-dialog.edit-ssr .ui-dialog-titlebar { display: none ; } +.ui-dialog.edit-ssr .ui-dialog-buttonpane { border: none ; padding: 0 ; font-size: 75% ; } +#edit-ssr { padding: 2px ; } +.ui-dialog.edit-ssr textarea { resize: none ; width: calc(100% - 4px) ; height: calc(100% - 1.25em) ; } +.ui-dialog.edit-ssr button { margin: 0 0 0 5px ; padding: 0.1em 0.2em ; } + .growl-title { display: none ; } .growl ul { margin-left: 1em ; } diff --git a/vasl_templates/webapp/static/generate.js b/vasl_templates/webapp/static/generate.js index 41956a3..4c75d15 100644 --- a/vasl_templates/webapp/static/generate.js +++ b/vasl_templates/webapp/static/generate.js @@ -29,6 +29,12 @@ function generate_snippet( $btn ) params.OB_SETUP_COLOR = gNationalities[params.PLAYER_2].ob_colors[0] ; params.OB_SETUP_COLOR_2 = gNationalities[params.PLAYER_2].ob_colors[1] ; } + else if ( template_id === "ssr" ) { + params.SSR = [] ; + $("#ssr-sortable li").each( function() { + params.SSR.push( $(this).text() ) ; + } ) ; + } // check for mandatory parameters if ( template_id in _MANDATORY_PARAMS ) { diff --git a/vasl_templates/webapp/static/images/trash.png b/vasl_templates/webapp/static/images/trash.png new file mode 100755 index 0000000..e77a2d6 Binary files /dev/null and b/vasl_templates/webapp/static/images/trash.png differ diff --git a/vasl_templates/webapp/static/main.js b/vasl_templates/webapp/static/main.js index 0f7dd57..90f7769 100644 --- a/vasl_templates/webapp/static/main.js +++ b/vasl_templates/webapp/static/main.js @@ -12,6 +12,20 @@ $(document).ready( function () { var navHeight = $("#tabs .ui-tabs-nav").height() ; $("input[name='scenario_name']").focus().focus() ; + // 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 diff --git a/vasl_templates/webapp/static/ssr.js b/vasl_templates/webapp/static/ssr.js new file mode 100644 index 0000000..2a6a3fd --- /dev/null +++ b/vasl_templates/webapp/static/ssr.js @@ -0,0 +1,87 @@ + +// -------------------------------------------------------------------- + +function add_ssr() +{ + // add a new SSR + edit_ssr( null ) ; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function edit_ssr( $elem ) +{ + // let the user edit a SSR's content + $("#edit-ssr textarea").val( $elem ? $elem.text() : "" ) ; + $("#edit-ssr").dialog( { + dialogClass: "edit-ssr", + modal: true, + minWidth: 400, + minHeight: 150, + open: function() { + $(this).height( $(this).height() ) ; // fudge: force the textarea to resize + }, + buttons: { + OK: function() { + var val = $("#edit-ssr textarea").val().trim() ; + if ( $elem ) { + // update the existing SSR + if ( val !== "" ) + $elem.text( val ) ; + else + delete_ssr( $elem ) ; + } + else { + // create a new SSR + if ( val !== "" ) { + var $new_ssr = $( "
" ) ; + $new_ssr.text( val ) ; + $("#ssr-sortable").append( $new_ssr ) ; + init_ssr( $new_ssr ) ; + } + } + update_ssr_hint() ; + $(this).dialog( "close" ) ; + }, + Cancel: function() { $(this).dialog( "close" ) ; }, + }, + } ) ; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +function delete_ssr( $elem ) +{ + // delete the SSR + $elem.addClass( "highlighted" ) ; + ask( "Delete this SSR?", escapeHTML($elem.text()), { + "ok": function() { $elem.remove() ; update_ssr_hint() ; }, + "close": function() { $elem.removeClass("highlighted") ; }, + } ) ; +} + +// -------------------------------------------------------------------- + +function init_ssr( $elem ) +{ + // initialize SSR element(s) + $elem.dblclick( function() { + edit_ssr( $(this) ) ; + } ) ; + $elem.click( function( evt ) { + if ( evt.ctrlKey ) + delete_ssr( $(this) ) ; + } ) ; +} + +function update_ssr_hint() +{ + // show/hide the SSR hint + if ( $("#ssr-sortable li").length === 0 ) { + $("#ssr-sortable").hide() ; + $("#ssr-hint").show() ; + } else { + $("#ssr-sortable").show() ; + $("#ssr-hint").hide() ; + } +} diff --git a/vasl_templates/webapp/static/utils.js b/vasl_templates/webapp/static/utils.js index 7a9baeb..af66d93 100644 --- a/vasl_templates/webapp/static/utils.js +++ b/vasl_templates/webapp/static/utils.js @@ -33,6 +33,37 @@ function copyToClipboard( val ) // -------------------------------------------------------------------- +function ask( title, msg, args ) +{ + // ask a question + var $dlg = $("#ask") ; + $dlg.html( msg ) ; + $dlg.dialog( { + modal: true, + title: title, + 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 showInfoMsg( msg ) { // show the informational message @@ -40,7 +71,7 @@ function showInfoMsg( msg ) style: "notice", title: null, message: msg, - location: "br", + location: "tr", } ) ; storeMsgForTestSuite( "_last-info_", msg ) ; } @@ -54,7 +85,7 @@ function showWarningMsg( msg ) style: "warning", title: null, message: msg, - location: "br", + location: "tr", } ) ; storeMsgForTestSuite( "_last-warning_", msg ) ; } @@ -68,7 +99,7 @@ function showErrorMsg( msg ) style: "error", title: null, message: msg, - location: "br", + location: "tr", fixed: true, } ) ; storeMsgForTestSuite( "_last-error_", msg ) ; diff --git a/vasl_templates/webapp/templates/main.html b/vasl_templates/webapp/templates/main.html index c99cb80..2d16dfd 100644 --- a/vasl_templates/webapp/templates/main.html +++ b/vasl_templates/webapp/templates/main.html @@ -45,7 +45,10 @@