Module: RedmineExtensions::ApplicationHelper
- Includes:
- RenderingHelper
- Defined in:
- app/helpers/redmine_extensions/application_helper.rb
Instance Method Summary collapse
- #autocomplete_field_tag(name, jsonpath_or_array, selected_values, options = {}) ⇒ Object
-
#detect_hide_elements(uniq_id, user = nil, default = true) ⇒ Object
hide elements for issues and users.
- #entity_css_icon(entity_or_entity_class) ⇒ Object
-
#plugin_settings_path(plugin, *attrs) ⇒ Object
——-= Hack methods =——.
-
#present(model, options = {}, &block) ⇒ Object
——-= Rendering and presenting methods =——-.
- #render_entity_assignments(entity, target_class, options = {}, &block) ⇒ Object
- #render_toggler(container_uniq_id, user = nil, options = {}, &block) ⇒ Object
- #render_toggler_header(user, content, modul_uniq_id, options = {}) ⇒ Object
- #url_to_entity(entity, options = {}) ⇒ Object
Methods included from RenderingHelper
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, = {}) .reverse_merge!({select_first_value: false, show_toggle_button: false, load_immediately: false, preload: true, multiple: true}) [: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 content_tag(:span, :class => 'easy-multiselect-tag-container') do text_field_tag('', '', ([:html_options] || {}).merge(id: [: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 !(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, ={}, &block) if model.is_a?(RedmineExtensions::BasePresenter) presenter = model.(.merge(view_context: self)) else presenter = RedmineExtensions::BasePresenter.present(model, self, ) 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, = {}, &block) ||= {} collection_name = .delete(:collection_name) || target_class.name.pluralize.underscore project = .delete(:project) query_class = .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 = [:query_column_names] unless [:query_column_names].blank? entities = query.entities entities_count = entities.size [:entities_count] = entities_count [:module_name] ||= "entity_#{entity.class.name.underscore}_#{entity.id}_#{collection_name}" [:heading] ||= l("label_#{target_class.name.underscore}_plural", :default => 'Heading') if [:context_menus_path].nil? [: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 => }) end |
#render_toggler(container_uniq_id, user = nil, options = {}, &block) ⇒ Object
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, ={}, &block) user ||= User.current [:heading] ||= '' [:heading_links] ||= [] [:heading_links] = [[:heading_links]] if [:heading_links] && ![:heading_links].is_a?(Array) [:container_html] ||= {} [:default_button_state] = false #if is_mobile_device? [:default_button_state] = true if [:default_button_state].nil? [:ajax_call] = true if [:ajax_call].nil? s = '' if !.key?(:no_heading_button) [:heading] << content_tag(:div, [:heading_links].join(' ').html_safe, :class => 'module-heading-links') unless [:heading_links].blank? s << render_toggler_header(user, [:heading].html_safe, container_uniq_id, ) end if [:ajax_call] == false = [:default_button_state] else = true end s << (content_tag(:div, { :id => container_uniq_id, :style => ( ? '' : 'display:none') }.merge([: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, ={}) = [:expander_options] || {} wrapping_heading_element = [:wrapping_heading_element] || 'h3' wrapping_heading_element_classes = ([:wrapping_heading_element_classes] || '') + ' module-heading' wrapping_heading_element_styles = [:wrapping_heading_element_styles] ajax_call = .delete(:ajax_call) ? 'true' : 'false' html = '' if [:no_expander] html << content_tag(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 << content_tag(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}\"> </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, ={}) m = "url_to_#{entity.class.name.underscore}".to_sym if respond_to?(m) send(m, entity, ) else nil end end |