Re-implemented sortable's as a jQuery plugin.

master
Pacman Ghost 6 years ago
parent b387c2ed80
commit 904ca951a5
  1. 9
      vasl_templates/webapp/static/css/main.css
  2. 15
      vasl_templates/webapp/static/css/sortable.css
  3. 21
      vasl_templates/webapp/static/css/tabs-ob.css
  4. 10
      vasl_templates/webapp/static/css/tabs-scenario.css
  5. 86
      vasl_templates/webapp/static/main.js
  6. 48
      vasl_templates/webapp/static/simple_notes.js
  7. 48
      vasl_templates/webapp/static/snippets.js
  8. 206
      vasl_templates/webapp/static/sortable.js
  9. 6
      vasl_templates/webapp/static/utils.js
  10. 14
      vasl_templates/webapp/static/vo.js
  11. 61
      vasl_templates/webapp/templates/index.html

@ -84,15 +84,6 @@ input[type="text"] { margin-bottom: 0.25em ; }
/* -------------------------------------------------------------------- */
.sortable { font-size: 80% ; }
.sortable { list-style-type: none ; margin: 0 ; padding: 0 ; }
.sortable li {
margin-bottom: 2px ; padding: 5px ;
border: 1px dotted #333 ; background: #eee ;
}
.sortable li.highlighted { background: #48c8ff ; }
.sortable li:hover { cursor: pointer ; }
.ui-dialog-titlebar { padding: 0.2em 0.5em 0.2em 0.5em !important ; }
.ui-dialog-titlebar-close { margin-top: -10px !important ; }

@ -0,0 +1,15 @@
.sortable { font-size: 80% ; }
.sortable { list-style-type: none ; margin: 0 ; padding: 0 ; }
.sortable li {
margin-bottom: 2px ; padding: 5px ;
border: 1px dotted #333 ; background: #eee ;
}
.sortable li.highlighted { background: #48c8ff ; }
.sortable li:hover { cursor: pointer ; }
.sortable li input[type="button"] { float: right ; }
.sortable-hint { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; font-style: italic ; }
.sortable-hint p { margin-bottom: 1em ; }
.sortable-trash { margin-left: 5px ; height: 2em ; }

@ -10,13 +10,8 @@
.panel-ob_setups .content { -ms-grid-row: 1 ; -ms-grid-column: 1 ; }
.panel-ob_setups .footer { -ms-grid-row: 2 ; -ms-grid-column: 1 ; }
.panel-ob_setups ul.sortable li input[type="button"] { float: right ; }
.panel-ob_setups .footer { text-align: right ; font-size: 75% ; }
.panel-ob_setups .footer .l { float: left ; }
.ob_setups-trash { margin-left: 5px ; height: 2em ; }
.ob_setups-hint { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; font-style: italic ; }
.ob_setups-hint p { margin-bottom: 1em ; }
/* -------------------------------------------------------------------- */
@ -30,17 +25,11 @@
.panel-ob_notes .content { -ms-grid-row: 1 ; -ms-grid-column: 1 ; }
.panel-ob_notes .footer { -ms-grid-row: 2 ; -ms-grid-column: 1 ; }
.panel-ob_notes ul.sortable li input[type="button"] { float: right ; }
.panel-ob_notes .footer { font-size: 75% ; }
.panel-ob_notes .footer .l { float: left ; }
.panel-ob_notes .footer input[type="button"][data-id="ob_note"] { float: right ; }
.panel-ob_notes div.snippet-control { float: right ; margin: 0.25em 0.25em 0 0 ; }
.panel-ob_notes .footer .l { float: left ; }
.ob_notes-trash { margin-left: 5px ; height: 2em ; }
.ob_notes-hint { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; font-style: italic ; }
.ob_notes-hint p { margin-bottom: 1em ; }
/* -------------------------------------------------------------------- */
.panel-vehicles {
@ -55,10 +44,6 @@
.panel-vehicles .footer { text-align: right ; font-size: 75% ; }
.panel-vehicles .footer .l { float: left ; }
.vehicles-trash { margin-left: 5px ; height: 2em ; }
.vehicles-hint { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; font-style: italic ; }
.vehicles-hint p { margin-bottom: 1em ; }
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
@ -74,7 +59,3 @@
.panel-ordnance .footer { text-align: right ; font-size: 75% ; }
.panel-ordnance .footer .l { float: left ; }
.ordnance-trash { margin-left: 5px ; height: 2em ; }
.ordnance-hint { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; font-style: italic ; }
.ordnance-hint p { margin-bottom: 1em ; }

@ -70,14 +70,8 @@
#panel-scenario_notes .content { -ms-grid-row: 1 ; -ms-grid-column: 1 ; }
#panel-scenario_notes .footer { -ms-grid-row: 2 ; -ms-grid-column: 1 ; }
#panel-scenario_notes ul.sortable li input[type="button"] { float: right ; }
#panel-scenario_notes .footer { text-align: right ; font-size: 75% ; }
#panel-scenario_notes .footer .l { float: left ; }
#panel-scenario_notes #scenario_notes-trash { margin-left: 5px ; height: 2em ; }
#scenario_notes-hint { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; font-style: italic ; }
#scenario_notes-hint p { margin-bottom: 1em ; }
/* -------------------------------------------------------------------- */
@ -92,7 +86,3 @@
#panel-ssr .footer { text-align: right ; font-size: 75% ; }
#panel-ssr .footer .l { float: left ; }
#panel-ssr #ssr-trash { margin-left: 5px ; height: 2em ; }
#ssr-hint { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; font-style: italic ; }
#ssr-hint p { margin-bottom: 1em ; }

@ -14,7 +14,7 @@ var _NATIONALITY_SPECIFIC_BUTTONS = {
$(document).ready( function () {
// initialize
// initialize the menu
var $menu = $("#menu input") ;
$menu.popmenu( {
new_scenario: { label: "New scenario", action: on_new_scenario },
@ -66,86 +66,80 @@ $(document).ready( function () {
fixupOB2( $ob2 ) ;
$("#tabs-ob2").html( $ob2.html() ) ;
// initialize
// initialize the tabs
$("#tabs").tabs( {
heightStyle: "fill",
} ).show() ;
var navHeight = $("#tabs .ui-tabs-nav").height() ;
$("input[name='SCENARIO_NAME']").focus().focus() ;
// initialize
// initialize the scenario date picker
$("input[name='SCENARIO_DATE']").datepicker( {
showAnim: "slideDown",
changeMonth: true, changeYear: true,
defaultDate: "01/01/1940",
} ) ;
// initialize
init_sortable( $("#ssr-sortable"),
function() { add_ssr() ; },
edit_ssr
) ;
// initialize the SSR's
$("#ssr-sortable").sortable2( "init", {
add: add_ssr, edit: edit_ssr
} ) ;
// initialize the scenario notes
init_sortable( $("#scenario_notes-sortable"),
function() { add_scenario_note() ; },
edit_scenario_note
) ;
$("#scenario_notes-sortable").sortable2( "init", {
add: add_scenario_note, edit: edit_scenario_note,
} ) ;
$("#panel-scenario_notes input[type='button'][data-id='scenario_note']").click( function() {
edit_template( "scenario_note" ) ;
} ) ;
// initialize the OB setups
init_sortable( $("#ob_setups-sortable_1"),
function() { add_ob_setup(1) ; },
edit_ob_setup
) ;
$("#ob_setups-sortable_1").sortable2( "init", {
add: function() { add_ob_setup(1) ; },
edit: edit_ob_setup
} ) ;
$("#panel-ob_setups1 input[type='button'][data-id='ob_setup']").click( function() {
edit_template( "ob_setup" ) ;
} ) ;
init_sortable( $("#ob_setups-sortable_2"),
function() { add_ob_setup(2) ; },
edit_ob_setup
) ;
$("#ob_setups-sortable_2").sortable2( "init", {
add: function() { add_ob_setup(2) ; },
edit: edit_ob_setup
} ) ;
$("#panel-ob_setups2 input[type='button'][data-id='ob_setup']").click( function() {
edit_template( "ob_setup" ) ;
} ) ;
// initialize the OB notes
init_sortable( $("#ob_notes-sortable_1"),
function() { add_ob_note(1) ; },
edit_ob_note
) ;
$("#ob_notes-sortable_1").sortable2( "init", {
add: function() { add_ob_note(1) ; },
edit: edit_ob_note
} ) ;
$("#panel-ob_notes1 input[type='button'][data-id='ob_note']").click( function() {
edit_template( "ob_note" ) ;
} ) ;
init_sortable( $("#ob_notes-sortable_2"),
function() { add_ob_note(2) ; },
edit_ob_note
) ;
$("#ob_notes-sortable_2").sortable2( "init", {
add: function() { add_ob_note(2) ; },
edit: edit_ob_note
} ) ;
$("#panel-ob_notes2 input[type='button'][data-id='ob_note']").click( function() {
edit_template( "ob_note" ) ;
} ) ;
// initialize the OB vehicles
init_sortable( $("#vehicles-sortable_1"),
function() { add_vo( "vehicles", 1 ) ; },
null
) ;
init_sortable( $("#vehicles-sortable_2"),
function() { add_vo( "vehicles", 2 ) ; },
null
) ;
$("#vehicles-sortable_1").sortable2( "init", {
add: function() { add_vo( "vehicles", 1 ) ; },
} ) ;
$("#vehicles-sortable_2").sortable2( "init", {
add: function() { add_vo( "vehicles", 2 ) ; },
} ) ;
// initialize the OB ordnance
init_sortable( $("#ordnance-sortable_1"),
function() { add_vo( "ordnance", 1 ) ; },
null
) ;
init_sortable( $("#ordnance-sortable_2"),
function() { add_vo( "ordnance", 2 ) ; },
null
) ;
$("#ordnance-sortable_1").sortable2( "init", {
add: function() { add_vo( "ordnance", 1 ) ; },
} ) ;
$("#ordnance-sortable_2").sortable2( "init", {
add: function() { add_vo( "ordnance", 2 ) ; },
} ) ;
// handle ENTER and double-clicks in the "select vehicle/ordnance" dialog
function auto_select_vo( evt ) {
@ -387,8 +381,8 @@ function on_player_change( $select )
// reset the OB params
$("textarea[name='OB_SETUP_"+player_id+"']").val( "" ) ;
$("input[name='OB_SETUP_WIDTH_"+player_id+"']").val( "" ) ;
delete_all_sortable_entries( $( "#vehicles-sortable_" + player_id ) ) ;
$( "#vehicles-sortable_" + player_id ).sortable2( "delete-all" ) ;
$("input[name='VEHICLES_WIDTH_"+player_id+"']").val( "" ) ;
delete_all_sortable_entries( $( "#ordnance-sortable_" + player_id ) ) ;
$( "#ordnance-sortable_" + player_id ).sortable2( "delete-all" ) ;
$("input[name='ORDNANCE_WIDTH_"+player_id+"']").val( "" ) ;
}

@ -5,27 +5,27 @@
// --------------------------------------------------------------------
function add_scenario_note() { _do_edit_simple_note( $("#scenario_notes-sortable"), null ) ; }
function do_add_scenario_note( $sortable, data ) { _do_add_simple_note($sortable,data) ; }
function edit_scenario_note( $sortable, $entry ) { _do_edit_simple_note( $sortable, $entry ) ; }
function do_add_scenario_note( $sortable2, data ) { _do_add_simple_note($sortable2,data) ; }
function edit_scenario_note( $sortable2, $entry ) { _do_edit_simple_note( $sortable2, $entry ) ; }
function add_ssr() { _do_edit_simple_note( $("#ssr-sortable"), null ) ; }
function do_add_ssr( $sortable, data ) { _do_add_simple_note($sortable,data) ; }
function edit_ssr( $sortable, $entry ) { _do_edit_simple_note( $sortable, $entry ) ; }
function do_add_ssr( $sortable2, data ) { _do_add_simple_note($sortable2,data) ; }
function edit_ssr( $sortable2, $entry ) { _do_edit_simple_note( $sortable2, $entry ) ; }
function add_ob_setup( player_id ) { _do_edit_simple_note( $("#ob_setups-sortable_"+player_id), null ) ; }
function do_add_ob_setup( $sortable, data ) { _do_add_simple_note($sortable,data) ; }
function edit_ob_setup( $sortable, $entry ) { _do_edit_simple_note( $sortable, $entry ) ; }
function do_add_ob_setup( $sortable2, data ) { _do_add_simple_note($sortable2,data) ; }
function edit_ob_setup( $sortable2, $entry ) { _do_edit_simple_note( $sortable2, $entry ) ; }
function add_ob_note( player_id ) { _do_edit_simple_note( $("#ob_notes-sortable_"+player_id), null ) ; }
function do_add_ob_note( $sortable, data ) { _do_add_simple_note($sortable,data) ; }
function edit_ob_note( $sortable, $entry ) { _do_edit_simple_note( $sortable, $entry ) ; }
function do_add_ob_note( $sortable2, data ) { _do_add_simple_note($sortable2,data) ; }
function edit_ob_note( $sortable2, $entry ) { _do_edit_simple_note( $sortable2, $entry ) ; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function _do_edit_simple_note( $sortable, $entry )
function _do_edit_simple_note( $sortable2, $entry )
{
// figure out what we're editing
var note_type = _get_note_type_for_sortable( $sortable ) ;
var note_type = _get_note_type_for_sortable( $sortable2 ) ;
var note_type0 = note_type.substring( 0, note_type.length-1 ) ; // plural -> singular :-/
// let the user edit the note
@ -40,7 +40,7 @@ function _do_edit_simple_note( $sortable, $entry )
$width = $(this).children( "input[name='width']" ) ;
$width_label = $(this).children( "label[for='width']" ) ;
if ( $entry ) {
var data = $entry.data( "sortable-data" ) ;
var data = $entry.data( "sortable2-data" ) ;
$caption.val( data.caption ) ;
$width.val( data.width ) ;
}
@ -68,10 +68,10 @@ function _do_edit_simple_note( $sortable, $entry )
if ( $entry ) {
// update the existing note
if ( caption === "" )
delete_sortable_entry( $entry ) ;
$sortable2.sortable2( "delete", { entry: $entry } ) ;
else {
$entry.data("sortable-data").caption = caption ;
$entry.data("sortable-data").width = width ;
$entry.data("sortable2-data").caption = caption ;
$entry.data("sortable2-data").width = width ;
$entry.empty().append( _make_simple_note( note_type, caption ) ) ;
}
}
@ -79,7 +79,7 @@ function _do_edit_simple_note( $sortable, $entry )
// create a new note
if ( caption !== "" ) {
data = { caption: caption, width: width } ;
_do_add_simple_note( $sortable, data ) ;
_do_add_simple_note( $sortable2, data ) ;
}
}
$(this).dialog( "close" ) ;
@ -91,12 +91,14 @@ function _do_edit_simple_note( $sortable, $entry )
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function _do_add_simple_note( $sortable, data )
function _do_add_simple_note( $sortable2, data )
{
// add a new sortable entry
var note_type = _get_note_type_for_sortable( $sortable ) ;
var $entry = _make_simple_note( note_type, data.caption ) ;
add_sortable( $sortable, $entry , data ) ;
// add a new sortable2 entry
var note_type = _get_note_type_for_sortable( $sortable2 ) ;
$sortable2.sortable2( "add", {
content: _make_simple_note( note_type, data.caption ),
data: data,
} ) ;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -114,7 +116,7 @@ function _make_simple_note( note_type, caption )
// add a handler for the snippet button
$content.children("input[type='button']").click( function() {
var data = $(this).parent().parent().data( "sortable-data" ) ;
var data = $(this).parent().parent().data( "sortable2-data" ) ;
var key ;
if ( note_type === "scenario_notes" )
key = "SCENARIO_NOTE" ;
@ -133,10 +135,10 @@ function _make_simple_note( note_type, caption )
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function _get_note_type_for_sortable( $sortable )
function _get_note_type_for_sortable( $sortable2 )
{
// figure out what type of note the sortable has
var id = $sortable.prop( "id" ) ;
var id = $sortable2.prop( "id" ) ;
var match = /^((scenario_notes|ssr|vehicles|ob_setups|ob_notes))-sortable(_\d)?$/.exec( id ) ;
return match[1] ;
}

@ -205,16 +205,16 @@ function unload_params( params, check_date_capabilities )
// collect the SSR's
params.SSR = [] ;
var data = get_sortable_entry_data( $("#ssr-sortable") ) ;
var data = $("#ssr-sortable").sortable2( "get-entry-data" ) ;
for ( var i=0 ; i < data.length ; ++i )
params.SSR.push( data[i].caption ) ;
// collect the vehicles/ordnance
function get_vo( vo_type, player_id, key ) {
var $sortable = $( "#" + vo_type + "-sortable_" + player_id ) ;
var $sortable2 = $( "#" + vo_type + "-sortable_" + player_id ) ;
var objs = [] ;
$sortable.children( "li" ).each( function() {
var entry = $(this).data( "sortable-data" ).vo_entry ;
$sortable2.children( "li" ).each( function() {
var entry = $(this).data( "sortable2-data" ).vo_entry ;
var obj = {
name: entry.name,
note_number: entry.note_number,
@ -492,34 +492,34 @@ function do_load_scenario( params )
set_param( $("select[name='PLAYER_2']"), "PLAYER_2" ).trigger( "change" ) ;
var i ;
for ( var key in params ) {
var player_id, $sortable ;
var player_id, $sortable2 ;
if ( key === "SSR" ) {
$sortable = $( "#ssr-sortable" ) ;
$sortable2 = $( "#ssr-sortable" ) ;
for ( i=0 ; i < params[key].length ; ++i )
do_add_scenario_note( $sortable, { caption: params[key][i] } ) ;
do_add_scenario_note( $sortable2, { caption: params[key][i] } ) ;
params_loaded[key] = true ;
continue ;
}
if ( key === "SCENARIO_NOTES" ) {
$sortable = $( "#scenario_notes-sortable" ) ;
$sortable2 = $( "#scenario_notes-sortable" ) ;
for ( i=0 ; i < params[key].length ; ++i )
do_add_scenario_note( $sortable, params[key][i] ) ;
do_add_scenario_note( $sortable2, params[key][i] ) ;
params_loaded[key] = true ;
continue ;
}
if ( key === "OB_SETUPS_1" || key === "OB_SETUPS_2" ) {
player_id = key.substring( key.length-1 ) ;
$sortable = $( "#ob_setups-sortable_" + player_id ) ;
$sortable2 = $( "#ob_setups-sortable_" + player_id ) ;
for ( i=0 ; i < params[key].length ; ++i )
do_add_ob_setup( $sortable, params[key][i] ) ;
do_add_ob_setup( $sortable2, params[key][i] ) ;
params_loaded[key] = true ;
continue ;
}
if ( key === "OB_NOTES_1" || key === "OB_NOTES_2" ) {
player_id = key.substring( key.length-1 ) ;
$sortable = $( "#ob_notes-sortable_" + player_id ) ;
$sortable2 = $( "#ob_notes-sortable_" + player_id ) ;
for ( i=0 ; i < params[key].length ; ++i )
do_add_ob_note( $sortable, params[key][i] ) ;
do_add_ob_note( $sortable2, params[key][i] ) ;
params_loaded[key] = true ;
continue ;
}
@ -586,11 +586,11 @@ function on_save_scenario()
}
var params = {} ;
unload_params( params, false ) ;
params.SCENARIO_NOTES = get_sortable_entry_data( $("#scenario_notes-sortable") ) ;
params.OB_SETUPS_1 = get_sortable_entry_data( $("#ob_setups-sortable_1") ) ;
params.OB_SETUPS_2 = get_sortable_entry_data( $("#ob_setups-sortable_2") ) ;
params.OB_NOTES_1 = get_sortable_entry_data( $("#ob_notes-sortable_1") ) ;
params.OB_NOTES_2 = get_sortable_entry_data( $("#ob_notes-sortable_2") ) ;
params.SCENARIO_NOTES = $("#scenario_notes-sortable").sortable2( "get-entry-data" ) ;
params.OB_SETUPS_1 = $("#ob_setups-sortable_1").sortable2( "get-entry-data" ) ;
params.OB_SETUPS_2 = $("#ob_setups-sortable_2").sortable2( "get-entry-data" ) ;
params.OB_NOTES_1 = $("#ob_notes-sortable_1").sortable2( "get-entry-data" ) ;
params.OB_NOTES_2 = $("#ob_notes-sortable_2").sortable2( "get-entry-data" ) ;
extract_vo_names( "VEHICLES_1" ) ;
extract_vo_names( "ORDNANCE_1" ) ;
extract_vo_names( "VEHICLES_2" ) ;
@ -634,13 +634,13 @@ function on_new_scenario( verbose )
$("select[name='PLAYER_2_SAN']").val( 2 ) ;
// reset all the template parameters
delete_all_sortable_entries( $("#scenario_notes-sortable") ) ;
delete_all_sortable_entries( $("#ssr-sortable") ) ;
$("#scenario_notes-sortable").sortable2( "delete-all" ) ;
$("#ssr-sortable").sortable2( "delete-all" ) ;
for ( var i=1 ; i <= 2 ; ++i ) {
delete_all_sortable_entries( $( "#ob_setups-sortable_" + i ) ) ;
delete_all_sortable_entries( $( "#ob_notes-sortable_" + i ) ) ;
delete_all_sortable_entries( $( "#vehicles-sortable_" + i ) ) ;
delete_all_sortable_entries( $( "#ordnance-sortable_" + i ) ) ;
$( "#ob_setups-sortable_" + i ).sortable2( "delete-all" ) ;
$( "#ob_notes-sortable_" + i ).sortable2( "delete-all" ) ;
$( "#vehicles-sortable_" + i ).sortable2( "delete-all" ) ;
$( "#ordnance-sortable_" + i ).sortable2( "delete-all" ) ;
}
// provide some feedback to the user

@ -1,125 +1,117 @@
// --------------------------------------------------------------------
function init_sortable( $sortable, on_add, on_edit )
( function( $ ) {
$.fn.sortable2 = function( action, args )
{
// initialize the support elements
var $add = _find_sortable_helper( $sortable, "add" ) ;
$add.click( on_add ) ;
$sortable.data( "on_edit", on_edit ) ;
// handle dragging entries to the trash
var $trash = _find_sortable_helper( $sortable, "trash" ) ;
$sortable.sortable( { connectWith: $trash, cursor: "move" } ) ;
$trash.sortable( {
receive: function( evt, ui ) {
ui.item.remove() ;
update_sortable_hint($sortable) ;
}
} ) ;
}
var actions = {
"init": function( $sortable2 ) {
// initialize the sortable2 and support elements
$sortable2.data( "on_edit", args.edit ) ;
var $add = find_helper( $sortable2, "add" ) ;
$add.click( args.add ) ;
// handle dragging entries to the trash
var $trash = find_helper( $sortable2, "trash" ) ;
$trash.prop( "src", gImagesBaseUrl + "/trash.png" ) ;
$sortable2.sortable( { connectWith: $trash, cursor: "move" } ) ;
$trash.sortable( {
receive: function( evt, ui ) {
ui.item.remove() ;
update_hint( $sortable2 ) ;
}
} ) ;
},
// --------------------------------------------------------------------
"add": function( $sortable2 ) {
// add a new entry to the sortable2
var $entry = $( "<li></li>" ) ;
$entry.append( args.content ) ;
$entry.data( "sortable2-data", args.data ) ;
$sortable2.append( $entry ) ;
init_entry( $sortable2, $entry ) ;
// update the hint
update_hint( $sortable2 ) ;
},
function add_sortable( $sortable, $content, sortable_data )
{
// add a new entry to the sortable
var $entry = $( "<li></li>" ) ;
$entry.append( $content ) ;
$entry.data( "sortable-data", sortable_data ) ;
$sortable.append( $entry ) ;
init_sortable_entry( $entry ) ;
"delete": function( $sortable2 ) {
// delete the entry from the sortable2
delete_entry( $sortable2, args.entry ) ;
},
// update the hint
update_sortable_hint( $sortable ) ;
"delete-all": function( $sortable2 ) {
// delete all entries from the sortable2
$sortable2.children( "li" ).each( function() {
$(this).remove() ;
} ) ;
update_hint( $sortable2 ) ;
},
return $entry ;
}
"get-entry-data": function( $sortable2 ) {
// get the data associated with each sortable2 entry
var entry_data = [] ;
$sortable2.children( "li" ).each( function() {
entry_data.push( $(this).data( "sortable2-data" ) ) ;
} ) ;
return entry_data ;
},
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
} ;
function init_sortable_entry( $entry )
{
// initialize the sortable entry
var $sortable = $entry.parent() ;
var on_edit = $sortable.data( "on_edit" ) ;
if ( on_edit ) {
$entry.dblclick( function() {
on_edit( $sortable, $entry ) ;
function init_entry( $sortable2, $entry )
{
// initialize the sortable2 entry
var on_edit = $sortable2.data( "on_edit" ) ;
if ( on_edit ) {
$entry.dblclick( function() { // double-click => edit the entry
on_edit( $sortable2, $entry ) ;
} ) ;
}
$entry.click( function( evt ) { // ctrl-click => delete the entry
if ( evt.ctrlKey )
delete_entry( $sortable2, $(this) ) ;
} ) ;
}
$entry.click( function( evt ) {
if ( evt.ctrlKey )
delete_sortable_entry( $(this) ) ;
} ) ;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function update_sortable_hint( $sortable )
{
// show/hide the hint
var $hint = _find_sortable_helper( $sortable, "hint" ) ;
if ( $sortable.children("li").length === 0 ) {
$sortable.hide() ;
$hint.show() ;
} else {
$sortable.show() ;
$hint.hide() ;
function delete_entry( $sortable2, $entry )
{
// ask if it's OK to delete the entry
$entry.addClass( "highlighted" ) ;
var caption = $entry.data( "sortable2-data" ).caption ;
if ( ! caption )
caption = $entry.html() ;
ask( "OK to delete?", escapeHTML(caption), {
"ok": function() {
// yup - make it so
$entry.remove() ;
update_hint( $sortable2 ) ;
},
"close": function() { $entry.removeClass("highlighted") ; },
} ) ;
}
}
// --------------------------------------------------------------------
function delete_sortable_entry( $entry )
{
// initialize
var $sortable = $entry.parent() ;
// ask if it's OK to delete the entry
$entry.addClass( "highlighted" ) ;
var caption = $entry.data("sortable-data").caption ;
if ( ! caption )
caption = $entry.html() ;
ask( "OK to delete?", escapeHTML(caption), {
"ok": function() {
// yup - make it so
$entry.remove() ;
update_sortable_hint( $sortable ) ;
},
"close": function() { $entry.removeClass("highlighted") ; },
} ) ;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function delete_all_sortable_entries( $sortable )
{
// delete all entries from the sortable
$sortable.children("li").each( function() {
$(this).remove() ;
} ) ;
update_sortable_hint( $sortable ) ;
}
// --------------------------------------------------------------------
function update_hint( $sortable2 ) {
// show/hide the hint
var $hint = find_helper( $sortable2, "hint" ) ;
if ( $sortable2.children("li").length === 0 ) {
$sortable2.hide() ;
$hint.show() ;
} else {
$sortable2.show() ;
$hint.hide() ;
}
}
function get_sortable_entry_data( $sortable )
{
// get the data associated with each sortable entry
var entry_data = [] ;
$sortable.children("li").each( function() {
entry_data.push( $(this).data( "sortable-data" ) ) ;
} ) ;
return entry_data ;
}
function find_helper( $sortable2, type ) {
// find a helper element for the sortable2
var id = $sortable2.prop( "id" ) ;
var pos = id.indexOf( "sortable" ) ;
return $( "#" + id.substring(0,pos) + type+ id.substring(pos+8) ) ;
}
// --------------------------------------------------------------------
// execute the specified action
var retval = actions[action]( this ) ;
function _find_sortable_helper( $sortable, type )
{
// find a support element for the specified sortable
var id = $sortable.prop( "id" ) ;
var pos = id.indexOf( "sortable" ) ;
return $( "#" + id.substring(0,pos) + type+ id.substring(pos+8) ) ;
}
return (retval !== undefined) ? retval : this ;
} ;
} ) ( jQuery ) ;

@ -34,8 +34,9 @@ function copyToClipboard( val )
// --------------------------------------------------------------------
// Connect a text box to a select box, and filter the available options.
jQuery.fn.filterByText = function( $textbox ) {
( function( $ ) {
$.fn.filterByText = function( $textbox )
{
function compressSpaces( val ) { return val.replace( /\s/g, "" ).trim() ; }
return this.each( function() {
@ -74,6 +75,7 @@ jQuery.fn.filterByText = function( $textbox ) {
} ) ;
} ) ;
} ;
} ) ( jQuery ) ;
// --------------------------------------------------------------------

@ -4,9 +4,9 @@
function add_vo( vo_type, player_id )
{
// get the vehicles/ordnance already added
var $sortable = $( "#" + vo_type + "-sortable_" + player_id ) ;
var $sortable2 = $( "#" + vo_type + "-sortable_" + player_id ) ;
var vo_present = [];
$sortable.children("li").each( function() {
$sortable2.children("li").each( function() {
vo_present.push( $(this).text() ) ;
} );
@ -56,11 +56,11 @@ function add_vo( vo_type, player_id )
function do_add_vo( vo_type, player_id, entry )
{
// add the specified vehicle/ordnance
var $sortable = $( "#" + vo_type + "-sortable_" + player_id ) ;
add_sortable( $sortable,
$( "<div>" + entry.name + "</div>" ),
{ caption: entry.name, vo_entry: entry }
) ;
var $sortable2 = $( "#" + vo_type + "-sortable_" + player_id ) ;
$sortable2.sortable2( "add", {
content: $( "<div>" + entry.name + "</div>" ),
data: { caption: entry.name, vo_entry: entry }
} ) ;
}
// --------------------------------------------------------------------

@ -9,12 +9,15 @@
<link rel="stylesheet" type="text/css" href="{{url_for('static',filename='growl/jquery.growl.css')}}" />
<link rel="stylesheet" type="text/css" href="{{url_for('static',filename='popmenu/jquery.popmenu.css')}}" />
<link rel="stylesheet" type="text/css" href="{{url_for('static',filename='css/main.css')}}" />
<link rel="stylesheet" type="text/css" href="{{url_for('static',filename='css/sortable.css')}}" />
<link rel="stylesheet" type="text/css" href="{{url_for('static',filename='css/tabs-scenario.css')}}" />
<link rel="stylesheet" type="text/css" href="{{url_for('static',filename='css/tabs-ob.css')}}" />
</head>
<body>
<!-- ----------------------------------------------------------------- -->
<div id="menu" style="display:none;">
<input type="button" value="actions">
<input id="load-scenario" type="file" accept=".json" style="display:none;">
@ -22,6 +25,8 @@
<textarea id="template_pack_persistence" style="display:none;"></textarea>
</div>
<!-- ----------------------------------------------------------------- -->
<div id="tabs">
<ul>
@ -31,7 +36,10 @@
<li> <a href="#tabs-other">Other</a>
</ul>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<div id="tabs-scenario">
<fieldset class="tl"> <legend>S<u>c</u>enario</legend>
<div id="panel-scenario">
<div class="label" data-labelfor="SCENARIO_NAME">Name:</div> <input name="SCENARIO_NAME" type="text" class="param">
@ -57,6 +65,7 @@
<div class="footer"> <input type="button" class="generate" data-id="players" value="Snippet"> </div>
</div>
</fieldset>
<fieldset class="tr"> <legend>Victor<u>y</u> Conditions</legend>
<div id="panel-vc">
<textarea name="VICTORY_CONDITIONS" type="text" class="param"></textarea>
@ -67,31 +76,33 @@
</div>
</div>
</fieldset>
<fieldset class="bl"> <legend>Notes</legend>
<div id="panel-scenario_notes">
<div class="content">
<div id="scenario_notes-hint"> <p>Click on the "+" below to add a new scenario note. <p>To re-order the scenario notes, use the mouse to drag them around. <p>Ctrl-click on a scenario note to delete it, or drag it into the trashcan below. </div>
<div id="scenario_notes-hint" class="sortable-hint"> <p>Click on the "+" below to add a new scenario note. <p>To re-order the scenario notes, use the mouse to drag them around. <p>Ctrl-click on a scenario note to delete it, or drag it into the trashcan below. </div>
<ul id="scenario_notes-sortable" class="sortable" style="display:none;"></ul>
</div>
<div class="footer">
<div class="l">
<input type="button" id="scenario_notes-add" value="+">
<img id="scenario_notes-trash" src="{{url_for('static',filename='images/trash.png')}}">
<img id="scenario_notes-trash" class="sortable-trash">
</div>
<input type="button" data-id="scenario_note" value="EDIT">
</div>
</div>
</fieldset>
<fieldset class="br"> <legend>SSR's</legend>
<div id="panel-ssr">
<div class="content">
<div id="ssr-hint"> <p>Click on the "+" below to add a new SSR, double-click on an SSR to edit it. <p>To re-order the SSR's, use the mouse to drag them around. <p>Ctrl-click on an SSR to delete it, or drag it into the trashcan below. </div>
<div id="ssr-hint" class="sortable-hint"> <p>Click on the "+" below to add a new SSR, double-click on an SSR to edit it. <p>To re-order the SSR's, use the mouse to drag them around. <p>Ctrl-click on an SSR to delete it, or drag it into the trashcan below. </div>
<ul id="ssr-sortable" class="sortable" style="display:none;"></ul>
</div>
<div class="footer">
<div class="l">
<input type="button" id="ssr-add" value="+">
<img id="ssr-trash" src="{{url_for('static',filename='images/trash.png')}}">
<img id="ssr-trash" class="sortable-trash">
</div>
<label for="SSR_WIDTH">Width:</label>
<input type="text" class="param" name="SSR_WIDTH" size="5">
@ -99,34 +110,39 @@
</div>
</div>
</fieldset>
</div>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<div id="tabs-ob1">
<fieldset class="tl"> <legend>OB setup</legend>
<div id="panel-ob_setups1" class="panel-ob_setups">
<div class="content">
<div id="ob_setups-hint_1" class="ob_setups-hint"> <p>Click on the "+" below to add a new setup note. <p>To re-order the setup notes, use the mouse to drag them around. <p>Ctrl-click on a setup note to delete it, or drag it into the trashcan below. </div>
<div id="ob_setups-hint_1" class="sortable-hint"> <p>Click on the "+" below to add a new setup note. <p>To re-order the setup notes, use the mouse to drag them around. <p>Ctrl-click on a setup note to delete it, or drag it into the trashcan below. </div>
<ul id="ob_setups-sortable_1" class="sortable" style="display:none;"></ul>
</div>
<div class="footer">
<div class="l">
<input type="button" id="ob_setups-add_1" value="+">
<img id="ob_setups-trash_1" class="ob_setups-trash" src="{{url_for('static',filename='images/trash.png')}}">
<img id="ob_setups-trash_1" class="sortable-trash">
</div>
<input type="button" data-id="ob_setup" value="EDIT">
</div>
</div>
</fieldset>
<fieldset class="bl"> <legend>Notes</legend>
<div id="panel-ob_notes1" class="panel-ob_notes">
<div class="content">
<div id="ob_notes-hint_1" class="ob_notes-hint"> <p>Click on the "+" below to add a new setup note. <p>To re-order the setup notes, use the mouse to drag them around. <p>Ctrl-click on a setup note to delete it, or drag it into the trashcan below. </div>
<div id="ob_notes-hint_1" class="sortable-hint"> <p>Click on the "+" below to add a new setup note. <p>To re-order the setup notes, use the mouse to drag them around. <p>Ctrl-click on a setup note to delete it, or drag it into the trashcan below. </div>
<ul id="ob_notes-sortable_1" class="sortable" style="display:none;"></ul>
</div>
<div class="footer">
<div class="l">
<input type="button" id="ob_notes-add_1" value="+">
<img id="ob_notes-trash_1" class="ob_notes-trash" src="{{url_for('static',filename='images/trash.png')}}">
<img id="ob_notes-trash_1" class="sortable-trash">
</div>
<input type="button" data-id="ob_note" value="EDIT">
<input type="button" class="generate" data-id="mol" value="MOL">
@ -139,16 +155,17 @@
</div>
</div>
</fieldset>
<fieldset class="tr"> <legend>Vehicles</legend>
<div id="panel-vehicles_1" class="panel-vehicles">
<div class="content">
<div id="vehicles-hint_1" class="vehicles-hint"> <p>Click on the "+" below to add a new Vehicle. <p>To re-order the Vehicles, use the mouse to drag them around. <p>Ctrl-click on an Vehicle to delete it, or drag it into the trashcan below. </div>
<div id="vehicles-hint_1" class="sortable-hint"> <p>Click on the "+" below to add a new Vehicle. <p>To re-order the Vehicles, use the mouse to drag them around. <p>Ctrl-click on an Vehicle to delete it, or drag it into the trashcan below. </div>
<ul id="vehicles-sortable_1" class="sortable" style="display:none;"></ul>
</div>
<div class="footer">
<div class="l">
<input type="button" id="vehicles-add_1" value="+">
<img id="vehicles-trash_1" class="vehicles-trash" src="{{url_for('static',filename='images/trash.png')}}">
<img id="vehicles-trash_1" class="sortable-trash">
</div>
<label for="VEHICLES_WIDTH_1">Width:</label>
<input type="text" class="param" name="VEHICLES_WIDTH_1" size="5">
@ -156,16 +173,17 @@
</div>
</div>
</fieldset>
<fieldset class="br"> <legend>Ordnance</legend>
<div id="panel-ordnance_1" class="panel-ordnance">
<div class="content">
<div id="ordnance-hint_1" class="ordnance-hint"> <p>Click on the "+" below to add a new Gun. <p>To re-order the Gun's, use the mouse to drag them around. <p>Ctrl-click on an Gun to delete it, or drag it into the trashcan below. </div>
<div id="ordnance-hint_1" class="sortable-hint"> <p>Click on the "+" below to add a new Gun. <p>To re-order the Gun's, use the mouse to drag them around. <p>Ctrl-click on an Gun to delete it, or drag it into the trashcan below. </div>
<ul id="ordnance-sortable_1" class="sortable" style="display:none;"></ul>
</div>
<div class="footer">
<div class="l">
<input type="button" id="ordnance-add_1" value="+">
<img id="ordnance-trash_1" class="ordnance-trash" src="{{url_for('static',filename='images/trash.png')}}">
<img id="ordnance-trash_1" class="sortable-trash">
</div>
<label for="ORDNANCE_WIDTH_1">Width:</label>
<input type="text" class="param" name="ORDNANCE_WIDTH_1" size="5">
@ -173,11 +191,16 @@
</div>
</div>
</fieldset>
</div>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<div id="tabs-ob2"> <!-- nb: this will be created dynamically from the OB1 tab -->
</div>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<div id="tabs-other">
<div id="panel-other">
<fieldset>
@ -185,18 +208,28 @@
</div>
</div>
<div id="edit-template" style="display:none;"> <textarea></textarea> </div>
</div>
<!-- ----------------------------------------------------------------- -->
<div id="edit-template" style="display:none;">
<textarea></textarea>
</div>
<div id="edit-simple_note" style="display:none;">
<textarea></textarea>
<label for="width">Width:</label> <input name="width" type="text" size="5">
</div>
<div id="select-vo" style="display:none;">
<div class="header"> <b>Filter by:</b> <input type="text" size="10"> </div>
<select size=2></select> </div>
</div>
<div id="ask" style="display:none;"></div>
</div>
<!-- ----------------------------------------------------------------- -->
</body>
<script src="{{url_for('static',filename='jquery/jquery-3.3.1.min.js')}}"></script>

Loading…
Cancel
Save