Module: CoreLinkHelper

Defined in:
app/helpers/core_link_helper.rb

Overview

common link generation helpers

Instance Method Summary collapse

Instance Method Details

Show a list of things if the condition is true.



212
213
214
215
216
217
218
219
220
221
222
# File 'app/helpers/core_link_helper.rb', line 212

def action_link_tag(condition, path, options = {})
  return unless condition

  data = {}
  confirmation_data(options, data)
  link_classes = tooltip_data(options, data)
  (:a, href: path, class: link_classes.join(' '), data: data) do
    concat(materialize_icon(icon_name(options, 'directions_run'), options))
    concat(options[:label]) if options[:label].present?
  end
end

#action_list_tag(condition, path, options = {}) ⇒ Object

Show a list of things in a pull down list if the condition is true



199
200
201
202
203
204
205
206
207
# File 'app/helpers/core_link_helper.rb', line 199

def action_list_tag(condition, path, options = {})
  return unless condition

  raise('Label Required') if options[:label].blank?

  (:li) do
    action_link_tag(condition, path, options)
  end
end

Add the ‘Add` button



399
400
401
402
403
404
405
406
407
408
409
# File 'app/helpers/core_link_helper.rb', line 399

def add_link_button(path, options)
  options[:title] ||= t('ui_form.actions.add')
  options[:icon] ||= 'add'
  (:a,
              href: path,
              class: 'btn-floating btn-large right',
              style: 'padding: 0;margin: 0px 15px',
              title: options[:title]) do
    concat((:i, class: 'material-icons') { options[:icon] })
  end
end

Add a thingy



388
389
390
391
392
393
394
# File 'app/helpers/core_link_helper.rb', line 388

def add_link_tag(klass, path, options = {})
  return unless can?(:create, klass)

  (:div, class: 'fixed-action-btn horizontal') do
    concat(add_link_button(path, options))
  end
end

#confirmation_data(options, data, default = nil) ⇒ Object

See if there is any confirmation and add it to the data element



446
447
448
449
# File 'app/helpers/core_link_helper.rb', line 446

def confirmation_data(options, data, default = nil)
  confirm = options[:confirm] || options[:confirmation] || default
  data[:confirm] = confirm if confirm.present?
end

#copy_tag(copy_text, options = {}) ⇒ Object

Setup the text as copy text



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

def copy_tag(copy_text, options = {})
  secure = options[:secure] || false
  display_text = secure ? mask_value(copy_text) : copy_text
  (:div, class: 'clipboard') do
    concat((:span) { display_text })
    concat(copy_text_tag(copy_text, options))
    concat(download_tag(options[:download_url], options)) if options[:download_url].present?
  end
end

#copy_text_tag(copy_text, options = {}) ⇒ Object

Create a text element that is easy to copy



32
33
34
35
36
37
38
39
# File 'app/helpers/core_link_helper.rb', line 32

def copy_text_tag(copy_text, options = {})
  options[:icon_name] ||= 'content_copy'
  (:a, class: 'copy', href: '#', data: { 'clipboard-text' => copy_text }, onclick: 'return false;') do
    concat((:i, class: 'material-icons') do
      options[:icon_name]
    end)
  end
end

Create a thingy



282
283
284
285
286
287
288
289
290
291
292
# File 'app/helpers/core_link_helper.rb', line 282

def create_link_tag(obj, path, options = {})
  return unless can? :create, obj

  data = {}
  confirmation_data(options, data, t('links.creation_confirmation', name: obj.class.to_s.underscore.humanize))
  link_classes = tooltip_data(options, data)
  (:a, href: path, class: link_classes, data: data) do
    concat(materialize_icon(icon_name(options, 'add'), options))
    concat(options[:label]) if options[:label].present?
  end
end

#create_list_tag(obj, path, options = {}) ⇒ Object

Create a thingy in a pull-down list



270
271
272
273
274
275
276
277
# File 'app/helpers/core_link_helper.rb', line 270

def create_list_tag(obj, path, options = {})
  return unless can? :create, obj

  options[:label] ||= I18n.t('ui_form.actions.create')
  (:li) do
    create_link_tag(obj, path, options)
  end
end

#delete_button_tag(obj, path, options = {}) ⇒ Object

Delete an thingy



254
255
256
257
258
259
260
261
262
263
264
265
# File 'app/helpers/core_link_helper.rb', line 254

def delete_button_tag(obj, path, options = {})
  return unless can? :destroy, obj

  data = { method: :delete }
  confirmation_data(options, data, t('links.deletion_confirmation', name: obj.class.to_s.underscore.humanize))
  link_classes = tooltip_data(options, data)
  %w[btn red].each { |c| link_classes << c unless link_classes.include?(c) }
  (:a, class: link_classes, href: path, data: data) do
    concat(materialize_icon(icon_name(options, 'delete'), options))
    concat(options[:label]) if options[:label].present?
  end
end

Delete an thingy



239
240
241
242
243
244
245
246
247
248
249
# File 'app/helpers/core_link_helper.rb', line 239

def delete_link_tag(obj, path, options = {})
  return unless can? :destroy, obj

  data = { method: :delete }
  confirmation_data(options, data, t('links.deletion_confirmation', name: obj.class.to_s.underscore.humanize))
  link_classes = tooltip_data(options, data, I18n.t('ui_form.actions.delete'))
  (:a, href: path, class: link_classes, data: data) do
    concat(materialize_icon(icon_name(options, 'delete'), options))
    concat(options[:label]) if options[:label].present?
  end
end

#delete_list_tag(obj, path, options = {}) ⇒ Object

Delete a thingy in a pull down list



227
228
229
230
231
232
233
234
# File 'app/helpers/core_link_helper.rb', line 227

def delete_list_tag(obj, path, options = {})
  return unless can? :destroy, obj

  options[:label] ||= I18n.t('ui_form.actions.delete')
  (:li) do
    delete_link_tag(obj, path, options)
  end
end

Demote a publishable kb object



361
362
363
364
365
366
367
368
369
370
# File 'app/helpers/core_link_helper.rb', line 361

def demote_link_tag(obj, path, options = {})
  return unless can? :demote, obj

  (:a, href: path) do
    concat((:i, class: 'material-icons') do
      'file_download'
    end)
    concat(options[:label]) if options[:label].present?
  end
end

#demote_list_tag(obj, path, options = {}) ⇒ Object

Demote a publishable kb object in a pull down list



349
350
351
352
353
354
355
356
# File 'app/helpers/core_link_helper.rb', line 349

def demote_list_tag(obj, path, options = {})
  return unless can? :demote, obj

  options[:label] ||= I18n.t('links.demote')
  (:li) do
    demote_link_tag(obj, path, options)
  end
end

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

Generate a download link with the download icon



10
11
12
13
14
# File 'app/helpers/core_link_helper.rb', line 10

def download_tag(url, options = {})
  (:a, href: url) do
    concat(materialize_icon(options[:download_icon_name] || 'cloud_download'))
  end
end

Edit a page



375
376
377
378
379
380
381
382
383
# File 'app/helpers/core_link_helper.rb', line 375

def edit_class_link_tag(klass, path)
  return unless can?(:edit, klass)

  (:div, class: 'fixed-action-btn horizontal') do
    concat((:a, href: path, class: 'btn-floating btn-large right', style: 'padding: 0;margin: 0px 15px') do
      concat((:i, class: 'material-icons') { 'edit' })
    end)
  end
end

Edit a thingy



107
108
109
110
111
112
113
114
115
116
# File 'app/helpers/core_link_helper.rb', line 107

def edit_link_tag(obj, path, options = {})
  return unless can? :edit, obj

  data = {}
  link_classes = tooltip_data(options, data, 'Edit')
  (:a, href: path, class: link_classes.join(' '), data: data) do
    concat(materialize_icon(icon_name(options, 'edit'), options))
    concat(options[:label]) if options[:label].present?
  end
end

#edit_list_tag(obj, path, options = {}) ⇒ Object

Edit a thingy in a pull down list



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

def edit_list_tag(obj, path, options = {})
  return unless can? :edit, obj

  options[:label] ||= I18n.t('ui_form.actions.edit')
  (:li) do
    edit_link_tag(obj, path, options)
  end
end

#edit_modal_tag(obj, path, _options = {}) ⇒ Object



118
119
120
121
122
123
124
# File 'app/helpers/core_link_helper.rb', line 118

def edit_modal_tag(obj, path, _options = {})
  return unless can? :edit, obj

  (:a, href: path, class: 'modal-action') do
    concat(I18n.t('ui_form.actions.edit'))
  end
end

#favorite_tag(favorite, options = {}) ⇒ Object

Add a favorite tag



57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/core_link_helper.rb', line 57

def favorite_tag(favorite, options = {})
  data = {}
  link_classes = tooltip_data(options, data, I18n.t('ui_form.actions.favorite'))
  link_classes += %w[material-icons pointer favorite]
  (:i,
              class: link_classes.join(' '),
              data: data,
              id: favorite.id.to_s,
              type: favorite.favorite_type) { concat(icon_name(options, 'favorite_border')) }
end

#form_cancel_button_tag(path, name = 'cancel') ⇒ Object

Form cancel button



414
415
416
417
418
419
# File 'app/helpers/core_link_helper.rb', line 414

def form_cancel_button_tag(path, name = 'cancel')
  options = { class: 'btn-large waves-effect waves-light secondary', href: path }
  (:a, options) do
    concat(t("ui_form.actions.#{name}"))
  end
end

#form_submit_button_tag(condition = true, options = {}) ⇒ Object

Form submit button



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'app/helpers/core_link_helper.rb', line 424

def form_submit_button_tag(condition = true, options = {})
  return unless condition

  tag_options = { class: 'btn-large waves-effect waves-light', type: :submit }
  if options[:action].present?
    tag_options[:name] = options[:name] || 'button_action'
    tag_options[:value] = options[:action]
  end
  tag_options[:class] += ' disabled' if options[:disabled]
  tag_options[:class] += ' disabled' if options[:disabled]

  button_text = options[:text] || t('ui_form.actions.save')
  button_icon = options[:icon] || 'save'
  (:button, tag_options) do
    concat(button_text)
    concat((:i, class: 'material-icons right') { button_icon })
  end
end

#icon_name(options, default = nil) ⇒ Object



461
462
463
# File 'app/helpers/core_link_helper.rb', line 461

def icon_name(options, default = nil)
  options[:icon] || options[:icon_name] || default
end

Details of a thingy



184
185
186
187
188
189
190
191
192
193
194
# File 'app/helpers/core_link_helper.rb', line 184

def info_link_tag(obj, path, options = {})
  return unless can? :read, obj

  data = {}
  confirmation_data(options, data)
  link_classes = tooltip_data(options, data)
  (:a, href: path, class: link_classes, data: data) do
    concat(materialize_icon(icon_name(options, 'info'), options))
    concat(options[:label]) if options[:label].present?
  end
end

#info_list_tag(obj, path, options = {}) ⇒ Object

Details of a thingy in a pull down list



174
175
176
177
178
179
# File 'app/helpers/core_link_helper.rb', line 174

def info_list_tag(obj, path, options = {})
  options[:label] ||= I18n.t('ui_form.actions.info')
  (:li) do
    info_link_tag(obj, path, options)
  end
end

Generic link tag



82
83
84
85
86
87
88
89
90
# File 'app/helpers/core_link_helper.rb', line 82

def link_tag(title, path, options = {})
  data = {}
  link_classes = tooltip_data(options, data)
  confirmation_data(options, data)
  (:a, href: path, class: link_classes, data: data) do
    concat(materialize_icon(icon_name(options), options))
    concat(title)
  end
end

#materialize_icon(name, options = {}) ⇒ Object

Add a material icon by name



71
72
73
74
75
76
77
# File 'app/helpers/core_link_helper.rb', line 71

def materialize_icon(name, options = {})
  return if name.blank?

  classes = %w[material-icons]
  classes += options[:classes] if options[:classes].present?
  (:i, class: classes.join(' '), title: options[:title]) { name }
end

Send notification



309
310
311
312
313
314
315
316
317
318
# File 'app/helpers/core_link_helper.rb', line 309

def notification_link_tag(obj, path, options = {})
  return unless can? :manage, obj

  (:a, href: path) do
    concat((:i, class: 'material-icons') do
      options[:icon_name] || 'email'
    end)
    concat(options[:label]) if options[:label].present?
  end
end

#notification_list_tag(obj, path, options = {}) ⇒ Object

Send notification in a pull down list



297
298
299
300
301
302
303
304
# File 'app/helpers/core_link_helper.rb', line 297

def notification_list_tag(obj, path, options = {})
  return unless can? :manage, obj

  options[:label] ||= I18n.t('customer_account_users.index.reset_password')
  (:li) do
    notification_link_tag(obj, path, options)
  end
end

Promote a publishable kb object



335
336
337
338
339
340
341
342
343
344
# File 'app/helpers/core_link_helper.rb', line 335

def promote_link_tag(obj, path, options = {})
  return unless can? :promote, obj

  (:a, href: path) do
    concat((:i, class: 'material-icons') do
      'file_upload'
    end)
    concat(options[:label]) if options[:label].present?
  end
end

#promote_list_tag(obj, path, options = {}) ⇒ Object

Promote a publishable kb object in a pull down list



323
324
325
326
327
328
329
330
# File 'app/helpers/core_link_helper.rb', line 323

def promote_list_tag(obj, path, options = {})
  return unless can? :promote, obj

  options[:label] ||= I18n.t('links.promote')
  (:li) do
    promote_link_tag(obj, path, options)
  end
end

#replay_button_tag(obj, path, options = {}) ⇒ Object

Restart a thingy



157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'app/helpers/core_link_helper.rb', line 157

def replay_button_tag(obj, path, options = {})
  return unless can? :edit, obj

  data = {}
  options[:icon_name] ||= 'replay'
  confirmation_data(options, data, t('links.replay_confirmation', name: obj.class.to_s.underscore.humanize))
  link_classes = tooltip_data(options, data)
  link_classes << 'btn' unless link_classes.include?('btn')
  (:a, href: path, data: data, class: link_classes) do
    concat(materialize_icon(icon_name(options), options))
    concat(options[:label]) if options[:label].present?
  end
end

Restart a thingy



129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/helpers/core_link_helper.rb', line 129

def replay_link_tag(obj, path, options = {})
  return unless can? :edit, obj

  data = {}
  options[:icon_name] ||= 'replay'
  confirmation_data(options, data, t('links.replay_confirmation', name: obj.class.to_s.underscore.humanize))
  link_classes = tooltip_data(options, data)
  (:a, href: path, data: data, class: link_classes.join(' ')) do
    concat(materialize_icon(icon_name(options), options))
    concat(options[:label]) if options[:label].present?
  end
end

#replay_list_tag(obj, path, options = {}) ⇒ Object

Restart a thingy



145
146
147
148
149
150
151
152
# File 'app/helpers/core_link_helper.rb', line 145

def replay_list_tag(obj, path, options = {})
  return unless can? :edit, obj

  options[:label] ||= I18n.t('ui_form.actions.replay')
  (:li) do
    replay_link_tag(obj, path, options)
  end
end

#table_action_button(action_id, icon_name = 'more_horiz') ⇒ Object

Add the table action button and setup the drop down



44
45
46
47
48
49
50
51
52
# File 'app/helpers/core_link_helper.rb', line 44

def table_action_button(action_id, icon_name = 'more_horiz')
  datum = { target: action_id,
            constrainWidth: false,
            gutter: 28,
            alignment: 'right' }
  (:a, class: 'dropdown-trigger', data: datum) do
    concat(materialize_icon(icon_name))
  end
end

#tooltip_data(options, data, default = nil) ⇒ Object



451
452
453
454
455
456
457
458
459
# File 'app/helpers/core_link_helper.rb', line 451

def tooltip_data(options, data, default = nil)
  link_classes = Array.wrap(options[:link_classes]) || []
  tooltip = options[:tooltip] || default
  if tooltip.present?
    link_classes << 'tooltipped'
    data[:tooltip] = tooltip
  end
  link_classes
end