diff --git a/app/helpers/angular_form_builder.rb b/app/helpers/angular_form_builder.rb index 3d51291cbc..8444928f91 100644 --- a/app/helpers/angular_form_builder.rb +++ b/app/helpers/angular_form_builder.rb @@ -13,19 +13,35 @@ class AngularFormBuilder < ActionView::Helpers::FormBuilder # @fields_for_record_name --> :collection # @object.send(@fields_for_record_name).first.class.to_s.underscore --> enterprise_fee - name = "#{@object_name}[#{@fields_for_record_name}_attributes][{{ $index }}][#{method}]" - id = "#{@object_name}_#{@fields_for_record_name}_attributes_{{ $index }}_#{method}" value = "{{ #{@object.send(@fields_for_record_name).first.class.to_s.underscore}.#{method} }}" - @template.text_field_tag name, value, :id => id + @template.text_field_tag angular_name(method), value, :id => angular_id(method) + end + + def angular_hidden_field(method, options = {}) + value = "{{ #{@object.send(@fields_for_record_name).first.class.to_s.underscore}.#{method} }}" + + @template.hidden_field_tag angular_name(method), value, :id => angular_id(method) end def angular_select(method, choices, angular_field, options = {}) - @template.select_tag method, @template.angular_options_for_select(choices, angular_field), options.reverse_merge!({'ng-model' => angular_field}) + options.reverse_merge!({'id' => angular_id(method)}) + + @template.select_tag angular_name(method), @template.angular_options_for_select(choices, angular_field), options end def angular_collection_select(method, collection, value_method, text_method, angular_field, options = {}) - @template.select_tag method, @template.angular_options_from_collection_for_select(collection, value_method, text_method, angular_field), options.reverse_merge!({'ng-model' => angular_field}) + options.reverse_merge!({'id' => angular_id(method)}) + + @template.select_tag angular_name(method), @template.angular_options_from_collection_for_select(collection, value_method, text_method, angular_field), options end + private + def angular_name(method) + "#{@object_name}[#{@fields_for_record_name}_attributes][{{ $index }}][#{method}]" + end + + def angular_id(method) + "#{@object_name}_#{@fields_for_record_name}_attributes_{{ $index }}_#{method}" + end end diff --git a/app/views/admin/enterprise_fees/index.html.haml b/app/views/admin/enterprise_fees/index.html.haml index 67c10480f1..0ce3168b53 100644 --- a/app/views/admin/enterprise_fees/index.html.haml +++ b/app/views/admin/enterprise_fees/index.html.haml @@ -20,28 +20,13 @@ / -- Finished product = enterprise_fee_set_form.angular_fields_for :collection do |f| %tr{'ng-repeat' => 'enterprise_fee in enterprise_fees | filter:query'} - %td= f.angular_collection_select :enterprise_id, Enterprise.all, :id, :name, 'enterprise_fee.enterprise_id', :include_blank => true + %td + = f.angular_hidden_field :id + = f.angular_collection_select :enterprise_id, Enterprise.all, :id, :name, 'enterprise_fee.enterprise_id', :include_blank => true %td= f.angular_select :fee_type, enterprise_fee_type_options, 'enterprise_fee.fee_type' %td= f.angular_text_field :name %td= f.angular_collection_select :calculator_type, @calculators, :name, :description, 'enterprise_fee.calculator_type', {:class => 'calculator_type'} %td{'ng-bind-html-unsafe' => 'enterprise_fee.calculator_settings'} %td{'spree-delete-resource' => "1"} - %tr - %td --- - - / -- Plain old Rails - = enterprise_fee_set_form.fields_for :collection do |f| - - enterprise_fee = f.object - %tr - %td= f.collection_select :enterprise_id, Enterprise.all, :id, :name, :include_blank => true - %td= f.select :fee_type, enterprise_fee_type_options - %td= f.text_field :name - %td= f.collection_select :calculator_type, @calculators, :name, :description, {}, {:class => 'calculator_type'} - %td - - if !enterprise_fee.new_record? - .calculator-settings - = f.fields_for :calculator do |calculator_form| - = preference_fields(enterprise_fee.calculator, calculator_form) - %td= link_to_delete enterprise_fee unless enterprise_fee.new_record? = enterprise_fee_set_form.submit 'Update'