Class: LoyalCore::ActionView::LabeledBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
lib/loyal_core/action_view/labeled_builder.rb

Instance Method Summary collapse

Instance Method Details

#bit_able_check_box(name, *args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/loyal_core/action_view/labeled_builder.rb', line 36

def bit_able_check_box name, *args
  result = (field_label name, *args) + @template.tag(:br)

  config = object.class.send(:"#{name}_bit_config")

  config.keys.each do |_name|
    _config = config[_name]

    if _config.value > 0
      _checkbox_options = {
        :type => :checkbox,
        :value => _config.key,
        :name => "#{name}_values[]"
      }

      if object.send(:"#{name}_bit?", _name)
        _checkbox_options[:checked] = :checked
      end

      result << (
        @template.tag :input, _checkbox_options
      )

      result << "#{_config.desc}"
    end
  end

  result
end

#error_messagesObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/loyal_core/action_view/labeled_builder.rb', line 101

def error_messages
  if object.errors.full_messages.any?
    @template.(:div, :class => 'error_messages') do
      @template. :h2, (
        "#{@template.pluralize(object.errors.count, "error")} #{I18n.t('views.form.prohibited_being_saved')}:"
      )

      @template. :ul do
        object.errors.full_messages.map do |msg|
          @template. :li, msg
        end.join.html_safe
      end
    end
  end
end

#filter_named_select(name, *args) ⇒ Object



30
31
32
33
34
# File 'lib/loyal_core/action_view/labeled_builder.rb', line 30

def filter_named_select name, *args
  (field_label name, *args) + @template.tag(:br) + select(
    name, object.class.send(:"#{name}_named_filter_config").to_select_options
  )
end

#labeled_check_box(name, *args) ⇒ Object



75
76
77
78
79
# File 'lib/loyal_core/action_view/labeled_builder.rb', line 75

def labeled_check_box(name, *args)
  @template. :div, class: 'field' do
    check_box(name, *args) + ' ' + field_label(name, *args)
  end
end

#nested_belongs_to_select(name, clazz, class_or_item, *args) ⇒ Object



97
98
99
# File 'lib/loyal_core/action_view/labeled_builder.rb', line 97

def nested_belongs_to_select name, clazz, class_or_item, *args
  impl_nested_belongs_to_select_with_mover name, nil, class_or_item, clazz, *args
end

#nested_parent_select(name, class_or_item, *args) ⇒ Object

def check_box(name, *args)

@template. :div, class: 'field' do
  super + ' ' + field_label(name, *args)
end

end



87
88
89
90
91
92
93
94
95
# File 'lib/loyal_core/action_view/labeled_builder.rb', line 87

def nested_parent_select name, class_or_item, *args
  impl_nested_belongs_to_select_with_mover name, object, class_or_item, object.class, *args

  # @template.content_tag :div, class: "field" do
  #   (field_label name, *args) + @template.tag(:br) + select(
  #     name, *([object.class.nested_set_select_options(nil, object, :include_blank => true)] + args) 
  #   )
  # end
end

#select_editor_content_mode(name, *args) ⇒ Object

选择编辑器的类型



5
6
7
8
9
10
11
12
13
14
# File 'lib/loyal_core/action_view/labeled_builder.rb', line 5

def select_editor_content_mode name, *args
  (field_label name, *args) + @template.tag(:br) + self.select(
    name,
    object.class.send(:"content_mode_config").to_select_options,
    {},
    {
      :class => 'loyal-editor-content-mode-selector'
    }
  )
end

#select_with_label(name, *args) ⇒ Object



24
25
26
27
28
# File 'lib/loyal_core/action_view/labeled_builder.rb', line 24

def select_with_label name, *args
  @template. :div, class: "field" do
    (field_label name, *args) + @template.tag(:br) + self.select(name, *args)
  end
end

#submit(value = nil, options = {}) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/loyal_core/action_view/labeled_builder.rb', line 66

def submit value=nil, options={}
  @template.submit_tag (value || I18n.t('loyal_core.action_view.form_builder.submit.default_value')),
    options.reverse_merge(
      :data => {
        :disable_with => I18n.t('loyal_core.action_view.form_builder.submit.disable_with')
      }
  )
end