Module: Agilibox::ButtonHelper

Included in:
AllHelpers
Defined in:
app/helpers/agilibox/button_helper.rb

Instance Method Summary collapse

Instance Method Details

#bs_button(url, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/agilibox/button_helper.rb', line 2

def bs_button(url, options = {})
  action = options.delete(:action)
  icon   = options.delete(:icon)
  text   = options.delete(:text) || ta(action)
  title  = options.delete(:title) || text

  text   = %(#{icon icon} <span class="text">#{text}</span>).html_safe

  options = {
    :class => "btn btn-xs btn-default link_#{action}",
    :title => title,
  }.deep_merge(options)

  if (confirm = options.delete(:confirm))
    confirm = t("actions.confirm") if confirm == true

    options.deep_merge!(
      :data => {
        :confirm => confirm,
      },
    )
  end

  link_to(text, url, options)
end

#complete_button(url, options = {}) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
# File 'app/helpers/agilibox/button_helper.rb', line 125

def complete_button(url, options = {})
  options = {
    :icon    => :check,
    :action  => :complete,
    :class   => "btn btn-xs btn-success link_complete",
    :confirm => true,
    :method  => :patch,
  }.merge(options)

  bs_button(url, options)
end

#copy_button(url, options = {}) ⇒ Object



116
117
118
119
120
121
122
123
# File 'app/helpers/agilibox/button_helper.rb', line 116

def copy_button(url, options = {})
  options = {
    :icon    => :copy,
    :action  => :copy,
  }.merge(options)

  bs_button(url, options)
end

#create_button(url, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'app/helpers/agilibox/button_helper.rb', line 39

def create_button(url, options = {})
  options = {
    :icon   => :plus,
    :action => :create,
    :class  =>"btn btn-xs btn-success link_create",
  }.merge(options)

  bs_button(url, options)
end

#delete_button(url, options = {}) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
# File 'app/helpers/agilibox/button_helper.rb', line 104

def delete_button(url, options = {})
  options = {
    :icon    => :trash,
    :action  => :delete,
    :class   => "btn btn-xs btn-danger link_delete",
    :confirm => true,
    :method  => :delete,
  }.merge(options)

  bs_button(url, options)
end

#download_button(url, options = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'app/helpers/agilibox/button_helper.rb', line 58

def download_button(url, options = {})
  options = {
    :icon     => :cloud_download_alt,
    :action   => :download,
    :download => File.basename(url),
    :target   => "_blank",
  }.merge(options)

  bs_button(url, options)
end

#export_button(url, options = {}) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/helpers/agilibox/button_helper.rb', line 69

def export_button(url, options = {})
  ext = url.split(".").last

  if ext.length <= 4
    action = :"export_#{ext}"
  else
    action = :export
  end

  options = {
    :icon     => :download,
    :action   => action,
  }.merge(options)

  download_button(url, options)
end

#import_button(url, options = {}) ⇒ Object



86
87
88
89
90
91
92
93
# File 'app/helpers/agilibox/button_helper.rb', line 86

def import_button(url, options = {})
  options = {
    :icon     => :upload,
    :action   => :import,
  }.merge(options)

  bs_button(url, options)
end

#lock_button(url, options = {}) ⇒ Object



148
149
150
151
152
153
154
155
156
157
# File 'app/helpers/agilibox/button_helper.rb', line 148

def lock_button(url, options = {})
  options = {
    :icon    => :lock,
    :action  => :lock,
    :confirm => true,
    :method  => :patch,
  }.merge(options)

  bs_button(url, options)
end


28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/agilibox/button_helper.rb', line 28

def print_button(options = {})
  options = {
    :icon    => :print,
    :action  => :print,
    :class   => "btn btn-xs btn-default",
    :onclick => "print(); return false;",
  }.merge(options)

  bs_button("#", options)
end

#read_button(url, options = {}) ⇒ Object



49
50
51
52
53
54
55
56
# File 'app/helpers/agilibox/button_helper.rb', line 49

def read_button(url, options = {})
  options = {
    :icon   => :info_circle,
    :action => :read,
  }.merge(options)

  bs_button(url, options)
end

#snooze_button(url, options = {}) ⇒ Object



137
138
139
140
141
142
143
144
145
146
# File 'app/helpers/agilibox/button_helper.rb', line 137

def snooze_button(url, options = {})
  options = {
    :icon    => :clock,
    :action  => :snooze,
    :confirm => true,
    :method  => :patch,
  }.merge(options)

  bs_button(url, options)
end

#unlock_button(url, options = {}) ⇒ Object



159
160
161
162
163
164
165
166
167
168
# File 'app/helpers/agilibox/button_helper.rb', line 159

def unlock_button(url, options = {})
  options = {
    :icon    => :unlock,
    :action  => :unlock,
    :confirm => true,
    :method  => :patch,
  }.merge(options)

  bs_button(url, options)
end

#update_button(url, options = {}) ⇒ Object



95
96
97
98
99
100
101
102
# File 'app/helpers/agilibox/button_helper.rb', line 95

def update_button(url, options = {})
  options = {
    :icon   => :pencil_alt,
    :action => :update,
  }.merge(options)

  bs_button(url, options)
end