Module: PhantomHelpers::ViewHelpers::LinkHelper

Defined in:
lib/phantom_helpers/view_helpers/link_helper.rb

Instance Method Summary collapse

Instance Method Details



237
238
239
240
241
242
243
244
245
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 237

def ajax_link_to_back(resource, options = {})
  name = ('<span class="glyphicon glyphicon-share-alt"></span> ' + t(:'phantom_helpers.back')).html_safe
  attributes = {
    :class => "col-xs-12 btn btn-warning back-link back-modal-link",
    :remote => true
  }.merge(options)

  link_to name, resource, attributes
end


127
128
129
130
131
132
133
134
135
136
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 127

def ajax_link_to_delete(resource, options = {})
  name = ("<span class='glyphicon glyphicon-remove'></span>").html_safe
  attributes = {
    :remote => true,
    :method => :delete,
    :data => { :confirm => t(:'phantom_helpers.are_you_sure') },
    :class => 'btn btn-xs btn-danger delete-link'
  }.merge(options)
  link_to name, resource, attributes
end


171
172
173
174
175
176
177
178
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 171

def ajax_link_to_edit(resource, options = {})
  name = ("<span class='glyphicon glyphicon-pencil'></span>").html_safe
  attributes = {
    :remote => true,
    :class => "btn btn-xs btn-warning js-edit-link"
  }.merge(options)
  link_to name, resource, attributes
end


162
163
164
165
166
167
168
169
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 162

def ajax_link_to_make_primary(resource, options = {})
  attributes = {
    :remote => true,
    :method => :post,
    :data => { :confirm => t(:'phantom_helpers.are_you_sure') },
  }.merge(options)
  link_to primary_checkbox, resource, attributes
end

needs id, because it is unique



63
64
65
66
67
68
69
70
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 63

def ajax_link_to_new(text, resource, options = {})
  name = ("<span class='glyphicon glyphicon-plus'></span> " + text).html_safe
  attributes = {
    :remote => true,
    :class => "btn btn-primary"
  }.merge(options)
  link_to name, resource, attributes
end


80
81
82
83
84
85
86
87
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 80

def ajax_link_to_recovery(resource, options = {})
  name = (:span, nil, class: 'glyphicon glyphicon-repeat')
  attributes = {
    remote: true,
    class: "btn btn-xs btn-success recovery-link"
  }.merge(options)
  link_to name, resource, attributes
end


89
90
91
92
93
94
95
96
97
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 89

def ajax_link_to_restore(resource, options = {})
  name = (:span, nil, class: 'glyphicon glyphicon-repeat')
  attributes = {
    remote: true,
    method: :patch,
    class: "btn btn-xs btn-success recovery-link"
  }.merge(options)
  link_to name, resource, attributes
end


202
203
204
205
206
207
208
209
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 202

def ajax_link_to_show(resource, options = {})
  name = ("<span class='glyphicon glyphicon-eye-open'></span>").html_safe
  attributes = {
    :remote => true,
    :class => "btn btn-xs btn-info show-link"
  }.merge(options)
  link_to name, resource, attributes
end

#ajax_soft_delete(resource, options = {}) ⇒ Object



147
148
149
150
151
152
153
154
155
156
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 147

def ajax_soft_delete(resource, options = {})
  name = ("<span class='glyphicon glyphicon-remove'></span>").html_safe
  attributes = {
    :remote => true,
    :method => :patch,
    :data => { :confirm => t(:'phantom_helpers.are_you_sure') },
    :class => 'btn btn-xs btn-danger delete-link'
  }.merge(options)
  link_to name, resource, attributes
end

#button(text, resource, options = {}) ⇒ Object



14
15
16
17
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 14

def button(text, resource, options = {})
  attributes = {:class => "btn btn-default"}.merge(options)
  link_to text, resource, attributes
end


5
6
7
8
9
10
11
12
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 5

