Merge pull request #29 from finnlabs/feature/fix-rate-form-enter-keypress

Feature/fix rate form enter keypress
pull/6827/head
sschu 12 years ago
commit 9e32a4420d
  1. 51
      app/assets/javascripts/costs/rates.js
  2. 4
      app/views/cost_types/_list_deleted.html.erb
  3. 2
      app/views/cost_types/_rate.html.erb
  4. 1
      app/views/cost_types/edit.html.erb
  5. 2
      app/views/hourly_rates/_rate.html.erb
  6. 1
      app/views/hourly_rates/edit.html.erb

@ -1,30 +1,29 @@
function addRate(date_field) {
var my_date = date_field.value;
var date_elements = $(RatesForm.parentElement).select('input.date');
function addRate(date_field){
RatesForm.add_on_top();
var highest_date = null;
for (var e in date_elements) {
if (e.value > my_date) {
highest_date = e;
} else {
break;
}
}
var newRateRow = $(RatesForm.parentElement).down("tr");
var validFromField = newRateRow.down('input.date')
validFromField.value = jQuery.datepicker.formatDate('yy-mm-dd', new Date());
newRateRow.down('td.currency').down('input').select();
}
switch (highest_date) {
case null:
RatesForm.add_on_top()
var e = $(RatesForm.parentElement).down("tr");
break;
default:
var after = highest_date.up('tr');
RatesForm.add_after(after);
var e = after.next();
break;
}
function disableEnterKey(event){
if (event.keyCode == 13) event.preventDefault();
}
var new_date_field = e.down('input.date')
new_date_field.value = date_field.value;
date_field.value = "";
e.down('td.currency').down('input').select();
function deleteRow(image){
var row = image.up("tr")
var parent=row.up();
row.remove();
recalculate_even_odd(parent);
}
jQuery(function(jQuery){
jQuery(document).on("keydown", "body.action-edit input", function(event){
disableEnterKey(event);
});
jQuery(document).on("click", "body.action-edit img.delete", function(){
deleteRow(this);
});
});

@ -6,8 +6,8 @@
<table class="list cost_types deleted_cost_types">
<thead><tr>
<%= sort_header_tag "name", :caption => CostType.model_name.human %>
<%= sort_header_tag "unit", :caption => l(:caption_cost_type_unit_name) %>
<%= sort_header_tag "unit_plural", :caption => l(:caption_cost_type_unit_name_plural) %>
<%= sort_header_tag "unit", :caption => CostType.human_attribute_name(:unit) %>
<%= sort_header_tag "unit_plural", :caption => CostType.human_attribute_name(:unit_plural) %>
<th><%= CostType.human_attribute_name(:current_rate) %></th>
<th><%= l(:caption_locked_on) %></th>
<th></th>

@ -23,6 +23,6 @@
<label class="hidden-for-sighted", for="<%= "#{id_prefix}_rate" %>"><%= Rate.model_name.human %></label>
<%= rate_form.text_field :rate, :size => 7, :index => id_or_index, :value => rate.rate ? rate.rate.round(2) : "" %> <%= Setting.plugin_openproject_costs['costs_currency'] %>
</td>
<td><%= image_to_function 'delete.png', "var e = $('#{id_prefix}');parent=e.up();e.remove();recalculate_even_odd(parent)", {:alt => l(:button_delete), :title => l(:button_delete)}%></td>
<td><%= image_tag 'delete.png', :alt => l(:button_delete), :title => l(:button_delete), :class => 'delete' %></td>
</tr>
<% end %>

@ -42,7 +42,6 @@
<div>
<div>
<label class="hidden-for-sighted", for="add_rate_date" %>"><%= l(:description_date_for_new_rate) %></label>
<%= text_field_tag :add_rate_date, "", :size => 10, :value => Date.today %><%= calendar_for("add_rate_date") %>
<%= link_to_function l(:button_add_rate), "addRate($('add_rate_date'))", {:class => "icon icon-add"} %>
</div>
<div><%= submit_tag l(:button_save) %></div>

@ -23,6 +23,6 @@
<label class="hidden-for-sighted", for="<%= "#{id_prefix}_rate" %>"><%= Rate.model_name.human %></label>
<%= rate_form.text_field :rate, :size => 7, :index => id_or_index, :value => rate.rate ? rate.rate.round(2) : "" %> <%= Setting.plugin_openproject_costs['costs_currency'] %>
</td>
<td><%= image_to_function 'delete.png', "var e = $('#{id_prefix}');parent=e.up();e.remove();recalculate_even_odd(parent)", :alt => l(:button_delete) %></td>
<td><%= image_tag 'delete.png', :alt => l(:button_delete), :title => l(:button_delete), :class => "delete" %></td>
</tr>
<% end %>

@ -28,7 +28,6 @@
<div>
<div>
<label class="hidden-for-sighted", for="add_rate_date" %>"><%= l(:description_date_for_new_rate) %></label>
<%= text_field_tag :add_rate_date, "", :size => 10, :value => Date.today %><%= calendar_for("add_rate_date") %>
<%= link_to_function l(:button_add_rate), "addRate($('add_rate_date'))", {:class => "icon icon-add"} %>
</div>
<div><%= submit_tag l(:button_save) %></div>

Loading…
Cancel
Save