<?php $__env->startSection('page_title'); ?>
    OSAA - Invitational Meet Editor
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_sub_title'); ?>    
    Edit <?php echo $information['event']['name']; ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    @parent

	<script src="<?php echo asset('scripts/jquery.timepicker.min.js'); ?>" type="text/javascript"></script> 	

	<style type="text/css">
		.meet-label {
			margin-right: 15px;
		}
		.ui-autocomplete {
			max-height: 200px;
			overflow-y: auto;
			/* prevent horizontal scrollbar */
			overflow-x: hidden;
		}
		/* IE 6 doesn't support max-height
		* we use height instead, but this forces the menu to always be this tall
		*/
			* html .ui-autocomplete {
			height: 200px;
		}
	</style>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('jquery_init'); ?>
	$('.tooltip').tooltip();
	$('.tooltip.above').tooltip({ position : {my: "left bottom-15", at: "left top", collision: "flipfit"}});
	$('.tooltip.right').tooltip({ position : {my: "left+15 middle", at: "right middle", collision: "flipfit"}});

	$('.button').button();		
	$('.button.notext').button({text:false});
	$('.button.edit').button({ icons : { primary : 'ui-icon-pencil'}});
	$('.button.delete').button({ icons : { primary : 'ui-icon-closethick'}});
	$('.button.drop').button({ icons : { primary : 'ui-icon-circle-close'}});
	$('.button.cancel').button({ icons : { primary : 'ui-icon-circle-minus'}});
	$('.button.trash').button({ icons : { primary : 'ui-icon-trash'}});
	$('.button.clipboard').button({ icons : { primary : 'ui-icon-clipboard'}});
	$('.button.print').button({ icons : { primary : 'ui-icon-print'}});
	$('.button.add').button({ icons : { primary : 'ui-icon-plusthick'}});
	$('.button.next').button({ icons : { secondary : 'ui-icon-triangle-1-e'}});
	$('.button.add_teams').button({ icons : { secondary : 'ui-icon-triangle-1-e'}});	
	$('.button.join').button({ icons : { secondary : 'ui-icon-triangle-1-e'}});
	$('.button.next_add').button({ icons : { secondary : 'ui-icon-plus'}});
	$('.button.add_more_team_spots').button({ icons : { primary : 'ui-icon-plus'}});
	$('.button.create').button({ icons : { secondary : 'ui-icon-triangle-1-e'}});
	$('.button.search').button({ icons : { secondary : 'ui-icon-triangle-1-e'}});
	$('.button.reset').button({ icons : { primary : 'ui-icon-triangle-1-w'}});
	$('.button.submit_scores').button({ icons : { primary : 'ui-icon-circle-arrow-e' }});	
	$('.home_button').button({ icons : { primary : 'ui-icon-home'}, text : false}).css('height', '24px').css('margin-top', '3px');
	$('.team_view_button').button({ icons : { primary : 'ui-icon-bookmark'}}).css('margin-right', '10px').css('margin-top', '3px');
	$('.oos_button').button({ icons : { primary : 'ui-icon-note' }}).css('margin-right', '10px').css('margin-top', '3px');
	
	$('.button_set').buttonset();
	$('.button_set label').addClass('ui-corner-all');
	$('.submit_button').button();
 
	$('#event_date, #event_date2').datepicker({'dateFormat' : 'mm/dd/yy', 'defaultDate' : '<?php echo json_encode($information['event']['start_at']); ?>'});
	
	$('#event_time, #event_time2').timepicker({ 'timeFormat': 'h:i A' , 'step' : 15, 'maxTime' : '10:00pm'});

  	function updateOOSState ()
    {
		if ($('#host_is_oos:checked').length > 0)
    	{
    		$('#state').removeAttr('disabled');   		
    	}
    	else
    	{
    		$('#state').attr('disabled', 'disabled');
    	}  
	}

	updateOOSState ();

    $('input[name="host_is_oos"]').change(function ()
    {
    	updateOOSState ();
    });

    availableOpponents = <?php echo json_encode($information['available_opponents']); ?>;
	$('.school_autocomplete').autocomplete(
    {
    	source : availableOpponents
	});

	$('.location_autocomplete').autocomplete(
    {
    	source : <?php echo json_encode($information['available_locations']); ?>
	});





    $('.invitation_list_viewer').dialog({
    	autoOpen : false,
		buttons :
		[
			{
				text : 'Done', 'class' : 'float_right', click : function () {
					$(this).dialog('close');
				}
			}
		],
		draggable : false,
		height: 'auto',
		modal : true,
		open : function ()
		{
			$('.invitation_list_viewer').html("<div class='ajax_loader' style='width:16px; height:11px; margin:4em auto; background-image: url(http://www.osaa.org/images/icons/ajax_loader2.gif); background-repeat:no-repeat;'></div>");
			populateInvitationList();
		},
		resizable : false,
		show : {
			effect : 'highlight',
			delay : 0,
			duration : 400,
			easing : 'easeInOutSine'
		},
		title : <?php echo json_encode($information['event']['name']); ?>,
		width : 900
	});

    $('#edit_invitation_list').click(function () {
        $('.invitation_list_viewer').dialog('open');
    });


    function populateInvitationList(message) {
		var meet = <?php echo json_encode($information['id']); ?>;
		var jqxhr = $.ajax({
			type : 'GET',
			url : '/meets/' + meet + '/invitation-list?mode=ajax',
			dataType : 'html'
		})
		.done(function (data){
			$('.invitation_list_viewer').html(data);
			$('.button').button();

			$('.button.cancel[data-action="drop"]').click(function ()
			{
				$('#confirm_drop_dialog_meet')
					.attr('data-meet', $(this).attr('data-meet'))
					.attr('data-team', $(this).attr('data-team'))
					.attr('data-team-name', $(this).attr('data-team-name'))
					.dialog('open');
			});

			$('.school_autocomplete').autocomplete(
			{
				source : availableOpponents
			});

			$('#add_new_team').click(function(){invite_add_team()});

			$('#team_is_oos').change(function ()
			{
				if ($('#team_is_oos:checked').length > 0)
				{
					$('#new_team_state').removeAttr('disabled');   		
				}
				else
				{
					$('#new_team_state').attr('disabled', 'disabled');
				}
			});

			$('#new_team_form').submit(function(){return false;});

			if(typeof(message) != "undefined") {
				$(".invitation_list_viewer .message").html(message);
				$(".invitation_list_viewer .message-box").fadeIn();
			}

			$('.ui-dialog-buttonpane').css('padding', '0').css('font-size', '8pt');
			$('.ui-dialog-buttonpane .ui-dialog-buttonset').css('width', '100%');
		})
		.fail(function (){
			$('.invitation_list_viewer').html('There was an error.');
		});
    }



    function invite_add_team() {
		var n = $('#new_team').val().replace(/<\/?[^>]+(>|$)/g, "");

		if (n == '')
		{
			alert ('You must enter the name of the new team participating in this meet.');
			return false;
		}
		
		$('#new_team_state').removeAttr('disabled');

		$.ajax({
			type: "POST",
			url: "/meets/add-team",
			data: $("#new_team_form").serialize(),
			success: function(data)
			{
				console.log(data);
				populateInvitationList(data);
			}
		});

		$('.invitation_list_viewer').html("<div class='ajax_loader' style='width:16px; height:11px; margin:4em auto; background-image: url(http://www.osaa.org/images/icons/ajax_loader2.gif); background-repeat:no-repeat;'></div>");
    }





	$('#confirm_drop_dialog_meet').dialog(
	{
      autoOpen: false,
      resizable: false,
      height: 250,
      width: 400,
      modal: true,
      open: function(){
		$('.dropping_team').html($(this).attr('data-team-name'));
		$('.dropping_meet').html('<?php echo json_encode($information['event']['name']); ?>');
      },
      buttons: {
        "Yes": function() {
          	
        	var team = $(this).attr('data-team');
        	var meet = $(this).attr('data-meet');
        	var team_name = $(this).attr('data-team-name');

			$(this).dialog("close");

			$('.invitation_list_viewer').html("<div class='ajax_loader' style='width:16px; height:11px; margin:4em auto; background-image: url(http://www.osaa.org/images/icons/ajax_loader2.gif); background-repeat:no-repeat;'></div>");

			$.ajax(
			{
				type : "POST",
				url  : '<?php echo url('/meets/drop'); ?>',
				data : { 'team' : team,
						 'meet' : meet },
				success : function(data)
				{
					populateInvitationList(data);
				}
			});

			return true;
        },
        "No": function() {
          $(this).dialog( "close" );
          return false;
        }
      }
    });





	$('#confirm_delete_dialog_meet').dialog(
	{
      autoOpen: false,
      resizable: false,
      height:260,
      width: 400,
      modal: true,
      buttons: {
        "Yes": function() {
          	
        	var team = $(this).attr('data-team');
        	var meet = $(this).attr('data-meet');

			$.ajax(
			{
				type : "POST",
				url  : '<?php echo url('/meets/delete'); ?>',
				data : { 'team' : team,
						 'meet' : meet },
				success : function()
				{
					window.location.replace("/activities/<?php echo strtolower($information['activity']); ?>");
				}
			});

			$(this).dialog("close");

			return true;
        },
        "No": function() {
          $(this).dialog( "close" );
          return false;
        }
      }
    });  

	$('.button.delete[data-action="delete"]').click(function ()
	{	
		$('#confirm_delete_dialog_meet').attr('data-meet', $(this).attr('data-meet'))
										.dialog('open');
	});


