Module: Tenon::TenonHelper

Defined in:
app/helpers/tenon/tenon_helper.rb

Instance Method Summary collapse

Instance Method Details

default tenon action link



15
16
17
18
19
# File 'app/helpers/tenon/tenon_helper.rb', line 15

def action_link(title, link, icon, options = {})
  icon_tag = (:i, '', class: "fa fa-#{icon} fa-fw")
  default_options = { title: title, data: { tooltip: title } }
  link_to icon_tag, link, default_options.deep_merge(options)
end

#browser_detection(http) ⇒ Object

browser detection and warning message



58
59
60
61
62
# File 'app/helpers/tenon/tenon_helper.rb', line 58

def browser_detection(http)
  if http.match(/MSIE 6|MSIE 7|MSIE 8.0/)
    (:div, "For an optimal Tenon experience, please upgrade Internet Explorer to the #{link_to 'latest version', 'http://browsehappy.com/', target: '_blank'} or switch to another #{link_to 'modern browser', 'http://browsehappy.com/', target: '_blank'}.".html_safe, id: 'flash-warning', class: 'flash-msg')
  end
end

default tenon delete link



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/tenon/tenon_helper.rb', line 44

def delete_link(obj, options = {})
  if policy(obj).destroy?
    default_options = { data: {
      confirm: 'Are you sure? There is no undo for this!',
      tooltip: 'Delete',
      method: 'Delete',
      remote: 'true'
    } }
    url = polymorphic_url(obj)
    action_link('Delete', url, 'trash-o', default_options.deep_merge(options))
  end
end

#display_action(action) ⇒ Object



8
9
10
11
12
# File 'app/helpers/tenon/tenon_helper.rb', line 8

def display_action(action)
  action = 'edit' if action == 'update'
  action = 'new' if action == 'create'
  action.titleize.humanize
end

#display_controller(controller) ⇒ Object



3
4
5
6
# File 'app/helpers/tenon/tenon_helper.rb', line 3

def display_controller(controller)
  controller = controller.split('/')[1] if controller.match('/')
  controller.humanize.titleize
end

default tenon edit link



36
37
38
39
40
41
# File 'app/helpers/tenon/tenon_helper.rb', line 36

def edit_link(obj, options = {})
  if policy(obj).edit?
    url = polymorphic_url([:edit] + Array(obj))
    action_link('Edit', url, 'pencil', options)
  end
end

#form_header_for(obj, opts = {}) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'app/helpers/tenon/tenon_helper.rb', line 70

def form_header_for(obj, opts = {})
  label = opts.fetch(:label, obj.class.name.demodulize.titleize)
  label = label.gsub(/\s+Decorator$/, '')
  if obj.persisted?
    "Edit #{label}"
  else
    "Create a New #{label}"
  end
end

#i18n_language_nav(table) ⇒ Object



64
65
66
67
68
# File 'app/helpers/tenon/tenon_helper.rb', line 64

def i18n_language_nav(table)
  if Tenon.config.languages && I18nLookup.fields[:tables][table]
    render 'tenon/shared/i18n_language_nav'
  end
end

extention of action_link for boolean toggles



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/tenon/tenon_helper.rb', line 22

def toggle_link(object, field, link, true_values, false_values)
  state = object.send(field)
  icon = state ? true_values[0] : false_values[0]
  tooltip = state ? true_values[1] : false_values[1]
  data = {
    trueicon:     true_values[0],
    falseicon:    false_values[0],
    truetooltip:  true_values[1],
    falsetooltip: false_values[1]
  }
  action_link tooltip, link, icon, class: "toggle #{field} #{state}", data: data
end