<%= form_tag({:controller => "wkexchangerate", :action => 'update', :tab => 'wkexchangerate'}, :method => :get, :id => 'query_form') do %>
<% wkexpense_helper = Object.new.extend(WkexpenseHelper) %>
<table class="list" id="commit-keywords">
  <thead>
    <tr>
	<th></th>
      <th><%= l(:label_from_currency) %></th>
      <th><%= l(:label_to_currency) %></th>
      <th><%= l(:label_exchange_rate) %></th>
      <th class="buttons"></th>
    </tr>
  </thead>
  <tbody>
	<% unless @curentry.blank? %>
		<% @curentry.each do |entry| %>
			<tr class="commit-keywords">
				<td>
					<%= hidden_field_tag "exrate_id[]",  entry.id  %>
				</td>
			  <td>
				<%=h select_tag("from_currency[]",options_for_select(wkexpense_helper.options_for_currency,:selected => entry.from_c), :style => "width:200px;", :required => true) %>
			  </td>
			  <td>
				<%=h select_tag("to_currency[]",options_for_select(wkexpense_helper.options_for_currency,:selected => entry.to_c), :style => "width:200px;", :required => true) %>
			  </td>
			   <td>
				<%= text_field_tag("rate[]", entry.ex_rate, :id => nil, :style => "width:200px;", :required => true) %>
			  </td>      
			 
			  <td class="buttons">
				<%= link_to(l(:button_delete), '#',
							:class => 'delete-commit-keywords icon-only icon-del',
							:title => l(:button_delete)) %>
			  </td>
			</tr>
		<% end %>
	<% else %>
		<tr class="commit-keywords">
		<td>
			<%= hidden_field_tag "exrate_id[]",  ""  %>
		</td>
		  <td>
			<%=h select_tag("from_currency[]",options_for_select(wkexpense_helper.options_for_currency,:selected => ''), :style => "width:200px;", :required => true) %>
		 </td>
		  <td>
			<%=h select_tag("to_currency[]",options_for_select(wkexpense_helper.options_for_currency,:selected => ''), :style => "width:200px;", :required => true) %>
		 </td>
		  <td>
			<%= text_field_tag("rate[]",
							   '', :id => nil, :size => 30, :required => true) %>
		  </td>
		<td class="buttons">
				<%= link_to(l(:button_delete), '#',
							:class => 'delete-commit-keywords icon-only icon-del',
							:title => l(:button_delete)) %>
			  </td>
		</tr>
	<% end %>
    <tr>
      <td></td>
	  <td></td>
      <td></td>
      <td></td>
      <td class="buttons">
        <%= link_to(l(:button_add), '#',
                    :class => 'add-commit-keywords icon-only icon-add',
                    :title => l(:button_add)) %>
      </td>
    </tr>
  </tbody>
</table>
<span class="pagination"><%= pagination_links_full @entry_pages, @entry_count %></span>
<p><%= submit_tag l(:button_save) %></p>
<% 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 %>
