Module: Spree::Admin::BaseHelper

Defined in:
app/helpers/spree/admin/base_helper.rb

Instance Method Summary collapse

Instance Method Details

#admin_hint(title, text) ⇒ Object



27
28
29
30
31
# File 'app/helpers/spree/admin/base_helper.rb', line 27

def admin_hint(title, text)
  (:span, class: 'hint-tooltip', title:, data: { content: text }) do
    (:i, '', class: 'fa fa-info-circle')
  end
end

#admin_layout(layout = nil) ⇒ Object



49
50
51
52
# File 'app/helpers/spree/admin/base_helper.rb', line 49

def admin_layout(layout = nil)
  @admin_layout = layout if layout
  @admin_layout
end

#datepicker_field_value(date, with_time: false) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/spree/admin/base_helper.rb', line 33

def datepicker_field_value(date, with_time: false)
  return if date.blank?

  format = if with_time
    t('spree.date_picker.format_with_time', default: '%Y/%m/%d %H:%M')
  else
    t('spree.date_picker.format', default: '%Y/%m/%d')
  end

  l(date, format:)
end

#error_message_on(object, method, _options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/spree/admin/base_helper.rb', line 15

def error_message_on(object, method, _options = {})
  object = convert_to_model(object)
  obj = object.respond_to?(:errors) ? object : instance_variable_get("@#{object}")

  if obj && obj.errors[method].present?
    errors = safe_join(obj.errors[method], "<br>".html_safe)
    (:span, errors, class: 'formError')
  else
    ''
  end
end

#field_container(model, method, options = {}, &block) ⇒ Object



6
7
8
9
10
11
12
13
# File 'app/helpers/spree/admin/base_helper.rb', line 6

def field_container(model, method, options = {}, &block)
  css_classes = options[:class].to_a
  css_classes << 'field'
  if error_message_on(model, method).present?
    css_classes << 'withError'
  end
  (:div, capture(&block), class: css_classes.join(' '), id: "#{model}_#{method}_field")
end

#spree_dom_id(record) ⇒ Object



45
46
47
# File 'app/helpers/spree/admin/base_helper.rb', line 45

def spree_dom_id(record)
  dom_id(record, 'spree')
end