Module: RedmineExtensions::ApplicationHelper

Includes:
RenderingHelper
Defined in:
app/helpers/redmine_extensions/application_helper.rb

Instance Method Summary collapse

Methods included from RenderingHelper

#render_with_fallback

Instance Method Details

#autocomplete_field_tag(name, jsonpath_or_array, selected_values, options = {}) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'app/helpers/redmine_extensions/application_helper.rb', line 166

def autocomplete_field_tag(name, jsonpath_or_array, selected_values, options = {})
  options.reverse_merge!({select_first_value: false, show_toggle_button: false, load_immediately: false, preload: true, multiple: true})
  options[:id] ||= sanitize_to_id(name)

  selected_values ||= []

  if jsonpath_or_array.is_a?(Array)
    source = jsonpath_or_array.to_json
  else
    source = "'#{jsonpath_or_array}'"
  end

  (:span, :class => 'easy-multiselect-tag-container') do
    text_field_tag('', '', (options[:html_options] || {}).merge(id: options[:id])) +
      javascript_tag("$('##{options[:id]}').easymultiselect({multiple: #{options[:multiple]}, rootElement: #{options[:rootElement].to_json}, inputName: '#{name}', preload: #{options[:preload]}, source: #{source}, selected: #{selected_values.to_json}, show_toggle_button: #{options[:show_toggle_button]}, select_first_value: #{options[:select_first_value]}, load_immediately: #{options[:load_immediately]}, autocomplete_options: #{(options[:jquery_auto_complete_options]||{}).to_json} });")
  end
end

#detect_hide_elements(uniq_id, user = nil, default = true) ⇒ Object

hide elements for issues and users



33
34
35
36
# File 'app/helpers/redmine_extensions/application_helper.rb', line 33

def detect_hide_elements(uniq_id, user = nil, default = true)
  return ''.html_safe if uniq_id.blank?
  return 'style="display:none"'.html_safe if !toggle_button_expanded?(uniq_id, user, default)
end

#entity_css_icon(entity_or_entity_class) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/helpers/redmine_extensions/application_helper.rb', line 91

def entity_css_icon(entity_or_entity_class)
  return '' if entity_or_entity_class.nil?

  if entity_or_entity_class.is_a?(Class) && entity_or_entity_class.respond_to?(:css_icon)
    entity_or_entity_class.css_icon
  elsif entity_or_entity_class.is_a?(ActiveRecord::Base)
    if entity_or_entity_class.respond_to?(:css_icon)
      entity_or_entity_class.css_icon
    elsif entity_or_entity_class.class.respond_to?(:css_icon)
      entity_or_entity_class.class.css_icon
    else
      "icon icon-#{entity_or_entity_class.class.name.dasherize}"
    end
  else
    "icon icon-#{entity_or_entity_class.class.name.dasherize}"
  end
end

#plugin_settings_path(plugin, *attrs) ⇒ Object

——-= Hack methods =——



7
8
9
10
11
12
13
# File 'app/helpers/redmine_extensions/application_helper.rb', line 7

def plugin_settings_path(plugin, *attrs)
  if plugin.is_a?(Redmine::Plugin) && (plugin.settings[:only_easy] || plugin.settings[:easy_settings])
    edit_easy_setting_path(plugin, *attrs)
  else
    super
  end
end

#present(model, options = {}, &block) ⇒ Object

——-= Rendering and presenting methods =——-



17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/helpers/redmine_extensions/application_helper.rb', line 17

def present(model, options={}, &block)
  if model.is_a?(RedmineExtensions::BasePresenter)
    presenter = model.update_options(options.merge(view_context: self))
  else
    presenter = RedmineExtensions::BasePresenter.present(model, self, options)
  end
  if block_given?
    yield presenter
  else
    presenter
  end
end

#render_entity_assignments(entity, target_class, options = {}, &block) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/helpers/redmine_extensions/application_helper.rb', line 47

