Module: ActiveScaffold::Helpers::ViewHelpers
- Includes:
- AssociationHelpers, CountryHelpers, FormColumnHelpers, HumanConditionHelpers, IdHelpers, ListColumnHelpers, PaginationHelpers, SearchColumnHelpers, ShowColumnHelpers
- Defined in:
- lib/active_scaffold/helpers/view_helpers.rb
Overview
All extra helpers that should be included in the View. Also a dumping ground for uncategorized helpers.
Constant Summary
Constants included from CountryHelpers
CountryHelpers::COUNTRIES, CountryHelpers::USASTATES
Instance Method Summary collapse
- #action_link_html(link, url, html_options, record) ⇒ Object
- #action_link_html_options(link, url_options, record, html_options) ⇒ Object
- #action_link_url_options(link, url_options, record, options = {}) ⇒ Object
-
#active_scaffold_config ⇒ Object
access to the configuration variable.
- #active_scaffold_config_for(*args) ⇒ Object
- #active_scaffold_controller_for(*args) ⇒ Object
- #active_scaffold_error_messages_for(*params) ⇒ Object
-
#active_scaffold_ie_stylesheets(frontend = :default) ⇒ Object
Provides stylesheets for IE to include with
stylesheet_link_tag
. -
#active_scaffold_includes(*args) ⇒ Object
easy way to include ActiveScaffold assets.
-
#active_scaffold_javascripts(frontend = :default) ⇒ Object
Provides list of javascripts to include with
javascript_include_tag
You can use this with your javascripts like <%= javascript_include_tag :defaults, ‘your_own_cool_script’, active_scaffold_javascripts, :cache => true %>. -
#active_scaffold_stylesheets(frontend = :default) ⇒ Object
Provides stylesheets to include with
stylesheet_link_tag
. - #column_calculation(column) ⇒ Object
- #column_class(column, column_value, record) ⇒ Object
- #column_empty?(column_value) ⇒ Boolean
- #column_heading_class(column, sorting) ⇒ Object
- #column_show_add_existing(column) ⇒ Object
- #column_show_add_new(column, associated, record) ⇒ Object
-
#controller_path_for_activerecord(klass) ⇒ Object
Uncategorized.
- #form_remote_upload_tag(url_for_options = {}, options = {}) ⇒ Object
- #generate_temporary_id ⇒ Object
- #get_action_link_id(url_options, record = nil, column = nil) ⇒ Object
-
#in_subform?(column, parent_record) ⇒ Boolean
Should this column be displayed in the subform?.
-
#link_to_visibility_toggle(id, options = {}) ⇒ Object
Creates a javascript-based link that toggles the visibility of some element on the page.
-
#loading_indicator_tag(options) ⇒ Object
a general-use loading indicator (the “stuff is happening, please wait” feedback).
-
#option_tags_for(select_options, options = {}) ⇒ Object
Turns [[label, value]] into <option> tags Takes optional parameter of :include_blank.
- #render_action_link(link, url_options, record = nil, html_options = {}) ⇒ Object
- #render_column_calculation(column) ⇒ Object
- #render_group_action_link(link, url_options, options, record = nil) ⇒ Object
- #skip_action_link(link, *args) ⇒ Object
- #url_options_for_nested_link(column, record, link, url_options, options = {}) ⇒ Object
- #url_options_for_sti_link(column, record, link, url_options, options = {}) ⇒ Object
Methods included from HumanConditionHelpers
#active_scaffold_human_condition_for, #override_human_condition, #override_human_condition?, #override_human_condition_column, #override_human_condition_column?
Methods included from CountryHelpers
#country_options_for_select, #country_select, #usa_state_options_for_select, #usa_state_select
Methods included from SearchColumnHelpers
#active_scaffold_search_boolean, #active_scaffold_search_country, #active_scaffold_search_date, #active_scaffold_search_datetime, #active_scaffold_search_for, #active_scaffold_search_multi_select, #active_scaffold_search_null, #active_scaffold_search_options, #active_scaffold_search_range, #active_scaffold_search_range_comparator_options, #active_scaffold_search_record_select, #active_scaffold_search_select, #active_scaffold_search_text, #active_scaffold_search_time, #active_scaffold_search_usa_state, #field_search_datetime_value, #field_search_params_range_values, #field_search_record_select_value, #override_search, #override_search?, #override_search_field, #override_search_field?, #searched_by?, #visibles_and_hiddens
Methods included from FormColumnHelpers
#active_scaffold_add_existing_input, #active_scaffold_add_existing_label, #active_scaffold_checkbox_list, #active_scaffold_input_boolean, #active_scaffold_input_carrierwave, #active_scaffold_input_checkbox, #active_scaffold_input_country, #active_scaffold_input_enum, #active_scaffold_input_file_column, #active_scaffold_input_for, #active_scaffold_input_options, #active_scaffold_input_paperclip, #active_scaffold_input_password, #active_scaffold_input_plural_association, #active_scaffold_input_radio, #active_scaffold_input_record_select, #active_scaffold_input_select, #active_scaffold_input_singular_association, #active_scaffold_input_text_options, #active_scaffold_input_textarea, #active_scaffold_input_usa_state, #active_scaffold_input_virtual, #active_scaffold_record_select, #active_scaffold_render_input, #active_scaffold_translated_option, #column_renders_as, #column_scope, #form_partial_for_column, #onsubmit, #override_form_field, #override_form_field?, #override_form_field_partial, #override_form_field_partial?, #override_input, #override_input?, #override_subform_partial, #override_subform_partial?, #subform_partial_for_column, #update_columns_options
Methods included from ShowColumnHelpers
#active_scaffold_show_text, #override_show_column_ui, #override_show_column_ui?, #show_column_override, #show_column_override?, #show_column_value
Methods included from ListColumnHelpers
#action_link_to_inline_form, #active_scaffold_column_carrierwave, #active_scaffold_column_checkbox, #active_scaffold_column_download_link, #active_scaffold_column_download_link_with_filename, #active_scaffold_column_paperclip, #active_scaffold_column_select, #active_scaffold_column_text, #active_scaffold_column_thumbnail, #active_scaffold_inplace_edit, #cache_association, #clean_column_value, #column_heading_value, #column_link_authorized?, #column_override, #column_override?, #configure_column_link, #format_association_value, #format_column_value, #format_inplace_edit_column, #format_number_value, #format_value, #get_column_value, #inplace_edit?, #inplace_edit_cloning?, #inplace_edit_control, #inplace_edit_control_css_class, #inplace_edit_tag_attributes, #mark_column_heading, #override_column_ui, #override_column_ui?, #render_column_heading, #render_list_column, #render_nested_view
Methods included from PaginationHelpers
#pagination_ajax_link, #pagination_ajax_links
Methods included from AssociationHelpers
#association_options_count, #association_options_find, #options_for_association, #options_for_association_conditions, #options_for_association_count
Methods included from IdHelpers
#action_iframe_id, #action_link_id, #active_scaffold_calculations_id, #active_scaffold_column_header_id, #active_scaffold_content_id, #active_scaffold_id, #active_scaffold_messages_id, #active_scaffold_tbody_id, #association_subform_id, #before_header_id, #controller_id, #element_cell_id, #element_form_id, #element_messages_id, #element_row_id, #empty_message_id, #id_from_controller, #loading_indicator_id, #search_input_id, #sub_form_id, #sub_form_list_id, #sub_section_id, #table_action_id
Instance Method Details
#action_link_html(link, url, html_options, record) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 202 def action_link_html(link, url, , record) # issue 260, use url_options[:link] if it exists. This prevents DB data from being localized. label = url.delete(:link) if url.is_a?(Hash) label ||= link.label if link.image.nil? html = link_to(label, url, ) else html = link_to(image_tag(link.image[:name] , :size => link.image[:size], :alt => label), url, ) end # if url is nil we would like to generate an anchor without href attribute url.nil? ? html.sub(/href=".*?"/, '') : html end |
#action_link_html_options(link, url_options, record, html_options) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 163 def (link, , record, ) link_id = get_action_link_id(, record, link.column) .reverse_merge! link..merge(:class => link.action) # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails [:method] = link.method if link.method != :get ['data-confirm'] = link.confirm(record.try(:to_label)) if link.confirm? ['data-position'] = link.position if link.position and link.inline? [:class] += ' as_action' if link.inline? if link.popup? ['data-popup'] = true [:target] = '_blank' end [:id] = link_id [:remote] = true unless link.page? || link.popup? if link.dhtml_confirm? [:class] += ' as_action' if !link.inline? [:page_link] = 'true' if !link.inline? [:dhtml_confirm] = link.dhtml_confirm.value [:onclick] = link.dhtml_confirm.onclick_function(controller, link_id) end [:class] += " #{link.[:class]}" unless link.[:class].blank? end |
#action_link_url_options(link, url_options, record, options = {}) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 148 def (link, , record, = {}) = .clone [:action] = link.action [:controller] = link.controller if link.controller .delete(:search) if link.controller and link.controller.to_s != params[:controller] .merge! link.parameters if link.parameters @link_record = record .merge! self.instance_eval(&(link.dynamic_parameters)) if link.dynamic_parameters.is_a?(Proc) @link_record = nil (link.column, record, link, , ) if link.nested_link? (link.column, record, link, , ) unless record.nil? || active_scaffold_config.sti_children.nil? [:_method] = link.method if !link.confirm? && link.inline? && link.method != :get end |
#active_scaffold_config ⇒ Object
access to the configuration variable
21 22 23 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 21 def active_scaffold_config controller.class.active_scaffold_config end |
#active_scaffold_config_for(*args) ⇒ Object
25 26 27 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 25 def active_scaffold_config_for(*args) controller.class.active_scaffold_config_for(*args) end |
#active_scaffold_controller_for(*args) ⇒ Object
29 30 31 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 29 def active_scaffold_controller_for(*args) controller.class.active_scaffold_controller_for(*args) end |
#active_scaffold_error_messages_for(*params) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 299 def (*params) = params..symbolize_keys .reverse_merge!(:container_tag => :div, :list_type => :ul) objects = Array.wrap(.delete(:object) || params).map do |object| object = instance_variable_get("@#{object}") unless object.respond_to?(:to_model) object = convert_to_model(object) if object.class.respond_to?(:model_name) [:object_name] ||= object.class.model_name.human.downcase end object end objects.compact! count = objects.inject(0) {|sum, object| sum + object.errors.count } unless count.zero? html = {} [:id, :class].each do |key| if .include?(key) value = [key] html[key] = value unless value.blank? else html[key] = 'errorExplanation' end end [:object_name] ||= params.first = if .include?(:header_message) [:header_message] else as_('errors.template.header', :count => count, :model => [:object_name].to_s.gsub('_', ' ')) end = .include?(:message) ? [:message] : as_('errors.template.body') = objects.sum do |object| object.errors..map do |msg| [:list_type] != :br ? content_tag(:li, msg) : msg end end = if [:list_type] == :br .join('<br/>').html_safe else content_tag([:list_type], .join.html_safe) end contents = [] contents << content_tag([:header_tag] || :h2, ) unless .blank? contents << content_tag(:p, ) unless .blank? contents << contents = contents.join.html_safe [:container_tag] ? content_tag([:container_tag], contents, html) : contents else '' end end |
#active_scaffold_ie_stylesheets(frontend = :default) ⇒ Object
Provides stylesheets for IE to include with stylesheet_link_tag
97 98 99 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 97 def active_scaffold_ie_stylesheets(frontend = :default) [ActiveScaffold::Config::Core.asset_path("stylesheet-ie.css", frontend)] end |
#active_scaffold_includes(*args) ⇒ Object
easy way to include ActiveScaffold assets
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 102 def active_scaffold_includes(*args) frontend = args.first.is_a?(Symbol) ? args.shift : :default = args.first.is_a?(Hash) ? args.shift : {} js = javascript_include_tag(*active_scaffold_javascripts(frontend).push()) css = stylesheet_link_tag(*active_scaffold_stylesheets(frontend).push()) [:cache] += '_ie' if [:cache].is_a? String [:concat] += '_ie' if [:concat].is_a? String ie_css = stylesheet_link_tag(*active_scaffold_ie_stylesheets(frontend).push()) js + "\n" + css + "\n<!--[if IE]>".html_safe + ie_css + "<![endif]-->\n".html_safe end |
#active_scaffold_javascripts(frontend = :default) ⇒ Object
Provides list of javascripts to include with javascript_include_tag
You can use this with your javascripts like
<%= javascript_include_tag :defaults, 'your_own_cool_script', active_scaffold_javascripts, :cache => true %>
85 86 87 88 89 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 85 def active_scaffold_javascripts(frontend = :default) ActiveScaffold::Config::Core.javascripts(frontend).collect do |name| ActiveScaffold::Config::Core.asset_path(name, frontend) end end |
#active_scaffold_stylesheets(frontend = :default) ⇒ Object
Provides stylesheets to include with stylesheet_link_tag
92 93 94 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 92 def active_scaffold_stylesheets(frontend = :default) [ActiveScaffold::Config::Core.asset_path("stylesheet.css", frontend)] end |
#column_calculation(column) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 269 def column_calculation(column) unless column.calculate.instance_of? Proc conditions = controller.send(:all_conditions) includes = active_scaffold_config.list.count_includes includes ||= controller.send(:active_scaffold_includes) unless conditions.nil? calculation = beginning_of_chain.calculate(column.calculate, column.name, :conditions => conditions, :joins => controller.send(:joins_for_collection), :include => includes) else column.calculate.call(@records) end end |
#column_class(column, column_value, record) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 238 def column_class(column, column_value, record) classes = [] classes << "#{column.name}-column" if column.css_class.is_a?(Proc) css_class = column.css_class.call(column_value, record) classes << css_class unless css_class.nil? else classes << column.css_class end unless column.css_class.nil? classes << 'empty' if column_empty? column_value classes << 'sorted' if active_scaffold_config.list.user.sorting.sorts_on?(column) classes << 'numeric' if column.column and [:decimal, :float, :integer].include?(column.column.type) classes.join(' ').rstrip end |
#column_empty?(column_value) ⇒ Boolean
262 263 264 265 266 267 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 262 def column_empty?(column_value) empty = column_value.nil? empty ||= column_value.empty? if column_value.respond_to? :empty? empty ||= [' ', active_scaffold_config.list.empty_field_text].include? column_value if String === column_value return empty end |
#column_heading_class(column, sorting) ⇒ Object
254 255 256 257 258 259 260 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 254 def column_heading_class(column, sorting) classes = [] classes << "#{column.name}-column_heading" classes << "sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column classes << column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) classes.join(' ') end |
#column_show_add_existing(column) ⇒ Object
289 290 291 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 289 def column_show_add_existing(column) (column.allow_add_existing and (column.association) > 0) end |
#column_show_add_new(column, associated, record) ⇒ Object
293 294 295 296 297 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 293 def column_show_add_new(column, associated, record) value = column.plural_association? || (column.singular_association? and not associated.empty?) value = false unless record.class.(:crud_type => :create) value end |
#controller_path_for_activerecord(klass) ⇒ Object
Uncategorized
37 38 39 40 41 42 43 44 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 37 def controller_path_for_activerecord(klass) begin controller = active_scaffold_controller_for(klass) controller.controller_path rescue ActiveScaffold::ControllerNotFound controller = nil end end |
#form_remote_upload_tag(url_for_options = {}, options = {}) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 73 def form_remote_upload_tag( = {}, = {}) [:target] = action_iframe_id() [:multipart] ||= true [:class] = "#{[:class]} as_remote_upload".strip output="" output << form_tag(, ) (output << "<iframe id='#{action_iframe_id()}' name='#{action_iframe_id()}' style='display:none'></iframe>").html_safe end |
#generate_temporary_id ⇒ Object
46 47 48 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 46 def generate_temporary_id (Time.now.to_f*1000).to_i.to_s end |
#get_action_link_id(url_options, record = nil, column = nil) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 189 def get_action_link_id(, record = nil, column = nil) id = [:id] || [:parent_id] id = "#{column.association.name}-#{record.id}" if column && column.plural_association? if record.try(column.association.name.to_sym).present? id = "#{column.association.name}-#{record.send(column.association.name).id}-#{record.id}" else id = "#{column.association.name}-#{record.id}" unless record.nil? end if column && column.singular_association? id = "#{id}-#{[:batch_scope].downcase}" if [:batch_scope] action_id = "#{id_from_controller([:controller]) + '-' if [:parent_controller]}#{[:action].to_s}" action_link_id(action_id, id) end |
#in_subform?(column, parent_record) ⇒ Boolean
Should this column be displayed in the subform?
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 61 def in_subform?(column, parent_record) return true unless column.association # Polymorphic associations can't appear because they *might* be the reverse association, and because you generally don't assign an association from the polymorphic side ... I think. return false if column.polymorphic_association? # A column shouldn't be in the subform if it's the reverse association to the parent return false if column.association.reverse_for?(parent_record.class) return true end |
#link_to_visibility_toggle(id, options = {}) ⇒ Object
Creates a javascript-based link that toggles the visibility of some element on the page. By default, it toggles the visibility of the sibling after the one it’s nested in. You may pass custom javascript logic in options to change that, though. For example, you could say :of => ‘$(“my_div_id”)’. You may also flag whether the other element is visible by default or not, and the initial text will adjust accordingly.
123 124 125 126 127 128 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 123 def link_to_visibility_toggle(id, = {}) [:default_visible] = true if [:default_visible].nil? [:hide_label] = as_(:hide) [:show_label] = as_(:show) javascript_tag("ActiveScaffold.create_visibility_toggle('#{id}', #{.to_json});") end |
#loading_indicator_tag(options) ⇒ Object
a general-use loading indicator (the “stuff is happening, please wait” feedback)
116 117 118 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 116 def loading_indicator_tag() image_tag "/images/active_scaffold/default/indicator.gif", :style => "visibility:hidden;", :id => loading_indicator_id(), :alt => "loading indicator", :class => "loading-indicator" end |
#option_tags_for(select_options, options = {}) ⇒ Object
Turns [[label, value]] into <option> tags Takes optional parameter of :include_blank
52 53 54 55 56 57 58 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 52 def (, = {}) .insert(0,[as_(:_select_),nil]) if [:include_blank] .collect do |option| label, value = option[0], option[1] value.nil? ? "<option value="">#{label}</option>" : "<option value=\"#{value}\">#{label}</option>" end end |
#render_action_link(link, url_options, record = nil, html_options = {}) ⇒ Object
134 135 136 137 138 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 134 def render_action_link(link, , record = nil, = {}) = (link, , record) = (link, , record, ) action_link_html(link, , , record) end |
#render_column_calculation(column) ⇒ Object
281 282 283 284 285 286 287 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 281 def render_column_calculation(column) calculation = column_calculation(column) override_formatter = "render_#{column.name}_#{column.calculate}" calculation = send(override_formatter, calculation) if respond_to? override_formatter "#{"#{as_(column.calculate)}: " unless column.calculate.is_a? Proc}#{format_column_value nil, column, calculation}" end |
#render_group_action_link(link, url_options, options, record = nil) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 140 def render_group_action_link(link, , , record = nil) if link.type == :member && ![:authorized] action_link_html(link, nil, {:class => "disabled #{link.action}#{link.[:class].blank? ? '' : (' ' + link.[:class])}"}, record) else render_action_link(link, , record) end end |
#skip_action_link(link, *args) ⇒ Object
130 131 132 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 130 def skip_action_link(link, *args) (!link.ignore_method.nil? and controller.try(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args)) end |
#url_options_for_nested_link(column, record, link, url_options, options = {}) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 215 def (column, record, link, , = {}) if column && column.association [:assoc_id] = .delete(:id) [:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present? link.eid = "#{controller_id.from(3)}_#{record.id}_#{column.association.name}" unless .has_key?(:reuse_eid) [:eid] = link.eid elsif link.parameters && link.parameters[:named_scope] [:assoc_id] = .delete(:id) link.eid = "#{controller_id.from(3)}_#{record.id}_#{link.parameters[:named_scope]}" unless .has_key?(:reuse_eid) [:eid] = link.eid end end |
#url_options_for_sti_link(column, record, link, url_options, options = {}) ⇒ Object
228 229 230 231 232 233 234 235 236 |
# File 'lib/active_scaffold/helpers/view_helpers.rb', line 228 def (column, record, link, , = {}) #need to find out controller of current record type #and set parameters sti_controller_path = controller_path_for_activerecord(record.class) if sti_controller_path [:controller] = sti_controller_path [:parent_sti] = controller_path end end |