<%= form_tag({:controller => "wkpublicholiday", :action => 'update', :tab => 'wkpublicholiday'}, :method => :post, :id => 'query_form') do %>
	<% actualIds = "" %>

	<table class="list" id="commit-keywords">
		<thead>
			<tr>
			<th></th>
			<th><%= l(:label_date) %></th>
			<th><%= l(:field_location) %></th>
			<!-- <th><%#= l(:field_department) %></th> -->
			<th><%= l(:label_wk_description) %></th>
			<th class="buttons"></th>
			</tr>
		</thead>
		<tbody>
		<% unless @phEntry.blank? %>
			<% @phEntry.each do |entry| %>
				<tr class="commit-keywords">
					<td>
						<%= hidden_field_tag "ph_id[]",  entry.id  %>
						<% actualIds = actualIds.blank? ? entry.id.to_s  : (actualIds + "," + entry.id.to_s) %>
					</td>
						<td>
						<%= date_field_tag('holiday_date[]', entry.holiday_date, :required => true, :style => "width:150px;", :disabled => !validateERPPermission('A_ATTEND')) %><%= calendar_for('holiday_date[]') %>
						</td>
					<td>
						<%=h select_tag("location_id[]", generic_options_for_select(WkLocation, nil, 'name', 'name', 'id', entry.location_id.nil? ? "" : entry.location_id , true), :style => "width:150px;", :disabled => !validateERPPermission('A_ATTEND') ) %>
					</td>
					<!--
					<td>
						<%#=h select_tag('department_id[]', options_for_select(options_for_enum_select('DP', entry.department_id, true)), :style => "width:120px;") %>
					</td> -->
						<td>
						<%= text_field_tag "description[]",  entry.description, :style => "width:150px;", :required => true, :disabled => !validateERPPermission('A_ATTEND')  %>
					</td>
					<% if validateERPPermission('A_ATTEND') %>
						<td class="buttons">

								<%= link_to(l(:button_delete), '#',
									:class => 'delete-commit-keywords icon-only icon-del',
									:title => l(:button_delete)) %>

						</td>
					<% end %>
				</tr>
			<% end %>
		<% else %>
			<% if validateERPPermission('A_ATTEND') %>
				<tr class="commit-keywords">
					<td>
						<%= hidden_field_tag "ph_id[]",  ""  %>
					</td>
					<td>
						<%= date_field_tag('holiday_date[]',Date.today.to_s, :style => "width:150px;", :required => true) %><%= calendar_for('holiday_date[]') %>
					</td>
					<td>
						<%=h select_tag("location_id[]", generic_options_for_select(WkLocation, nil, 'name', 'name', 'id', nil, true), :style => "width:150px;") %>
					</td>
					<!--
					<td>
						<%#=h select_tag('department_id[]', options_for_select(options_for_enum_select('DP', nil, true)), :style => "width:150px;") %>
					</td>
					-->
					<td>
						<%=
						text_field_tag "description[]",  ""  , :required => true, :style => "width:150px;"  %>
					</td>
						<td class="buttons">
							<%= link_to(l(:button_delete), '#',
										:class => 'delete-commit-keywords icon-only icon-del',
										:title => l(:button_delete)) %>
						</td>
				</tr>
			<% end %>
		<% end %>
			<tr>
				<td></td>
			<td></td>

			<td></td>
				<td></td>
				<% if validateERPPermission('A_ATTEND') %>
					<td class="buttons">
						<%= link_to(l(:button_add), '#',
												:class => 'add-commit-keywords icon-only icon-add',
												:title => l(:button_add)) %>
					</td>
				<% end %>
			</tr>
		</tbody>
	</table>
	<%= hidden_field_tag "actual_ids",  actualIds  %>
	<% if validateERPPermission('A_ATTEND') %>
		<p><%= submit_tag l(:button_save) %></p>
	<% end %>
<% end %>

<%= javascript_tag do %>
$('#commit-keywords').on('click', 'a.delete-commit-keywords', function(e){
  e.preventDefault();
  if ($('#commit-keywords tbody tr.commit-keywords').length > 1) {
    $(this).parents('#commit-keywords tr').remove();
  } else {
    $('#commit-keywords tbody tr.commit-keywords').find('input, select').val('');
  }
});
$('#commit-keywords').on('click', 'a.add-commit-keywords', function(e){
  e.preventDefault();
  var row = $('#commit-keywords tr.commit-keywords:last');
  row.clone().insertAfter(row).find('input, select').val('');
});
<% end %>