<div class="span12">
	<div class="page-header">
	  <h3>Create In Duty</h3>
	</div>
	<div class="col-md-3">
		<%= simple_form_for([:origami,@in_duty]) do |f| %>
		<div class="card">
			<div class="body">
				<%= f.error_notification %>
				  <div class="form-inputs">
				     <label>Dining Name:</label>
				    <%= @table.name %>
				    <br/>
				    <br/>

				    <label>Commissioner Name:</label>
				    <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %><br/><br/>
				    <label>In time</label>
				         <%= f.text_field :in_time, :value=>Time.current.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker"%><br/>
				     <label>Out time</label>
				         <%= f.text_field :out_time, :value=>Time.current.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker"%>
				  </div><br>
				  <div class="form-actions">
					  <div class='row'>
					    <div class="col-md-2">
					    <%= link_to 'Back', origami_index_in_duty_path(@table.id), class: 'btn bg-default' %>
					    </div>
					    <div class="col-md-10">
					    <button type="button" class="btn bg-blue btn-block" id='in_duty'>Create In Duty</button>
					    </div>
					  </div>
				  </div>
			</div>
		</div>
		<% end %>
	</div>
</div>


<script type="text/javascript">

$(function() {
    $('.datepicker').datepicker({
        format : 'dd-mm-yyyy',
        autoclose: true
    });
    $('.datepicker').attr('ReadOnly','true');
    $('.datepicker').css('cursor','pointer');
});

 $('#in_duty').on('click', function () {
        var ajax_url = "/origami/assign_in_duty";
        var commissioner_ids = $('#in_duty_commissioner_ids').val();
        var in_time = $('#in_duty_in_time').val();
        var out_time = $('#in_duty_out_time').val();
        var dining_id = '<%= @table.id %>';
        var sale_id = '<%= @sale_id %>';
        var booking_id = '<%= @booking_id %>';
        $.ajax({
            type: "POST",
            url: ajax_url,
            data: 'dining_id=' + dining_id + "sale_id=" + sale_id + "booking_id=" + booking_id + "&commissioner_ids=" + commissioner_ids +'&in_time=' + in_time + "&out_time=" + out_time,
            success: function (result) {
                window.location.href = '/origami/assign_in_duty/'+ dining_id;
            }
        });
    })

</script>
