Module: AlternateValuesHelper

Defined in:
app/helpers/alternate_values_helper.rb

Instance Method Summary (collapse)

Instance Method Details



55
56
57
58
59
60
# File 'app/helpers/alternate_values_helper.rb', line 55

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

- (Object) alternate_value_annotation_tag(alternate_value)



12
13
14
15
# File 'app/helpers/alternate_values_helper.rb', line 12

def alternate_value_annotation_tag(alternate_value)
  return nil if alternate_value.nil?
  (:span, alternate_value_string(alternate_value), class: [:annotation__alternate_value])
end


71
72
73
74
# File 'app/helpers/alternate_values_helper.rb', line 71

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.metamorphosize)
end

- (Object) alternate_value_string(alternate_value)



8
9
10
# File 'app/helpers/alternate_values_helper.rb', line 8

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

- (Object) alternate_value_tag(alternate_value)



3
4
5
6
# 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), " (on '#{alternate_value.alternate_value_object_attribute}') ('#{alternate_value.project_id.nil? ? "public" : "project only"}')"].join(' ')
end

- (String (html)?) alternate_values_list_tag(object)

Returns a ul/li of alternate_values for the object

Returns:

  • (String (html), nil)

    a ul/li of alternate_values for the object



19
20
21
22
23
24
25
# File 'app/helpers/alternate_values_helper.rb', line 19

def alternate_values_list_tag(object)
  return nil unless object.has_alternate_values? && object.alternate_values.any?
  (:h3, 'Alternate values') +
    (:ul, class: 'annotations__alternate_value_list') do
    object.alternate_values.collect { |a| (:li, alternate_value_annotation_tag(a)) }.join.html_safe
  end
end

- (True) alternate_values_recent_objects_partial

Returns indicates a custom partial should be used, see list_helper.rb

Returns:

  • (True)

    indicates a custom partial should be used, see list_helper.rb



82
83
84
# File 'app/helpers/alternate_values_helper.rb', line 82

def alternate_values_recent_objects_partial
  true 
end

- (Object) alternate_values_search_form



76
77
78
# File 'app/helpers/alternate_values_helper.rb', line 76

def alternate_values_search_form
  render('/alternate_values/quick_search_form')
end


67
68
69
# File 'app/helpers/alternate_values_helper.rb', line 67

def destroy_alternate_value_link(alternate_value)
  destroy_object_link(alternate_value)
end


62
63
64
65
# File 'app/helpers/alternate_values_helper.rb', line 62

def edit_alternate_value_link(alternate_value)
  edit_object_link(alternate_value)
  # link_to('Edit', edit_alternate_value_path(alternate_value))
end


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/alternate_values_helper.rb', line 37

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


29
30
31
# File 'app/helpers/alternate_values_helper.rb', line 29

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


33
34
35
# File 'app/helpers/alternate_values_helper.rb', line 33

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