Class: TwitterFormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- TwitterFormBuilder
- Includes:
- ActionView::Helpers::FormTagHelper
- Defined in:
- app/helpers/twitter_form_builder.rb
Constant Summary collapse
- COLS_CLASS =
'col-md-8'
Instance Method Summary collapse
- #apply(text = I18n.t('admin.common.apply')) ⇒ Object
- #cancel ⇒ Object
- #checkbox(method, options = {}) ⇒ Object
- #ckeditor(method, options = {}) ⇒ Object
- #combobox(method, choices, options = {}, html_options = {}) ⇒ Object
- #date(method, options = {}) ⇒ Object
- #datetime(method, options = {}) ⇒ Object
- #enum(method, options = {}, html_options = {}) ⇒ Object
- #enumerize(method, options = {}, html_options = {}) ⇒ Object
- #errors ⇒ Object
- #file_upload(method) ⇒ Object
- #image_upload(method, options = {}) ⇒ Object
- #list_all_combobox(association_name, options = {}, html_options = {}) ⇒ Object
- #multi_field(relation_name, options = {}) ⇒ Object
-
#nested_fields_for(association) ⇒ Object
Editing has_many collection parameters: association - name of has_many association association should be defined as accepts_nested_attributes with allow_destroy = true in model You should create partial with name #{association)_fields.
- #password(method, options = {}) ⇒ Object
- #row(method, controls, options = {}) ⇒ Object
- #save(text = I18n.t('admin.common.save')) ⇒ Object
-
#static_memo_text(method, options = {}) ⇒ Object
Displays multi-line static text in form.
- #static_text(method, options = {}) ⇒ Object
- #string(method, options = {}) ⇒ Object
- #textarea(method, options = {}) ⇒ Object
- #time(method, options = {}) ⇒ Object
- #wysiwyg(method, options = {}) ⇒ Object
Instance Method Details
#apply(text = I18n.t('admin.common.apply')) ⇒ Object
91 92 93 |
# File 'app/helpers/twitter_form_builder.rb', line 91 def apply text = I18n.t('admin.common.apply') submit text, name: :apply, class: 'btn btn-default wymupdate' end |
#cancel ⇒ Object
95 96 97 |
# File 'app/helpers/twitter_form_builder.rb', line 95 def cancel @template.back_action end |
#checkbox(method, options = {}) ⇒ Object
57 58 59 |
# File 'app/helpers/twitter_form_builder.rb', line 57 def checkbox method, = {} row method, content_tag(:div, check_box(method, ), class: 'checkbox'), end |
#ckeditor(method, options = {}) ⇒ Object
65 66 67 |
# File 'app/helpers/twitter_form_builder.rb', line 65 def ckeditor(method, = {}) row method, cktext_area(method, ()) end |
#combobox(method, choices, options = {}, html_options = {}) ⇒ Object
36 37 38 |
# File 'app/helpers/twitter_form_builder.rb', line 36 def combobox method, choices, = {}, = {} row method, select(method, choices, , ()), div_class: .delete(:div_class) || 'col-md-6' end |
#date(method, options = {}) ⇒ Object
73 74 75 |
# File 'app/helpers/twitter_form_builder.rb', line 73 def date method, = {} string(method, ({data: {'calendar-date' => true}, div_class: 'col-md-2'}, )) end |
#datetime(method, options = {}) ⇒ Object
77 78 79 80 |
# File 'app/helpers/twitter_form_builder.rb', line 77 def datetime(method, = {}) value = object.try(method).try(:strftime, '%Y-%m-%d %H:%M') string(method, ({data: {'calendar-datetime' => true}, div_class: 'col-md-3', value: value}, )) end |
#enum(method, options = {}, html_options = {}) ⇒ Object
40 41 42 |
# File 'app/helpers/twitter_form_builder.rb', line 40 def enum(method, = {}, = {}) combobox method, object.class.send(method.to_s.pluralize).collect { |s| [s[0].humanize, s[0]] }, , end |
#enumerize(method, options = {}, html_options = {}) ⇒ Object
44 45 46 |
# File 'app/helpers/twitter_form_builder.rb', line 44 def enumerize(method, = {}, = {}) combobox method, object.class.send(method).values.collect { |s| [s.text, s] }, , end |
#errors ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/helpers/twitter_form_builder.rb', line 7 def errors return nil unless @object.errors.any? = @object.errors..collect do |msg| "<p>#{ERB::Util.h(msg)}</p>".html_safe end content_tag(:div, content_tag(:div, content_tag(:div, content_tag(:button, '×'.html_safe, class: 'close', type: 'button', :'data-dismiss' => 'alert') + .join('').html_safe, class: 'alert alert-danger'), class: 'col-md-8 col-md-offset-2'), class: 'row') end |
#file_upload(method) ⇒ Object
138 139 140 141 142 143 |
# File 'app/helpers/twitter_form_builder.rb', line 138 def file_upload method @template.render partial: '/admin/common/file_upload_template', locals: { f: self, field: method } end |
#image_upload(method, options = {}) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/helpers/twitter_form_builder.rb', line 107 def image_upload method, = {} version = [:version] uri = if version.present? @object.send("#{method}_url", version) else @object.send("#{method}_url") end if [:size] url = uri || 'placeholder' else url = uri end upload_uri = [:upload_path] unless upload_uri upload_uri = @template.admin_upload_image_path(image_class: @object.class.name.underscore, field: method) end @template.render partial: '/admin/common/image_upload_template', locals: { f: self, url: url, size: [:size], version: version || '', title: [:title] || '', text: [:text], field: method, upload_uri: upload_uri, container: [:parent_id] || upload_container_id(method), options: .delete(:options) || {}, image_style: .delete(:image_style) || '' } end |
#list_all_combobox(association_name, options = {}, html_options = {}) ⇒ Object
48 49 50 51 |
# File 'app/helpers/twitter_form_builder.rb', line 48 def list_all_combobox(association_name, = {}, = {}) collection_class = object.class.reflect_on_association(association_name).klass combobox("#{association_name}_id", collection_class.all.sort_by(&:name).map { |element| [element.name, element.id] }, {include_blank: true}.merge(), ) end |
#multi_field(relation_name, options = {}) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'app/helpers/twitter_form_builder.rb', line 145 def multi_field(relation_name, = {}) reflection = self.object.class.reflections[relation_name] || self.object.class.reflections[relation_name.to_s] = {search_field_name: :name, show_all_on_focus: false, use_cache: true, relation_model_name: reflection.klass.model_name.singular}.merge!() [:source] ||= @template.admin_autocomplete_path([:relation_model_name], [:search_field_name]) string "#{relation_name}_tokens", title: self.object.class.human_attribute_name(relation_name), data: { multi_field: true, source: [:source], pre: self.object.send("#{relation_name}_json", [:search_field_name]), show_all_on_focus: [:show_all_on_focus], use_cache: [:use_cache], object_url_name: [:object_url_name]} end |
#nested_fields_for(association) ⇒ Object
Editing has_many collection parameters: association - name of has_many association association should be defined as accepts_nested_attributes with allow_destroy = true in model You should create partial with name #{association)_fields
103 104 105 |
# File 'app/helpers/twitter_form_builder.rb', line 103 def nested_fields_for(association) @template.render 'admin/common/nested_fields_for', f: self, section_name: @object.class.human_attribute_name(association), collection: association end |
#password(method, options = {}) ⇒ Object
69 70 71 |
# File 'app/helpers/twitter_form_builder.rb', line 69 def password method, = {} row method, password_field(method, ()), end |
#row(method, controls, options = {}) ⇒ Object
162 163 164 165 166 167 168 |
# File 'app/helpers/twitter_form_builder.rb', line 162 def row(method, controls, = {}) label_class = [:label_class] || 'control-label col-md-4 col-lg-2' label_tag = label(method, [:title], class: label_class) unless [:hide_label] [:div_class] ||= COLS_CLASS div_tag = content_tag :div, controls.html_safe, class: [:div_class] content_tag :div, "#{label_tag}#{div_tag}".html_safe, class: 'form-group' end |
#save(text = I18n.t('admin.common.save')) ⇒ Object
87 88 89 |
# File 'app/helpers/twitter_form_builder.rb', line 87 def save text = I18n.t('admin.common.save') submit text, name: :save, class: 'btn btn-success wymupdate' end |
#static_memo_text(method, options = {}) ⇒ Object
Displays multi-line static text in form
28 29 30 |
# File 'app/helpers/twitter_form_builder.rb', line 28 def static_memo_text(method, = {}) row method, simple_format(@object.send(method), class: 'form-control-static'), end |
#static_text(method, options = {}) ⇒ Object
23 24 25 |
# File 'app/helpers/twitter_form_builder.rb', line 23 def static_text(method, = {}) row method, content_tag(:p, static_text_formatter.format(method), class: 'form-control-static'), end |
#string(method, options = {}) ⇒ Object
32 33 34 |
# File 'app/helpers/twitter_form_builder.rb', line 32 def string method, = {} row method, text_field(method, ()), end |
#textarea(method, options = {}) ⇒ Object
53 54 55 |
# File 'app/helpers/twitter_form_builder.rb', line 53 def textarea method, = {} row method, text_area(method, ()), end |
#time(method, options = {}) ⇒ Object
82 83 84 85 |
# File 'app/helpers/twitter_form_builder.rb', line 82 def time(method, = {}) value = object.try(method).try(:strftime, '%H:%M') string(method, ({data: {'calendar-time' => true}, div_class: 'col-md-2', value: value}, )) end |
#wysiwyg(method, options = {}) ⇒ Object
61 62 63 |
# File 'app/helpers/twitter_form_builder.rb', line 61 def wysiwyg method, = {} textarea method, (merge_classes(, 'wymeditor')) end |