mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-06 22:36:07 +00:00
Change angular_ prefix to ng_
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
class AngularFormBuilder < ActionView::Helpers::FormBuilder
|
||||
# TODO: Use ng_ prefix, like ng_fields_for
|
||||
|
||||
def angular_fields_for(record_name, *args, &block)
|
||||
raise "Nested angular_fields_for is not yet supported" if @fields_for_record_name.present?
|
||||
def ng_fields_for(record_name, *args, &block)
|
||||
raise "Nested ng_fields_for is not yet supported" if @fields_for_record_name.present?
|
||||
@fields_for_record_name = record_name
|
||||
block.call self
|
||||
@fields_for_record_name = nil
|
||||
end
|
||||
|
||||
def angular_text_field(method, options = {})
|
||||
def ng_text_field(method, options = {})
|
||||
# @object_name --> "enterprise_fee_set"
|
||||
# @fields_for_record_name --> :collection
|
||||
# @object.send(@fields_for_record_name).first.class.to_s.underscore --> enterprise_fee
|
||||
@@ -18,22 +16,22 @@ class AngularFormBuilder < ActionView::Helpers::FormBuilder
|
||||
@template.text_field_tag angular_name(method), value, :id => angular_id(method)
|
||||
end
|
||||
|
||||
def angular_hidden_field(method, options = {})
|
||||
def ng_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 = {})
|
||||
def ng_select(method, choices, angular_field, options = {})
|
||||
options.reverse_merge!({'id' => angular_id(method)})
|
||||
|
||||
@template.select_tag angular_name(method), @template.angular_options_for_select(choices, angular_field), options
|
||||
@template.select_tag angular_name(method), @template.ng_options_for_select(choices, angular_field), options
|
||||
end
|
||||
|
||||
def angular_collection_select(method, collection, value_method, text_method, angular_field, options = {})
|
||||
def ng_collection_select(method, collection, value_method, text_method, angular_field, options = {})
|
||||
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
|
||||
@template.select_tag angular_name(method), @template.ng_options_from_collection_for_select(collection, value_method, text_method, angular_field), options
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module AngularFormHelper
|
||||
def angular_options_for_select(container, angular_field=nil)
|
||||
def ng_options_for_select(container, angular_field=nil)
|
||||
return container if String === container
|
||||
|
||||
container.map do |element|
|
||||
@@ -10,12 +10,12 @@ module AngularFormHelper
|
||||
end.join("\n").html_safe
|
||||
end
|
||||
|
||||
def angular_options_from_collection_for_select(collection, value_method, text_method, angular_field)
|
||||
def ng_options_from_collection_for_select(collection, value_method, text_method, angular_field)
|
||||
options = collection.map do |element|
|
||||
[element.send(text_method), element.send(value_method)]
|
||||
end
|
||||
|
||||
angular_options_for_select(options, angular_field)
|
||||
ng_options_for_select(options, angular_field)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ module ApplicationHelper
|
||||
end
|
||||
|
||||
|
||||
def angular_form_for(name, *args, &block)
|
||||
def ng_form_for(name, *args, &block)
|
||||
options = args.extract_options!
|
||||
|
||||
form_for(name, *(args << options.merge(:builder => AngularFormBuilder)), &block)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
= angular_form_for @enterprise_fee_set, :url => main_app.bulk_update_admin_enterprise_fees_path, :html => {'ng-app' => 'enterprise_fees', 'ng-controller' => 'AdminEnterpriseFeesCtrl'} do |enterprise_fee_set_form|
|
||||
= ng_form_for @enterprise_fee_set, :url => main_app.bulk_update_admin_enterprise_fees_path, :html => {'ng-app' => 'enterprise_fees', 'ng-controller' => 'AdminEnterpriseFeesCtrl'} do |enterprise_fee_set_form|
|
||||
- if @enterprise_fee_set.errors.present?
|
||||
%h2 Errors
|
||||
%ul
|
||||
@@ -17,14 +17,14 @@
|
||||
%th Calculator values
|
||||
%th
|
||||
%tbody
|
||||
= enterprise_fee_set_form.angular_fields_for :collection do |f|
|
||||
= enterprise_fee_set_form.ng_fields_for :collection do |f|
|
||||
%tr{'ng-repeat' => 'enterprise_fee in enterprise_fees | filter:query'}
|
||||
%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', 'ng-model' => 'calculatorType', 'spree-ensure-calculator-preferences-match-type' => "1"}
|
||||
= f.ng_hidden_field :id
|
||||
= f.ng_collection_select :enterprise_id, Enterprise.all, :id, :name, 'enterprise_fee.enterprise_id', :include_blank => true
|
||||
%td= f.ng_select :fee_type, enterprise_fee_type_options, 'enterprise_fee.fee_type'
|
||||
%td= f.ng_text_field :name
|
||||
%td= f.ng_collection_select :calculator_type, @calculators, :name, :description, 'enterprise_fee.calculator_type', {'class' => 'calculator_type', 'ng-model' => 'calculatorType', 'spree-ensure-calculator-preferences-match-type' => "1"}
|
||||
%td{'ng-bind-html-unsafe-compiled' => 'enterprise_fee.calculator_settings'}
|
||||
%td{'spree-delete-resource' => "1"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user