Fixed Quantity parent list display for new/edit forms
This commit is contained in:
parent
6433621fa7
commit
6e335c243a
@ -6,7 +6,7 @@ class QuantitiesController < ApplicationController
|
||||
|
||||
def index
|
||||
@quantity = @project.quantities.new
|
||||
@quantity.domain = Quantity.domains[session[:q_filters][:domain]]
|
||||
@quantity.domain = Quantity.domains[session[:q_filters][:domain]] || @quantity.domain
|
||||
prepare_quantities
|
||||
end
|
||||
|
||||
|
@ -11,9 +11,8 @@ module QuantitiesHelper
|
||||
end
|
||||
|
||||
def parent_options(domain)
|
||||
options = nested_set_options(@quantities.send(domain), @quantity) do |i|
|
||||
options = nested_set_options(@project.quantities.send(domain), @quantity) do |i|
|
||||
raw("#{' ' * i.level}#{i.name}")
|
||||
end
|
||||
options.unshift([t('.null_parent'), nil])
|
||||
end
|
||||
end
|
||||
|
@ -19,6 +19,7 @@ class Quantity < ActiveRecord::Base
|
||||
|
||||
after_initialize do
|
||||
if new_record?
|
||||
self.domain ||= :diet
|
||||
self.primary = false if self.primary.nil?
|
||||
end
|
||||
end
|
||||
|
@ -1,11 +1,12 @@
|
||||
<%= error_messages_for @quantity %>
|
||||
|
||||
<div class="box tabular">
|
||||
<p><%= f.select :domain, domain_options, required: true %></p>
|
||||
<p><%= f.select :domain, domain_options, {required: true} %></p>
|
||||
<% Quantity.domains.each_key do |d| %>
|
||||
<div id="parent_select_<%= d %>" style="display: none">
|
||||
<p><%= f.select :parent_id, parent_options(d),
|
||||
{required: true, label: :field_parent_quantity} %></p>
|
||||
<div id="parent_select_<%= d %>" <%= 'style=display:none;' if @quantity.domain != d %>>
|
||||
<p><%= f.select :parent_id, parent_options(d), {required: true,
|
||||
label: :field_parent_quantity,
|
||||
include_blank: t('.null_parent')} %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
<p><%= f.text_field :name, size: 25, required: true %></p>
|
||||
@ -17,15 +18,17 @@
|
||||
|
||||
<%= javascript_tag do %>
|
||||
function domainChange() {
|
||||
$('[id^=parent_select_]').prop('disabled', true).hide();
|
||||
$('[id^=parent_select_] select').attr('name', 'placeholder');
|
||||
$('[id=parent_select_'+$('#quantity_domain option:selected').val()+']')
|
||||
.prop('disabled', false).show();
|
||||
$('[id=parent_select_'+$('#quantity_domain option:selected').val()+'] select')
|
||||
box = $(this).closest('div');
|
||||
box.find('[id^=parent_select_]').prop('disabled', true).hide();
|
||||
box.find('[id^=parent_select_] select').attr('name', 'placeholder');
|
||||
domain = $(this).val();
|
||||
box.find('[id=parent_select_'+domain+']').prop('disabled', false).show();
|
||||
box.find('[id=parent_select_'+domain+'] select')
|
||||
.attr('name', 'quantity[parent_id]');
|
||||
}
|
||||
$('#quantity-form').on('change', '#quantity_domain', domainChange);
|
||||
$('form').on('change', '#quantity_domain', domainChange);
|
||||
|
||||
//Firefox does not emit 'change' signal when preserving form over reload
|
||||
$(document).ready(function() {
|
||||
domainChange();
|
||||
});
|
||||
|
@ -72,7 +72,8 @@
|
||||
<%=
|
||||
link_to l(:button_cancel), "#",
|
||||
onclick: '$(this).closest("tr").remove();
|
||||
$("#quantities a.icon-edit").css("visibility", "visible");'
|
||||
$("#quantities a.icon-edit").css("visibility", "visible");
|
||||
return false;'
|
||||
%>
|
||||
<% end %>
|
||||
</div>
|
||||
|
@ -14,10 +14,10 @@
|
||||
|
||||
<%= labelled_form_for @quantity,
|
||||
:url => project_quantities_path(@project),
|
||||
:html => {:id => 'quantity-form'} do |f| %>
|
||||
:html => {:id => 'quantity-add-form'} do |f| %>
|
||||
<%= render :partial => 'quantities/form', :locals => { :f => f } %>
|
||||
<%= submit_tag l(:button_create) %>
|
||||
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-quantity").hide()' %>
|
||||
<%= link_to l(:button_cancel), "#", onclick: '$("#add-quantity").hide(); return false;' %>
|
||||
<% end %>
|
||||
<hr>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user