Module: MailyHerald::Webui::ApplicationHelper

Includes:
Breadcrumbs::HelperExtensions
Defined in:
app/helpers/maily_herald/webui/application_helper.rb

Instance Method Summary collapse

Methods included from Breadcrumbs::HelperExtensions

#has_breadcrumbs?

Instance Method Details

#boolean_icon(value, options = {}) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 112

def boolean_icon value, options = {}
  options = {
    :style => :check,
    :text => :active,
  }.merge(options)

  i = case options[:style]
      when :check
        value ? "check-square-o" : "square-o"
      when :toggle
        value ? "toggle-on" : "toggle-off"
      end

  text = case options[:text]
         when :active
           value ? tw("commons.active") : tw("commons.inactive")
         when :enabled
           value ? tw("commons.enabled") : tw("commons.disabled")
         when :yes
           value ? tw("commons.positive") : tw("commons.negative")
         end

  icon(i, text)
end

#content_for_expertObject



69
70
71
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 69

def content_for_expert
  yield if expert_mode?
end

#display_context_attributes(attributes) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 54

def display_context_attributes attributes
  (:ul) do
    attributes.each do |k, v|
      if v.is_a?(Hash)
        concat((:li) do
          concat(k)
          concat(display_context_attributes(v))
        end)
      else
        concat((:li, k))
      end
    end
  end
end

#display_help_icon(title, options = {}) ⇒ Object



137
138
139
140
141
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 137

def display_help_icon title, options = {}
  link_to "#", class: "link link-help", data: {toggle: "tooltip", placement: options[:placement] || "right"}, title: (options[:scope] ? tw("#{options[:scope]}.help.#{title}") : t(".help.#{title}")) do
    icon(:question)
  end
end

#filter_box(field_name = :filter) ⇒ Object



143
144
145
146
147
148
149
150
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 143

def filter_box field_name = :filter
  (:div, class: "filter filter-search") do
    concat(text_field_tag(field_name, params[field_name], class: "search form-control", placeholder: "Search...", autocomplete: "off"))
    concat(button_tag(class: "btn", type: "submit") do
      icon(:search)
    end)
  end
end

#form_for(object, options = {}, &block) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 86

def form_for(object, options = {}, &block)
  options.reverse_merge!({builder: MailyHerald::Webui::FormBuilder})
  layout = case options[:layout]
           when :inline
             "form-inline"
           when :horizontal
             "form-horizontal"
           end
  if layout
    options[:html] ||= {}
    options[:html][:class] = [options[:html][:class], layout].compact.join(" ")
  end

  super(object, options, &block)
end

#friendly_name(obj) ⇒ Object



81
82
83
84
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 81

def friendly_name obj
  return unless obj
  obj.respond_to?(:title) && obj.title.present? ? obj.title : obj.try(:name)
end

#icon(icon, text = "", html_options = {}) ⇒ Object



102
103
104
105
106
107
108
109
110
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 102

def icon(icon, text="", html_options={})
  content_class = "fa fa-#{icon}"
  content_class << " #{html_options[:class]}" if html_options.key?(:class)
  html_options[:class] = content_class

  html = (:i, nil, html_options)
  html << " #{text}" unless text.blank?
  html.html_safe
end


43
44
45
46
47
48
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 43

def link_to_context_attributes_overview list, options = {}
  link_to context_variables_list_path(id: list, context: list.context_name), data: {toggle: "modal", target: "#modal-generic"}, class: ["link link-help", options[:class]] do 
    html = concat(icon(:list))
    html.concat(" ").concat(list.context_name) if options[:text]
  end if list.try(:context_name)
end

#render_breadcrumbsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 25

def render_breadcrumbs
  if has_breadcrumbs?
    (:ul, :class => "breadcrumb") do
      @breadcrumbs.each do |b|
        unless @breadcrumbs.last == b
          concat((:li) do
            concat(link_to(b[:name].is_a?(Symbol) ? tw(b[:name]) : b[:name], b[:url]))
          end)
        else
          concat((:li, :class => "active") do
            concat(b[:name].is_a?(Symbol) ? tw(b[:name]) : b[:name])
          end)
        end
      end
    end
  end
end

#render_context_attributes_info(list) ⇒ Object



50
51
52
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 50

def render_context_attributes_info list
  render partial: "maily_herald/webui/shared/context_attributes", locals: {list: list}
end

#render_main_menuObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 6

def render_main_menu
  (:ul, :class => "nav nav-main") do
    menu_manager.items.each do |i|
      title = i[:title] || i[:name]
      title = tw(title) if title.is_a?(Symbol)

      url = i[:url]
      url = self.instance_eval(&url) if url.is_a?(Proc)

      classes = []
      classes << "active" if current_menu_item == i[:name]

      concat((:li, :class => classes) do
        concat(link_to(title, url))
      end)
    end
  end
end

#smart_listing_config_profileObject



152
153
154
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 152

def smart_listing_config_profile
  :maily_herald
end

#tw(key, options = {}) ⇒ Object



77
78
79
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 77

def tw(key, options = {})
  t(key, {scope: [:maily_herald, :webui]}.merge(options))
end

#work_mode_t(mode) ⇒ Object



73
74
75
# File 'app/helpers/maily_herald/webui/application_helper.rb', line 73

def work_mode_t mode
  t(mode, {scope: [:maily_herald, :webui, :work_modes]})
end