def link_to_add_fields(name, f, association)
  new_object = f.object.send(association).klass.new
  id = new_object.object_id
  fields = f.fields_for(association, new_object, child_index: id) do |builder|
    render(association.to_s.singularize + "_fields", f: builder)
  end
  link_to(("<span class='glyphicon glyphicon-plus glyphicon-white'></span> " + name).html_safe, '#', :class => "btn btn-primary add_fields", data: {id: id, fields: fields.gsub("\n", "")})
end


247
248
249
250
251
252
253
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 247

def link_to_back(resource, options = {})
  name = ('<span class="glyphicon glyphicon-share-alt"></span> '+ t(:'phantom_helpers.back')).html_safe
  attributes = {
    :class => 'col-xs-12 btn btn-default back-link'
  }.merge(options)
  link_to name, resource, attributes
end


219
220
221
222
223
224
225
226
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 219

def link_to_cancel(options = {})
  text = ('<span class="glyphicon glyphicon-ban-circle"></span> '+ t(:'phantom_helpers.cancel')).html_safe
  attributes = {
    :class => "col-xs-12 btn btn-warning cancel-link",
    :'data-dismiss' => "modal"
  }.merge(options)
  link_to text, '#', attributes
end


99
100
101
102
103
104
105
106
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 99

def link_to_delete(resource, options = {})
  name = ("<span class='glyphicon glyphicon-remove'></span>").html_safe
  attributes = {
    :method => :delete,
    :class => 'btn btn-xs btn-danger delete-link'
  }.merge(options)
  link_to name, resource, attributes
end


108
109
110
111
112
113
114
115
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 108

def link_to_delete_with_text(resource, options = {})
  attributes = {
    :method => :delete,
    :data => {confirm: t(:'phantom_helpers.confirm_delete')},
    :class => 'btn btn-danger'
  }.merge(options)
  link_to t(:'phantom_helpers.delete'), resource, attributes
end


30
31
32
33
34
35
36
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 30

def link_to_download(resource, options = {})
  name = (:span, nil, class: 'glyphicon glyphicon-download')
  attributes = {
    class: "btn btn-xs btn-success download-link"
  }.merge(options)
  link_to name, resource, attributes
end

Edit button with only pencil image - without text



181
182
183
184
185
186
187
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 181

def link_to_edit(resource, options = {})
  name = ("<span class='glyphicon glyphicon-edit'></span>").html_safe
  attributes = {
    :class => "btn btn-xs btn-inverse edit-link",
  }.merge(options)
  link_to name, resource, attributes
end


196
197
198
199
200
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 196

def link_to_edit_with_custom_text(text, resource, options = {})
  name = ('<span class="glyphicon glyphicon-pencil"></span> '+ text).html_safe
  attributes = {:class => "col-xs-12 btn btn-warning edit-link"}.merge(options)
  link_to name, resource, attributes
end

Edit button with text "Edit" and pencil image



190
191
192
193
194
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 190

def link_to_edit_with_text(resource, options = {})
  name = ('<span class="glyphicon glyphicon-pencil"></span> '+t(:'phantom_helpers.edit')).html_safe
  attributes = {:class => "col-xs-12 btn btn-warning edit-link"}.merge(options)
  link_to name, resource, attributes
end


56
57
58
59
60
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 56

def link_to_export(text, resource, options = {})
  name = ('<span class="glyphicon glyphicon-download"></span> '+ text).html_safe
  attributes = {:class => 'btn btn-default'}.merge(options)
  link_to name, resource, attributes
end


24
25
26
27
28
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 24

def link_to_file(text, resource, options = {})
  name = ("<span class='glyphicon glyphicon-file'></span> " + text).html_safe
  attributes = {:class => "btn btn-primary"}.merge(options)
  link_to name, resource, attributes
end


50
51
52
53
54
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 50

def link_to_import(text, resource, options = {})
  name = ('<span class="glyphicon glyphicon-upload"></span> '+ text).html_safe
  attributes = {:class => 'btn btn-default'}.merge(options)
  link_to name, resource, attributes
end


255
256
257
258
259
260
261
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 255

def link_to_index(resource, options = {})
  name = ('<span class="glyphicon glyphicon-share-alt"></span> '+ t(:'phantom_helpers.index')).html_safe
  attributes = {
    :class => 'col-xs-12 btn btn-default index-link'
  }.merge(options)
  link_to name, resource, attributes