<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_functions'); ?>
   	<a href="/activities/<?php echo strtolower($information['activity']); ?>" id="cancel_button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" role="button" aria-disabled="false" title="Cancel editing and do not save changes." style="font-size: 10pt;">
   		<span class="ui-button-icon-primary ui-icon ui-icon-circle-close"></span>
   		<span class="ui-button-text">Exit</span>
   	</a>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('main_content'); ?>

<h2>Edit Meet</h2>


<?php echo Form::open(array('url' => url('/meets/edit'),
				'class' => 'edit_meet',
				'id' => 'meet_adder')); ?>

	<?php if (Session::has('errors')): ?>                
        <p class="error ui-state-error"><span class="ui-icon ui-icon-alert box_icon"></span><?php foreach ($errors->all() as $error): ?><?php echo $error; ?> <?php endforeach; ?></p>
    <?php endif; ?>
	<?php if (Session::has('success')): ?>                
		<p class="ui-state-highlight"><span class="ui-icon ui-icon-check box_icon"></span><?php echo Session::get('success'); ?></p>
	<?php endif; ?>

	<?php echo Form::hidden('event_time_zone', $information['event']['time_zone'], array('style' => 'width:100px;')); ?>
	<?php echo Form::hidden('action', 'EDIT_INV'); ?>

	<?php 
		$event_start_date = strtotime($information['event']['start_at']);
		$event_end_date = strtotime($information['event']['end_at']);
		$event_date_difference = $event_end_date - $event_start_date;
		$two_day_event = false;
		$meet_date = date('m/d/Y', $event_start_date);
		$meet_time = date('h:i A', $event_start_date);
		if ($event_date_difference != "0") {
			$two_day_event = true;
		} else {
			$two_day_event = false; 
		}
		$host_team = $information['host_team_name'];
	?>

	<div class="columns">
		<div class="fourth">
			<div class="input_label">Meet Type</div><?php echo ($information['meet_type'] == "DUAL") ? "Dual" : "Invitational"; ?>
			<?php echo Form::hidden('meet_type', $information['meet_type']); ?>
		</div>
		<div class="fourth">
			<div class="input_label">Meet ID</div><?php echo $information['id']; ?>
			<?php echo Form::hidden('meet_id', $information['id']); ?>
		</div>
		<div class="fourth">
			<div class="input_label">Event ID</div><?php echo $information['event']["id"]; ?>
			<?php echo Form::hidden('event_id', $information['event']["id"]); ?>       
		</div>
		<div class="fourth">
			<br>&nbsp; 
		</div>
	</div>

	<br />

	<div class="columns">
		<div class="half">

			<?php echo Form::label('meet_name', 'Name of the Meet', array('class' => 'input_label')); ?>
		    <?php echo Form::text('meet_name', $information['event']['name'], array('style' => 'width:300px;', 'maxlength' => '50')); ?><br />
		    <p class="small gray note under_input" style="line-height: 1.25em;">
		    	Give this meet a name, like "Gibson Winter Invitational" or "Reynolds Double-Dual."  There is no need to include the invited teams in this name, because teams participating in this meet will be displayed on the schedule.
		    </p>

			<br>

			<?php echo Form::label('event_date', 'Date', array('class' => 'input_label')); ?>
			<?php echo Form::text('event_date', $meet_date, array('class' => 'team_name', 'style' => 'width:100px;')); ?>
			<br>
			<label class="small gray note under_input" for="event_date">MM/DD/YYYY</label>

			<br><br>

			<?php echo Form::label('event_time', 'Time', array('class' => 'input_label')); ?>
			<?php echo Form::text('event_time', $meet_time, array('style' => 'width:80px;')); ?> Pacific	
			<br />
			<label class="small gray note under_input" for="event_time">Leave blank or choose 12:00 AM for TBD</label>

			<br><br>

			<?php echo Form::label('multi_day_event', 'Two Day Meet', array('class' => 'input_label')); ?>
			<?php echo Form::checkbox('multi_day_event', true, $two_day_event, false, array('style' => 'position: relative; top: 2px;')); ?> <label class="small gray note" for="multi_day_event">Check if the meet extends to the next day</label>	

			<br><br>

			<?php echo Form::label('location', 'Location', array('class' => 'input_label')); ?>
			<?php $eventLocation = $information['event']['location_name']; ?>
			<?php if (empty($eventLocation)): ?> 
				<?php echo Form::text('location', $information['host_team_name'], array('style' => 'width:300px;', 'class'=>'location_autocomplete')); ?><br />
			<?php else: ?> 
				<?php echo Form::text('location', $information['event']['location_name'], array('style' => 'width:300px;', 'class'=>'location_autocomplete')); ?><br />
			<?php endif; ?>
			<p class="small gray note under_input">If the meet is not being held at the host school, enter in a location</p>

			<br>


		</div>
		<div class="half">

			<?php echo Form::label('host_team', 'Host Team', array('class' => 'input_label')); ?>
			<?php echo Form::text('host_team', $host_team, array('style' => 'width:215px;', 'class' => 'school_autocomplete')); ?>
			<br><br>

			<?php echo Form::label('host_is_oos', 'OOS', array('class' => 'input_label')); ?>
			<?php echo Form::checkbox('host_is_oos', true, $information['host_team_oos']); ?>

			<select style="width:120px;" id="state" name="state" disabled="disabled" value="<?php echo $information['host_team_state']; ?>">
				<?php
					$states = DB::select('SELECT slug, name FROM states');
					$default = "OR";
					$default = is_null($information['host_team_state']) ? $default : $information['host_team_state'];
					$default = is_null(Input::old('state')) ? $default : Input::old('state');
					foreach ($states as $s)
					{
						$name = $s->name;
						$slug = $s->slug;

						echo '<option value="' . $slug . '"';
						if ($slug == $default) echo ' selected="selected"';
						echo '>' . $name . '</option>';	                  	
					}
					echo '<option value="Other">Other</option>';
				?>
			</select>

			<br><br>
			<br><br>

			<div class="ui-corner-all" style="padding: 4.5em; margin-bottom: 0.5em; ">
				<div class="ui-icon ui-icon-info float_left"></div><b>Teams</b><br>
				Use the "Edit Invitation List" button below to change which teams are invited to this meet.

			</div>

		</div>
	</div>

    <br class="clear" />

    <div class="horizontal_divider" style="width:100%;"></div>

    <br />		

	<div style="display:inline-block; width:25px;"></div>

    <?php echo Form::button('Delete Meet',
			 array('id' => 'is_delete',
			 	   'class' => 'button delete tooltip',
			 	   'data-action' => 'delete',
			   	   'data-confirm' => 'Are you sure you want to delete this meet?<br /><br /><div class="ui-state-error" style="padding:5px;"><div class="ui-icon ui-icon-alert float_left margin-right:1em;"></div>A deleted meet will be removed from your schedule.  Once deleted, this meet cannot be recovered easily.</div>',
			   	   'title' => 'Click this button to delete this meet.  A deleted meet will be removed from your schedule.  Once deleted, this meet cannot be recovered easily.')); ?>  
    <?php echo Form::button('Edit Invitation List',
			 array('id' => 'edit_invitation_list',
			 	   'class' => 'button tooltip',
			   	   'title' => 'Click this button to open a dialog that allows you to add or remove teams from the invitation list.')); ?>  


    <div style="display:inline-block; width:25px;"></div>
     
    
    <?php echo Form::submit('Update', array('class' => 'button float_right')); ?>

    <br /><br />				

