Module: Workbench::TableHelper

Defined in:
app/helpers/workbench/table_helper.rb

Overview

Helpers for table rendering

Instance Method Summary collapse

Instance Method Details

#copy_table_to_clipboard(selector) ⇒ Object



49
50
51
# File 'app/helpers/workbench/table_helper.rb', line 49

def copy_table_to_clipboard(selector)
  (:button, 'Copy to clipboard', data: { 'clipboard-table-selector': selector }, type: 'button')
end

#fancy_edit_tag(object) ⇒ Object



39
40
41
# File 'app/helpers/workbench/table_helper.rb', line 39

def fancy_edit_tag(object)
  (:td, edit_object_link(object), class: 'table-options', data: {edit: true}) 
end

#fancy_metadata_cells_tag(object) ⇒ Object

Hidden action links data-attributes:

data-show
data-edit
data-delete

This is very important, it must be set to make work the options for the context menu. Use the class “.table-options” to hide those options on the table



19
20
21
22
23
# File 'app/helpers/workbench/table_helper.rb', line 19

def (object)
  (:td, object_tag(object.updater)) +
    (:td, object_time_since_update_tag(object)) +
    fancy_options_cells_tag(object)
end

#fancy_options_cells_tag(object) ⇒ Object



25
26
27
28
29
30
31
# File 'app/helpers/workbench/table_helper.rb', line 25

def fancy_options_cells_tag(object)
  m = metamorphosize_if(object)
    fancy_show_tag(m) +
    fancy_edit_tag(m) + 
    fancy_pin_tag(m) +
    (:td, (link_to 'Destroy', m, method: :delete, data: {confirm: 'Are you sure?'}), class: 'table-options', data: {delete: true})
end

#fancy_pin_tag(object) ⇒ Object



43
44
45
46
47
# File 'app/helpers/workbench/table_helper.rb', line 43

def fancy_pin_tag(object)
  if object.respond_to?(:pinned?)
    (:td, pin_item_to_pinboard_link(object, sessions_current_user), class: 'table-options', data: {pin: true})
  end
end

#fancy_show_tag(object) ⇒ Object



33
34
35
36
37
# File 'app/helpers/workbench/table_helper.rb', line 33

def fancy_show_tag(object)
  defined?(object.annotated_object) ? 
    (:td, (link_to 'Show', metamorphosize_if(object.annotated_object)), class: 'table-options', data: {show: true}) :
    (:td, (link_to 'Show', object), class: 'table-options', data: {show: true})
end

#fancy_th_tag(group: nil, name: '') ⇒ Object



4
5
6
7
8
# File 'app/helpers/workbench/table_helper.rb', line 4

def fancy_th_tag(group: nil, name: '')
  (:th, data: {group: group}) do
    (:span, name)
  end
end