Module: EffectiveDatatablesHelper
- Defined in:
- app/helpers/effective_datatables_helper.rb
Overview
These are expected to be called by a developer. They are part of the datatables DSL.
Instance Method Summary collapse
- #approve_icon_to(path, options = {}) ⇒ Object
- #archive_icon_to(path, options = {}) ⇒ Object
-
#datatables_active_admin_path? ⇒ Boolean
TODO: Improve on this.
- #datatables_admin_path? ⇒ Boolean
- #destroy_icon_to(path, options = {}) ⇒ Object
- #edit_icon_to(path, options = {}) ⇒ Object
- #glyphicon_to(icon, path, options = {}) ⇒ Object (also: #bootstrap_icon_to, #glyph_icon_to)
- #ok_icon_to(path, options = {}) ⇒ Object
- #remove_icon_to(path, options = {}) ⇒ Object
- #render_datatable(datatable, input_js_options = nil) ⇒ Object
- #render_datatable_chart(datatable, name) ⇒ Object
- #render_datatable_charts(datatable) ⇒ Object
- #render_datatable_scopes(datatable) ⇒ Object
- #render_simple_datatable(datatable, input_js_options = nil) ⇒ Object
- #settings_icon_to(path, options = {}) ⇒ Object
-
#show_icon_to(path, options = {}) ⇒ Object
Icon Helpers for actions_column or elsewhere.
- #unarchive_icon_to(path, options = {}) ⇒ Object
Instance Method Details
#approve_icon_to(path, options = {}) ⇒ Object
112 113 114 |
# File 'app/helpers/effective_datatables_helper.rb', line 112 def approve_icon_to(path, = {}) glyphicon_to('ok', path, {title: 'Approve'}.merge()) end |
#archive_icon_to(path, options = {}) ⇒ Object
94 95 96 97 |
# File 'app/helpers/effective_datatables_helper.rb', line 94 def archive_icon_to(path, = {}) defaults = {title: 'Archive', data: {method: :delete, confirm: 'Archive this item?'}} glyphicon_to('trash', path, defaults.merge()) end |
#datatables_active_admin_path? ⇒ Boolean
TODO: Improve on this
76 77 78 |
# File 'app/helpers/effective_datatables_helper.rb', line 76 def datatables_active_admin_path? attributes[:active_admin_path] rescue false end |
#datatables_admin_path? ⇒ Boolean
67 68 69 70 71 72 73 |
# File 'app/helpers/effective_datatables_helper.rb', line 67 def datatables_admin_path? @datatables_admin_path ||= ( path = request.path.to_s.downcase.chomp('/') + '/' referer = request.referer.to_s.downcase.chomp('/') + '/' (attributes[:admin_path] || referer.include?('/admin/') || path.include?('/admin/')) rescue false ) end |
#destroy_icon_to(path, options = {}) ⇒ Object
89 90 91 92 |
# File 'app/helpers/effective_datatables_helper.rb', line 89 def destroy_icon_to(path, = {}) defaults = {title: 'Destroy', data: {method: :delete, confirm: 'Delete this item?'}} glyphicon_to('trash', path, defaults.merge()) end |
#edit_icon_to(path, options = {}) ⇒ Object
85 86 87 |
# File 'app/helpers/effective_datatables_helper.rb', line 85 def edit_icon_to(path, = {}) glyphicon_to('edit', path, {title: 'Edit'}.merge()) end |
#glyphicon_to(icon, path, options = {}) ⇒ Object Also known as: bootstrap_icon_to, glyph_icon_to
120 121 122 123 124 125 126 127 128 |
# File 'app/helpers/effective_datatables_helper.rb', line 120 def glyphicon_to(icon, path, = {}) content_tag(:a, .merge(href: path)) do if icon.start_with?('glyphicon-') content_tag(:span, '', class: "glyphicon #{icon}") else content_tag(:span, '', class: "glyphicon glyphicon-#{icon}") end end end |
#ok_icon_to(path, options = {}) ⇒ Object
108 109 110 |
# File 'app/helpers/effective_datatables_helper.rb', line 108 def ok_icon_to(path, = {}) glyphicon_to('ok', path, {title: 'OK'}.merge()) end |
#remove_icon_to(path, options = {}) ⇒ Object
116 117 118 |
# File 'app/helpers/effective_datatables_helper.rb', line 116 def remove_icon_to(path, = {}) glyphicon_to('remove', path, {title: 'Remove'}.merge()) end |
#render_datatable(datatable, input_js_options = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/helpers/effective_datatables_helper.rb', line 4 def render_datatable(datatable, = nil) raise 'expected datatable to be present' unless datatable datatable.view ||= self begin EffectiveDatatables.(controller, :index, datatable.collection_class) || raise(Effective::AccessDenied) rescue Effective::AccessDenied => e return content_tag(:p, "You are not authorized to view this datatable. (cannot :index, #{datatable.collection_class})") end render partial: 'effective/datatables/datatable', locals: { datatable: datatable, input_js_options: .try(:to_json) } end |
#render_datatable_chart(datatable, name) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/helpers/effective_datatables_helper.rb', line 53 def render_datatable_chart(datatable, name) raise 'expected datatable to be present' unless datatable return unless datatable.charts.present? return unless datatable.charts[name].present? datatable.view ||= self = datatable.charts[name] chart = datatable.to_json[:charts][name] render partial: ([:partial] || 'effective/datatables/chart'), locals: { datatable: datatable, chart: chart } end |
#render_datatable_charts(datatable) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'app/helpers/effective_datatables_helper.rb', line 44 def render_datatable_charts(datatable) raise 'expected datatable to be present' unless datatable return unless datatable.charts.present? datatable.view ||= self datatable.charts.map { |name, _| render_datatable_chart(datatable, name) }.join.html_safe end |
#render_datatable_scopes(datatable) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'app/helpers/effective_datatables_helper.rb', line 35 def render_datatable_scopes(datatable) raise 'expected datatable to be present' unless datatable return unless datatable.scopes.present? datatable.view ||= self render partial: 'effective/datatables/scopes', locals: { datatable: datatable } end |
#render_simple_datatable(datatable, input_js_options = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/helpers/effective_datatables_helper.rb', line 19 def render_simple_datatable(datatable, = nil) raise 'expected datatable to be present' unless datatable datatable.view ||= self datatable.simple = true begin EffectiveDatatables.(controller, :index, datatable.collection_class) || raise(Effective::AccessDenied) rescue Effective::AccessDenied => e return content_tag(:p, "You are not authorized to view this datatable. (cannot :index, #{datatable.collection_class})})") end render partial: 'effective/datatables/datatable', locals: {datatable: datatable, input_js_options: .try(:to_json) } end |
#settings_icon_to(path, options = {}) ⇒ Object
104 105 106 |
# File 'app/helpers/effective_datatables_helper.rb', line 104 def settings_icon_to(path, = {}) glyphicon_to('cog', path, {title: 'Settings'}.merge()) end |
#show_icon_to(path, options = {}) ⇒ Object
Icon Helpers for actions_column or elsewhere
81 82 83 |
# File 'app/helpers/effective_datatables_helper.rb', line 81 def show_icon_to(path, = {}) glyphicon_to('eye-open', path, {title: 'Show'}.merge()) end |
#unarchive_icon_to(path, options = {}) ⇒ Object
99 100 101 102 |
# File 'app/helpers/effective_datatables_helper.rb', line 99 def unarchive_icon_to(path, = {}) defaults = {title: 'Unarchive', data: {confirm: 'Unarchive this item?'}} glyphicon_to('retweet', path, defaults.merge()) end |