<?php echo Form::close(); ?>			

<div id="confirm_dialog" title="Confirmation"></div>

<div class="invitation_list_viewer" style="display:none;">
    <div class="ajax_loader" style="width:16px; height:11px; margin:0 auto; margin-top:6em; background-image: url('<?php echo asset('/images/icons/ajax_loader2.gif'); ?>'); background-repeat:no-repeat;"></div>
</div>

<div id="confirm_drop_dialog_meet" title="Confirm">
	<p>Do you want to drop <b style="color:#2e6e9e" class="dropping_team">Team Name Here</b> from <b style="color:#2e6e9e" class="dropping_meet">Meet Name Here</b>?</p>

	<br>
	<div class="ui-state-error" style="padding:5px;">
		<div class="ui-icon ui-icon-alert float_left margin-right:1em;"></div>
		Dropping this team will remove the team from the list of teams that are participating.
	</div>
</div>

<div id="confirm_delete_dialog_meet" title="Delete Meet?" data-meet="<?php echo $information['id']; ?>">
	Are you sure you want to delete this meet?<br /><br />
	<div class="ui-state-error" style="padding:5px;">
		<div class="ui-icon ui-icon-alert float_left margin-right:1em;"></div>
		If you delete this meet, all teams participating in this meet will have this meet removed from their schedules.
	</div>
</div>

<?php $__env->stopSection(); ?>