Module: MegaBar::ApplicationHelper

Defined in:
app/helpers/mega_bar/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#block_action_interpreter(block) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/helpers/mega_bar/application_helper.rb', line 115

def block_action_interpreter(block)
  case block.actions
  when 'show'
    "(used on show)"
  when 'sine'
    "(used on all displays)"
  when "current"
    "(uses current action)"
  else
   'not sure when this block would be used'
  end
end


65
66
67
68
69
70
# File 'app/helpers/mega_bar/application_helper.rb', line 65

def block_help_links
  links = []  
  # links << ['/mega-bar/blocks/' + @block.id.to_s + '?return_to=' + request.env['PATH_INFO'], 'Model Displays for the "' + @block.name + '" Block'] if @block.name
  # links << ['/mega-bar/blocks/' + @block.id.to_s + '/edit', 'Edit Block']
  links.map{ |l| link_to l[1], l[0]}.join(' | ')
end


89
90
91
92
93
94
# File 'app/helpers/mega_bar/application_helper.rb', line 89

def data_display_help_links(field)
  links = []
  links << [MegaBar::Engine.routes.url_for(controller: field[:data_format].controller_name, action: 'edit', id: field[:data_format].id, only_path: true)  + '?return_to=' + request.env['PATH_INFO'], field[:field_display].format.capitalize + ' settings' ]
   # links << [MegaBar::Engine.routes.url_for(controller: '/mega_bar/' + field[:field_display].format.pluralize, action: 'edit', id: field[:data_format].id, :only_path=> true), 'Edit ' + field[:field_display].format.capitalize]
  links.map{ |l| link_to l[1], l[0]}.join(' | ')
end

#data_format_locals(mega_record, displayable_field, value = nil, mega_bar = nil?) ) ⇒ Object



109
110
111
112
113
# File 'app/helpers/mega_bar/application_helper.rb', line 109

def data_format_locals(mega_record, displayable_field, value=nil, mega_bar=nil?)
  local = {obj: mega_record, displayable_field: displayable_field, field: displayable_field[:field], field_display: displayable_field[:field_display], options: displayable_field[:options], mega_bar: mega_bar, value: value }
  local[displayable_field[:data_format].class.name.downcase.sub('::', '_').sub('megabar_', '').to_sym] = displayable_field[:data_format]
  local
end


83
84
85
86
87
88
# File 'app/helpers/mega_bar/application_helper.rb', line 83

def field_help_links(field)
  links = []
  links << ['/mega-bar/models/' + field[:field].model_id.to_s + '/fields/' + field[:field].id.to_s + '?return_to=' + request.env['PATH_INFO'], 'Field']
  links << ['/mega-bar/field_displays/' + field[:field_display].id.to_s, 'Field Display']
  links.map{ |l| link_to l[1], l[0]}.join(' | ')
end

#filter_containsObject



49
50
51
52
# File 'app/helpers/mega_bar/application_helper.rb', line 49

def filter_contains
  filterr = text_field_tag(param_from_tablename(@mega_model_properties, @displayable_field[:field].tablename) + "[" + @displayable_field[:field].field + "___filter]", '', size: 15 )

end


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

def layout_help_links
  links = []
  links << ['/mega-bar/pages/' + @mega_page[:page_id].to_s  + '/layouts/' + @mega_layout.id.to_s  + '?return_to=' + request.env['PATH_INFO'], 'Layout Settings'] unless @mega_page.blank?
  # links << ['/mega-bar/layouts/' + @mega_layout.id.to_s + '/edit', 'Edit Layout']
  links.map{ |l| link_to l[1], l[0]}.join(' | ')
end

#layout_settings_header(layout = nil) ⇒ Object



128
129
130
131
132
# File 'app/helpers/mega_bar/application_helper.rb', line 128

def layout_settings_header(layout = nil)
  if layout.present?
    "<h2>Layout Sections</h2>".html_safe
  end
end


35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/mega_bar/application_helper.rb', line 35

def link_path(action = nil, id = nil)
  # application helper
  param_hash = {}
  @nested_ids.each do |param|
    param_hash = param_hash.merge(param)
  end
  param_hash = param_hash.merge(params.dup)
  param_hash[:action] = action
  param_hash[:id] = id
  url_for(param_hash)
end


60
61
62
63
64
# File 'app/helpers/mega_bar/application_helper.rb', line 60

