Module: AlternateValuesHelper
- Defined in:
- app/helpers/alternate_values_helper.rb
Instance Method Summary collapse
- #add_alternate_value_link(object: nil, attribute: nil) ⇒ Object
- #alternate_value_annotation_tag(alternate_value) ⇒ Object
- #alternate_value_link(alternate_value) ⇒ Object
- #alternate_value_string(alternate_value) ⇒ Object
- #alternate_value_tag(alternate_value) ⇒ Object
-
#alternate_values_list_tag(object) ⇒ String (html)?
A ul/li of alternate_values for the object.
-
#alternate_values_recent_objects_partial ⇒ True
Indicates a custom partial should be used, see list_helper.rb.
- #alternate_values_search_form ⇒ Object
- #destroy_alternate_value_link(alternate_value) ⇒ Object
- #edit_alternate_value_link(alternate_value) ⇒ Object
- #link_to_add_alternate_value(link_text, f) ⇒ Object
- #link_to_destroy_alternate_value(link_text, alternate_value) ⇒ Object
- #link_to_edit_alternate_value(link_text, alternate_value) ⇒ Object
Instance Method Details
#add_alternate_value_link(object: nil, attribute: nil) ⇒ Object
59 60 61 62 63 64 |
# File 'app/helpers/alternate_values_helper.rb', line 59 def add_alternate_value_link(object: nil, attribute: nil) link_to('Add alternate value', new_alternate_value_path( alternate_value: {alternate_value_object_type: object.class.base_class.name, alternate_value_object_id: object.id, alternate_value_object_attribute: attribute})) if object.has_alternate_values? end |
#alternate_value_annotation_tag(alternate_value) ⇒ Object
19 20 21 22 |
# File 'app/helpers/alternate_values_helper.rb', line 19 def alternate_value_annotation_tag(alternate_value) return nil if alternate_value.nil? content_tag(:span, alternate_value_string(alternate_value), class: [:annotation__alternate_value]) end |
#alternate_value_link(alternate_value) ⇒ Object
75 76 77 78 |
# File 'app/helpers/alternate_values_helper.rb', line 75 def alternate_value_link(alternate_value) return nil if alternate_value.nil? link_to(alternate_value_tag(alternate_value).html_safe, alternate_value.annotated_object.) end |
#alternate_value_string(alternate_value) ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/helpers/alternate_values_helper.rb', line 11 def alternate_value_string(alternate_value) ["\"#{alternate_value.value}\" ", alternate_value.klass_name, ' of ', # "#{alternate_value.alternate_value_object_attribute}", " \"#{alternate_value.original_value}\""].join end |
#alternate_value_tag(alternate_value) ⇒ Object
3 4 5 6 7 8 9 |
# File 'app/helpers/alternate_values_helper.rb', line 3 def alternate_value_tag(alternate_value) return nil if alternate_value.nil? [ alternate_value_string(alternate_value), tag.span("on '#{alternate_value.alternate_value_object_attribute}'", class: [:feedback, 'feedback-thin', 'feedback-secondary']), tag.span((alternate_value.project_id.nil? ? 'public' : 'project only'), class: [:feedback, 'feedback-thin', 'feedback-warning']) ].join(' ').html_safe end |
#alternate_values_list_tag(object) ⇒ String (html)?
Returns a ul/li of alternate_values for the object.
26 27 28 29 30 31 32 |
# File 'app/helpers/alternate_values_helper.rb', line 26 def alternate_values_list_tag(object) return nil unless object.has_alternate_values? && object.alternate_values.any? content_tag(:h3, 'Alternate values') + content_tag(:ul, class: 'annotations__alternate_value_list') do object.alternate_values.collect { |a| content_tag(:li, alternate_value_annotation_tag(a)) }.join.html_safe end end |
#alternate_values_recent_objects_partial ⇒ True
Returns indicates a custom partial should be used, see list_helper.rb.
86 87 88 |
# File 'app/helpers/alternate_values_helper.rb', line 86 def alternate_values_recent_objects_partial true end |
#alternate_values_search_form ⇒ Object
80 81 82 |
# File 'app/helpers/alternate_values_helper.rb', line 80 def alternate_values_search_form render('/alternate_values/quick_search_form') end |
#destroy_alternate_value_link(alternate_value) ⇒ Object
71 72 73 |
# File 'app/helpers/alternate_values_helper.rb', line 71 def destroy_alternate_value_link(alternate_value) destroy_object_link(alternate_value) end |
#edit_alternate_value_link(alternate_value) ⇒ Object
66 67 68 69 |
# File 'app/helpers/alternate_values_helper.rb', line 66 def edit_alternate_value_link(alternate_value) edit_object_link(alternate_value) # link_to('Edit', edit_alternate_value_path(alternate_value)) end |
#link_to_add_alternate_value(link_text, f) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/alternate_values_helper.rb', line 42 def link_to_add_alternate_value(link_text, f) new_object = f.object.class.reflect_on_association(:alternate_values) .klass.new({alternate_value_object_type: f.object.class.base_class.name, alternate_value_object_id: f.object.id, alternate_value_object_attribute: 'name'}) if f.object.alternate_values.any? fields = f.fields_for(:alternate_values, new_object, child_index: 'new_alternate_values') do |builder| render('alternate_values/alternate_value_fields', avf: builder) end else fields = nil end link_to(link_text, '', class: 'alternate-value-add', association: 'alternate_values', content: "#{fields}") end |
#link_to_destroy_alternate_value(link_text, alternate_value) ⇒ Object
34 35 36 |
# File 'app/helpers/alternate_values_helper.rb', line 34 def link_to_destroy_alternate_value(link_text, alternate_value) link_to(link_text, '', class: 'alternate-value-destroy', alternate_value_id: alternate_value.id) end |
#link_to_edit_alternate_value(link_text, alternate_value) ⇒ Object
38 39 40 |
# File 'app/helpers/alternate_values_helper.rb', line 38 def link_to_edit_alternate_value(link_text, alternate_value) link_to(link_text, '', class: 'alternate-value-edit', alternate_value_id: alternate_value.id) end |