end


228
229
230
231
232
233
234
235
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 228

def link_to_modal_cancel(options = {})
  name = t(:'phantom_helpers.cancel')
  attributes = {
    :class => "col-xs-12 btn btn-warning modal-cancel-link",
    :'data-dismiss' => "modal"
  }.merge(options)
  link_to name, '#', attributes
end


138
139
140
141
142
143
144
145
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 138

def link_to_modal_delete(options = {})
  name = ("<span class='glyphicon glyphicon-trash'></span>").html_safe
  attributes = {
    :class => 'btn btn-danger modal-delete-link col-xs-12',
    :data => {:confirm => nil}
  }.merge(options)
  link_to name, nil, attributes
end

needs id



73
74
75
76
77
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 73

def link_to_new(text, resource, options = {})
  name = ("<span class='glyphicon glyphicon-plus'></span> " + text).html_safe
  attributes = {:class => "btn btn-primary"}.merge(options)
  link_to name, resource, attributes
end


263
264
265
266
267
268
269
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 263

def link_to_report(resource, options = {})
  name = ('<span class="glyphicon glyphicon-download-alt"></span> '+ t(:'phantom_helpers.report')).html_safe
  attributes = {
    :class => 'col-xs-12 btn btn-default report-link'
  }.merge(options)
  link_to name, resource, attributes
end


211
212
213
214
215
216
217
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 211

def link_to_show(resource, options = {})
  name = ("<span class='glyphicon glyphicon-eye-open'></span>").html_safe
  attributes = {
    :class => "btn btn-xs btn-info show-link"
  }.merge(options)
  link_to name, resource, attributes
end


118
119
120
121
122
123
124
125
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 118

def link_to_soft_delete_with_text(resource, options = {})
  attributes = {
    :method => :patch,
    :data => {confirm: t(:'phantom_helpers.confirm_delete')},
    :class => 'btn btn-danger'
  }.merge(options)
  link_to t(:'phantom_helpers.delete'), resource, attributes
end


44
45
46
47
48
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 44

def link_to_upload(options = {})
  text = ("<span class='glyphicon glyphicon-upload'></span> " + t(:'phantom_helpers.picture.upload')).html_safe
  attributes = {:class => "btn btn-default"}.merge(options)
  button_tag(('span', text), attributes)
end


38
39
40
41
42
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 38

def link_to_upload_image(resource, options = {})
  name = ("<span class='glyphicon glyphicon-camera'></span> " + t(:'phantom_helpers.picture.change')).html_safe
  attributes = {:class => "btn btn-default col-xs-12"}.merge(options)
  link_to name, resource, attributes
end

#manage_buttons_for(resource, options = {}) ⇒ Object



280
281
282
283
284
285
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 280

def manage_buttons_for(resource, options = {})
  id = extract_id(resource)
  concat link_to_show(resource, :id => "show-#{id}-link") unless except?(:show, options)
  concat link_to_edit [:edit] + [resource].flatten, :id => "edit-#{id}-link", :remote => true unless except?(:edit, options)
  ajax_link_to_delete resource, :id => "delete-#{id}-link" unless except?(:delete, options)
end

#primary_button(text, resource, options = {}) ⇒ Object



19
20
21
22
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 19

def primary_button(text, resource, options = {})
  attributes = {:class => "btn btn-primary"}.merge(options)
  link_to text, resource, attributes
end

#primary_checkboxObject



158
159
160
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 158

def primary_checkbox
  ("<span class='glyphicon glyphicon-ok'></span>").html_safe
end

#submit_button(text, options = {}) ⇒ Object



271
272
273
274
275
276
277
278
# File 'lib/phantom_helpers/view_helpers/link_helper.rb', line 271

def submit_button(text, options={})
  text = ('<span class="glyphicon glyphicon-ok-circle"></span> '+ text).html_safe
  attributes = {
    :type => 'submit',
    :class => 'col-xs-12 btn btn-success button'
  }.merge(options)
  button_tag(('span', text), attributes)
end