// NOTE: This module manage simple notes (some text and an optional width),
// which is used by OB setups and OB notes (which differ only in their templates,
// the code to manage them is almost identical).
var gEditSimpleNoteDlgState = null ;
// --------------------------------------------------------------------
function add_scenario_note() { _do_edit_simple_note( "scenario_note", null, $("#scenario_notes-sortable"), null, gDefaultScenario._SCENARIO_NOTE_WIDTH, false ) ; }
function do_add_scenario_note( $sortable2, data ) { _do_add_simple_note($sortable2,data) ; }
function edit_scenario_note( $sortable2, $entry ) { _do_edit_simple_note( "scenario_note", null, $sortable2, $entry, null, false ) ; }
function add_ssr() { _do_edit_simple_note( "ssr", null, $("#ssr-sortable"), null, null, true ) ; }
function do_add_ssr( $sortable2, data ) { _do_add_simple_note($sortable2,data) ; }
function edit_ssr( $sortable2, $entry ) { _do_edit_simple_note( "ssr", null, $sortable2, $entry, null, true ) ; }
function add_ob_setup( player_no ) { _do_edit_simple_note( "ob_setup", player_no, $("#ob_setups-sortable_"+player_no), null, gDefaultScenario._OB_SETUP_WIDTH, true ) ; }
function do_add_ob_setup( $sortable2, data ) { _do_add_simple_note($sortable2,data) ; }
function edit_ob_setup( $sortable2, $entry ) { _do_edit_simple_note( "ob_setup", get_player_no_for_element($sortable2), $sortable2, $entry, null, true ) ; }
function add_ob_note( player_no ) { _do_edit_simple_note( "ob_note", player_no, $("#ob_notes-sortable_"+player_no), null, gDefaultScenario._OB_NOTE_WIDTH, false ) ; }
function do_add_ob_note( $sortable2, data ) { _do_add_simple_note($sortable2,data) ; }
function edit_ob_note( $sortable2, $entry ) { _do_edit_simple_note( "ob_note", get_player_no_for_element($sortable2), $sortable2, $entry, null, false ) ; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function _do_edit_simple_note( template_id, player_no, $sortable2, $entry, default_width, remove_first_para )
{
// figure out what we're editing
var note_type = _get_note_type_for_sortable( $sortable2 ) ;
var note_type0 = note_type.substring( 0, note_type.length-1 ) ; // plural -> singular :-/
// determine the next available ID
var usedIds = {} ;
$sortable2.children( "li" ).each( function() {
usedIds[ $(this).data("sortable2-data").id ] = true ;
} ) ;
var nextAvailableId = auto_assign_id( usedIds, "id" ) ;
function makeSimpleSnippet( evt ) {
// initialize
var $btnPane = $( ".ui-dialog.edit-simple_note .ui-dialog-buttonpane" ) ;
var $btn = $btnPane.find( "button.snippet" ) ;
var data = unloadData() ;
// prepare the template parameters
// NOTE: We don't bother handling the case of an empty caption.
var extraParams = {} ;
if ( template_id === "ssr" ) {
// NOTE: All the SSR's are combined into a single snippet, so it doesn't actually make sense
// to have a snippet button for individual SSR's, but it's convenient. We unload all the SSR's
// from the UI, then update the content for the one being edited (if it already exists), or
// add it to the end of the list (if it's a new one).
var ssrs = unload_ssrs() ;
if ( $entry ) {
// find and update the SSR being edited
$( "#ssr-sortable > li" ).each( function( index ) {
if ( $(this)[0] === $entry[0] )
ssrs[ index ] = data.caption ;
} ) ;
} else {
// add the new SSR to the end of the list
ssrs.push( data.caption ) ;
}
extraParams.SSR = ssrs ;
} else {
// override the template parameters unloaded from the UI with the current values from the dialog
var paramKey = template_id.toUpperCase() ;
extraParams[ paramKey ] = data.caption ;
extraParams[ paramKey+"_WIDTH" ] = data.width ;
}
// generate the snippet
generate_snippet( $btn, evt.shiftKey, extraParams ) ;
}
function unloadData() {
// unload the snippet data
return {
caption: unloadTrumbowyg( $caption, remove_first_para ),
width: $width.val().trim(),
} ;
}
// let the user edit the note
var dlgTitle = ($entry ? "Edit " : "Add ") + SORTABLE_DISPLAY_NAMES[note_type][0] ;
var $caption, $width, origData ;
var $dlg = $("#edit-simple_note").dialog( {
dialogClass: "edit-simple_note",
title: dlgTitle,
modal: true,
closeOnEscape: false,
position: gEditSimpleNoteDlgState ? gEditSimpleNoteDlgState.position : { my: "center", at: "center", of: window },
width: gEditSimpleNoteDlgState ? gEditSimpleNoteDlgState.width : $(window).width() * 0.4,
// NOTE: Simple notes don't normally have a lot of content, but we need space for the Trumbowyg dropdowns.
height: gEditSimpleNoteDlgState ? gEditSimpleNoteDlgState.height : Math.max( $(window).height() * 0.5, 325 ),
minWidth: 600,
minHeight: 250,
create: function() {
init_dialog( $(this), "OK", true ) ;
},
open: function() {
// initialize
$caption = $(this).find( "div.caption" ) ;
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") ;
var $btn = $btn_pane.find( "button.snippet" ) ;
$btn.prepend(
$( "" )
) ;
$width = $btn_pane.find( "input[name='width']" ) ;
if ( $width.length === 0 ) {
// create the width controls
$btn_pane.prepend( $( "