Module: LinksHelper

Includes:
Jabysoft::AuthorisationService
Defined in:
app/helpers/links_helper.rb

Instance Method Summary collapse

Methods included from Jabysoft::AuthorisationService

#authorise_link

Instance Method Details



57
58
59
60
# File 'app/helpers/links_helper.rb', line 57

def link_to_back(url, html_options = {})
  html_options.reverse_merge!(class: 'btn btn-default btn-lg')
  link_to t('back'), url, html_options
end


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

def link_to_destroy(model, url, html_options = {})
  style = 'btn btn-danger glyphicon glyphicon-trash'
  resource_id = html_options[:resource_id].presence
  html_options.reverse_merge!({"data-target" => "#delete-confirmation#{resource_id}", "data-toggle" => "modal"})
  authorise_link(:destroy, model: model, style: style, options: html_options) do |authorised|
    if authorised
      link_to '', url, html_options
    else
      (:div, class: 'tooltip-wrapper', "data-title" => I18n.t('not_authorized')) do
        link_to t('destroy'), url, html_options
      end
    end
  end
end


16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/links_helper.rb', line 16

def link_to_edit(model, url, html_options = {})
  authorise_link(:update, model: model, 
    style: 'btn btn-default glyphicon glyphicon-pencil', options: html_options) do |authorised|
    if authorised
      link_to '', url, html_options
    else
      (:div, class: 'tooltip-wrapper', "data-title" => I18n.t('not_authorized')) do
        link_to t('edit'), url, html_options
      end
    end
  end
end


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

def link_to_menu(model, url)
  link_to model.model_name.human.pluralize, url
end


4
5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/links_helper.rb', line 4

def link_to_new(model, url, html_options = {})
  authorise_link(:create, model: model, style: 'btn btn-primary btn-lg', options: html_options) do |authorised|
    if authorised
      link_to t('new', model: model.model_name.human), url, html_options
    else
      (:div, class: 'tooltip-wrapper', "data-title" => I18n.t('not_authorized')) do
        link_to t('new', model: model.model_name.human), url, html_options
      end
    end
  end
end


29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/links_helper.rb', line 29

def link_to_show(model, url, html_options = {})
  style = 'btn btn-default glyphicon glyphicon-zoom-in'
  authorise_link(:show, model: model, style: style, options: html_options) do |authorised|
    if authorised
      link_to '', url, html_options
    else
      (:div, class: 'tooltip-wrapper', "data-title" => I18n.t('not_authorized')) do
        link_to t('show'), url, html_options
      end
    end
  end
end

#submit_button(form, value = nil) ⇒ Object



74
75
76
77
78
79
80
# File 'app/helpers/links_helper.rb', line 74

def submit_button(form, value = nil)
  if value
    form.submit value, class: "btn btn-primary btn-lg"
  else
    form.submit t('save'), class: "btn btn-primary btn-lg"
  end
end

#submit_or_edit_button(form, edit_path, is_edition) ⇒ Object



66
67
68
69
70
71
72
# File 'app/helpers/links_helper.rb', line 66

def submit_or_edit_button(form, edit_path, is_edition)
  if is_edition && params[:action] != 'new'
    link_to_edit form.object, edit_path, class: "btn btn-primary glyphicon glyphicon-pencil"
  else
    submit_button(form)
  end
end