def model_display_collection_help_links
  links = []
  links << ['/mega-bar/model-display-collections/' + @mega_display[:collection_settings].id.to_s + '/edit?return_to=' + request.env['PATH_INFO'], 'Pagination Settings']
  links.map{ |l| link_to l[1], l[0]}.join(' | ')
end


54
55
56
57
58
59
# File 'app/helpers/mega_bar/application_helper.rb', line 54

def model_display_help_links
  links = []
  links << ['/mega-bar/model_displays/' + @mega_display[:model_display].id.to_s  + '?return_to=' + request.env['PATH_INFO'], 'Field Displays for the "' + @mega_display[:model_display].header.to_s +  '" model display']
  # links << ['/mega-bar/model_displays/' + @mega_display[:model_display].id.to_s  + '/edit' , 'Edit Model Display']
  links.map{ |l| link_to l[1], l[0]}.join(' | ')
end


77
78
79
80
81
82
# File 'app/helpers/mega_bar/application_helper.rb', line 77

def page_help_links
  links = []
  links << ['/mega-bar/pages/' + @mega_page[:page_id].to_s + '?return_to=' + request.env['PATH_INFO'], 'Layouts on the "' + @mega_page[:name] + '" Page']
  links << ['/mega-bar/pages/' + @mega_page[:page_id].to_s + '/edit/', 'Edit Page']
  links.map{ |l| link_to l[1], l[0]}.join(' | ')
end

#param_from_tablename(model_props, tablename) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/mega_bar/application_helper.rb', line 19

def param_from_tablename(model_props, tablename)
  # used in data_display stuff. but might could be replaced with env[:mega_env] stuff

  # if tablename starts with the module from the model_props, then chop it.
  # else just use it and hope for the best.
  # Joining to foreign modules not supported and what will happen is forms won't save if the table
  # additional possible logic:
  # else if you can find that the table couldn't be namespaced, then use that
  # elseif theres a module out there for it use it #todo:
  # else  use as is....

  prefix = model_props.modyule.nil? || model_props.modyule.empty? ? '8675309' : model_props.modyule.split('::').map { | m | m.underscore }.join('_') + '_'
  tablename.start_with?(prefix) ? tablename[prefix.size..-1].singularize : tablename.singularize

end

#pre_renderObject



47
48
# File 'app/helpers/mega_bar/application_helper.rb', line 47

def pre_render
end

#reorder_down(field, direction) ⇒ Object



102
103
104
105
106
107
108
# File 'app/helpers/mega_bar/application_helper.rb', line 102

def reorder_down(field, direction)
  return '' if @mega_display[:displayable_fields].last[:field_display].position == field[:field_display].position
  links = []
  arrow = direction == 'right' ? '->' : 'v'
  links << ["/mega-bar/field_displays/move/#{field[:field_display].id}?method=move_lower&return_to=" + request.env['PATH_INFO'] , arrow]
  links.map{ |l| link_to l[1], l[0], {data: { turbolinks: false }, class: 'admin_links'}}.join(' | ')
end

#reorder_up(field, direction) ⇒ Object



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

def reorder_up(field, direction)
  return '' if @mega_display[:displayable_fields].first[:field_display].position == field[:field_display].position
  links = []
  arrow = direction == 'left' ? '<-' : '^'
  links << ["/mega-bar/field_displays/move/#{field[:field_display].id}?method=move_higher&return_to=" + request.env['PATH_INFO'], arrow]
  links.map{ |l| link_to l[1], l[0], {data: { turbolinks: false }, class: 'admin_links'}}.join(' | ')
end

#sortable(column, title = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/mega_bar/application_helper.rb', line 3

def sortable(column, title=nil)
  #422pm.
  return title if !params[:id].blank?
  title ||= column.titleize
  css_class = column == sort_column(@mega_class, @mega_model_properties, params) ? 'current ' + sort_direction(params, @mega_model_properties) : nil
  direction = column == sort_column(@mega_class, @mega_model_properties, params) && sort_direction(params, @mega_model_properties) == 'asc' ? 'desc' : 'asc'
  hsh = {sort: column, direction: direction}
  action = !['show', 'index'].include?(@mega_rout[:action]) ? "/#{@mega_rout[:action]}" : ''

  path = url_for([*@nested_instance_variables, @kontroller_inst.pluralize.to_sym ]) + action + '?' + hsh.to_param
  link_to title, path, class: css_class
#       link_to title, hsh, class: css_class
  #link_to best_in_place sort_column, title, {:sort => column, :direction => direction, controller: @kontroller_path}, class: css_class

end