def render_entity_assignments(entity, target_class, options = {}, &block)
  options ||= {}
  collection_name = options.delete(:collection_name) || target_class.name.pluralize.underscore

  project = options.delete(:project)
  query_class = options.delete(:query_class)

  if query_class.nil?
    query_class_name = target_class.name + 'Query'

    query_class = query_class_name.constantize #if Object.const_defined?(query_class_name)
  end

  return '' if !query_class || !(query_class < EasyQuery) || !entity.respond_to?(collection_name)

  query = query_class.new(:name => 'c_query')
  query.project = project
  query.set_entity_scope(entity, collection_name)
  query.column_names = options[:query_column_names] unless options[:query_column_names].blank?

  entities = query.entities

  entities_count = entities.size
  options[:entities_count] = entities_count

  options[:module_name] ||= "entity_#{entity.class.name.underscore}_#{entity.id}_#{collection_name}"
  options[:heading] ||= l("label_#{target_class.name.underscore}_plural", :default => 'Heading')

  if options[:context_menus_path].nil?
    options[:context_menus_path] = [
      "context_menu_#{collection_name}_path".to_sym,
      "context_menus_#{collection_name}_path".to_sym,
      "#{collection_name}_context_menu_path".to_sym
    ].detect do |m|
      m if respond_to?(m)
    end
  end

  render(:partial => 'easy_entity_assignments/assignments_container', :locals => {
    :entity => entity,
    :query => query, :target_class => target_class, :project => project,
    :entities => entities, :entities_count => entities_count, :options => options})
end

#render_toggler(container_uniq_id, user = nil, options = {}, &block) ⇒ Object

options:

> options = text beside of plus button

> options = a hash of html attributes

> options = (true => expanded -), (false => collapsed +)

> options = make ajax call for saving state (true => ajax call, false => no call, no save)

> options = html element outside heading => h3, h4



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'app/helpers/redmine_extensions/application_helper.rb', line 115

def render_toggler(container_uniq_id, user = nil, options={}, &block)
  user ||= User.current
  options[:heading] ||= ''
  options[:heading_links] ||= []
  options[:heading_links] = [options[:heading_links]] if options[:heading_links] && !options[:heading_links].is_a?(Array)
  options[:container_html] ||= {}
  options[:default_button_state] = false #if is_mobile_device?
  options[:default_button_state] = true if options[:default_button_state].nil?
  options[:ajax_call] = true if options[:ajax_call].nil?

  s = ''
  if !options.key?(:no_heading_button)
    options[:heading] << (:div, options[:heading_links].join(' ').html_safe, :class => 'module-heading-links') unless options[:heading_links].blank?
    s << render_toggler_header(user, options[:heading].html_safe, container_uniq_id, options)
  end

  if options[:ajax_call] == false
    expanded = options[:default_button_state]
  else
    expanded = true
  end

  s << ((:div, {
    :id => container_uniq_id,
    :style => (expanded ? '' : 'display:none')
  }.merge(options[:container_html]) { |k, o, n| "#{o}; #{n}" }, &block))
  s.html_safe
end

#render_toggler_header(user, content, modul_uniq_id, options = {}) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'app/helpers/redmine_extensions/application_helper.rb', line 144

def render_toggler_header(user, content, modul_uniq_id, options={})
  expander_options = options[:expander_options] || {}
  wrapping_heading_element = options[:wrapping_heading_element] || 'h3'
  wrapping_heading_element_classes = (options[:wrapping_heading_element_classes] || '') + ' module-heading'
  wrapping_heading_element_styles = options[:wrapping_heading_element_styles]
  ajax_call = options.delete(:ajax_call) ? 'true' : 'false'

  html = ''

  if options[:no_expander]
    html << (wrapping_heading_element, content, :class => wrapping_heading_element_classes, :style => wrapping_heading_element_styles)
  else
    html << '<div class="module-toggle-button">'
    html << "<div class='group open' >"
    html << (wrapping_heading_element, content, :class => wrapping_heading_element_classes, :style => wrapping_heading_element_styles, :onclick => "var event = arguments[0] || window.event; if( !$(event.target).hasClass('do_not_toggle') && !$(event.target).parent().hasClass('module-heading-links') ) toggleMyPageModule(this,'#{modul_uniq_id}','#{user.id}', #{ajax_call})")
    html << "<span class='expander #{expander_options[:class]}' onclick=\"toggleMyPageModule($(this),'#{modul_uniq_id}','#{user.id}', #{ajax_call}); return false;\" id=\"expander_#{modul_uniq_id}\">&nbsp;</span>"
    html << '</div></div>'
  end

  html.html_safe
end

#url_to_entity(entity, options = {}) ⇒ Object



38
39
40
41
42
43
44
45
# File 'app/helpers/redmine_extensions/application_helper.rb', line 38

def url_to_entity(entity, options={})
  m = "url_to_#{entity.class.name.underscore}".to_sym
  if respond_to?(m)
    send(m, entity, options)
  else
    nil
  end
end