Module: Spree::Admin::PaymentMethodsHelper
- Defined in:
- app/helpers/spree/admin/payment_methods_helper.rb
Instance Method Summary collapse
- #basic_braintree_preference_keys ⇒ Object
- #braintree_advanced_preference_fields(object, form) ⇒ Object
- #braintree_basic_preference_fields(object, form) ⇒ Object
- #get_preference_fields(object, keys, form) ⇒ Object
- #preference_field_for(form, field, options) ⇒ Object
- #preference_field_tag(name, value, options) ⇒ Object
- #preference_fields(object, form) ⇒ Object
Instance Method Details
#basic_braintree_preference_keys ⇒ Object
102 103 104 |
# File 'app/helpers/spree/admin/payment_methods_helper.rb', line 102 def basic_braintree_preference_keys %i[merchant_id public_key private_key server test_mode] end |
#braintree_advanced_preference_fields(object, form) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'app/helpers/spree/admin/payment_methods_helper.rb', line 73 def braintree_advanced_preference_fields(object, form) return unless object.respond_to?(:preferences) keys = object.preferences.keys.reverse - basic_braintree_preference_keys keys_left, keys_right = keys.each_slice((keys.size / 2.0).ceil).to_a content_tag(:div, get_preference_fields(object, keys_left, form), class: 'col-md-6') + content_tag(:div, get_preference_fields(object, keys_right, form), class: 'col-md-6') end |
#braintree_basic_preference_fields(object, form) ⇒ Object
66 67 68 69 70 71 |
# File 'app/helpers/spree/admin/payment_methods_helper.rb', line 66 def braintree_basic_preference_fields(object, form) return unless object.respond_to?(:preferences) keys = object.preferences.slice(*basic_braintree_preference_keys).keys get_preference_fields(object, keys, form) end |
#get_preference_fields(object, keys, form) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/helpers/spree/admin/payment_methods_helper.rb', line 83 def get_preference_fields(object, keys, form) keys.reject { |k| k == :currency_merchant_accounts }.map do |key| next unless object.has_preference?(key) if object.preference_type(key) == :boolean content_tag(:div, preference_field_for(form, "preferred_#{key}", type: object.preference_type(key)) + form.label("preferred_#{key}", Spree.t(key), class: 'form-check-label'), class: 'form-group form-check', id: [object.class.to_s.parameterize, 'preference', key].join('-')) else content_tag(:div, class: 'form-group', 'data-hook' => "preferred_#{key}") do form.label("preferred_#{key}", Spree.t(key) + ': ') + preference_field_for(form, "preferred_#{key}", type: object.preference_type(key), values: object.send("preferred_#{key}_default").is_a?(Hash) ? object.send("preferred_#{key}_default")[:values] : nil, selected: object.preferences[key]) end end end.join(' ').html_safe end |
#preference_field_for(form, field, options) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/helpers/spree/admin/payment_methods_helper.rb', line 4 def preference_field_for(form, field, ) case [:type] when :integer form.text_field(field, ()) when :boolean form.check_box(field, ()) when :string if field.eql?('preferred_descriptor_name') content_tag(:div, Spree.t('descriptor_name_information_box_text').html_safe, class: 'alert alert-warning' ) end.to_s.html_safe + form.text_field(field, ()) when :password form.password_field(field, ()) when :text form.text_area(field, ()) when :boolean_select label_tag(field, Spree.t(field)) form.select(field, { Spree.t(:enabled) => true, Spree.t(:disabled) => false }, {}, class: 'select2') when :select label_tag(field, Spree.t(field)) form.select(field, ([:values].map { |key| [I18n.t(key, scope: 'braintree.preferences'), key] }, [:selected]), {}, class: 'select2') else form.text_field(field, ()) end end |
#preference_field_tag(name, value, options) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/spree/admin/payment_methods_helper.rb', line 38 def preference_field_tag(name, value, ) case [:type] when :integer text_field_tag(name, value, ()) when :boolean hidden_field_tag(name, 0, id: "#{name}_hidden") + check_box_tag(name, 1, value, ()) when :string text_field_tag(name, value, ()) when :password password_field_tag(name, value, ()) when :text text_area_tag(name, value, ()) when :boolean_select select_tag(name, value, ()) when :select select_tag(name, value, ()) else text_field_tag(name, value, ()) end end |
#preference_fields(object, form) ⇒ Object
60 61 62 63 64 |
# File 'app/helpers/spree/admin/payment_methods_helper.rb', line 60 def preference_fields(object, form) return unless object.respond_to?(:preferences) get_preference_fields(object, object.preferences.keys, form) end |