module Wobapphelpers::Helpers::ActionViewHelper

implement model independent links for new, edit, show, delete

Public Instance Methods

active_class(myclass) click to toggle source
# File lib/wobapphelpers/helpers/action_view_helper.rb, line 106
def active_class(myclass)
  if controller.controller_name == myclass
    "active"
  end
end
cancel_button() click to toggle source
# File lib/wobapphelpers/helpers/action_view_helper.rb, line 76
def cancel_button
  link_to icon_cancel + " " + t('wobapphelpers.helpers.cancel'),
    url_for(:back), :class => 'btn btn-secondary'
end
form_legend() click to toggle source
# File lib/wobapphelpers/helpers/action_view_helper.rb, line 8
def form_legend
  raw(
   %Q[<div class="row">] +
   %Q[<div class="col-sm-9 offset-sm-3 col-md-10 offset-md-2">] +
   %Q[<legend>#{controlleraction}</legend>] +
   %Q[</div>] +
   %Q[</div>]
  )
end
show_flash() click to toggle source
# File lib/wobapphelpers/helpers/action_view_helper.rb, line 81
def show_flash
  # "- #{flash[:success]} - #{flash[:notice]} - #{flash[:alert]} -"
  msg = ""
  [:alert, :error, :notice, :success, :info].each do |severity|
    next unless flash[severity]
    case severity
    when :error, :alert
      my_class = "alert alert-danger"
    when :notice, :info
      my_class = "alert alert-info"
    when :success
      my_class = "alert alert-success"
    else
      my_class = severity.to_s
    end
    msg += %Q[<div id="#{severity.to_s}" class="#{my_class} alert-dismissable fade show noprint" role="alert">]
    msg += %Q[<button type="button" class="close" data-dismiss="alert" aria-label="Clse">]
    msg += %Q[<span aria-hidden="true">&times;</span>]
    msg += %Q[</button>]
    msg += flash[severity]
    msg += %Q[</div>]
  end
  msg.html_safe
end

Private Instance Methods

_can?(action, obj) click to toggle source
# File lib/wobapphelpers/helpers/action_view_helper.rb, line 146
def _can?(action, obj)
  return true if Wobapphelpers.cancan == :none
  obj = _normalize(obj) if obj.kind_of? Class
  can? action, obj
end
_normalize(model) click to toggle source
# File lib/wobapphelpers/helpers/action_view_helper.rb, line 152
def _normalize(model)
  if Wobapphelpers.cancan == :cancan2
    model.model_name.downcase.pluralize.to_sym
  else
    model
  end
end
confirm_message(obj) click to toggle source
# File lib/wobapphelpers/helpers/action_view_helper.rb, line 178
def confirm_message(obj)
 "#{title(obj, :destroy)}?\n" + t('wobapphelpers.actions.destroy_confirm')
end
controlleraction() click to toggle source
# File lib/wobapphelpers/helpers/action_view_helper.rb, line 137
def controlleraction
  action        = controller.action_name
  namespace     = controller.controller_path
  resource_name = t("activerecord.models.#{namespace.singularize}")
  search_for    = [namespace, action].join(".").to_sym
  t(search_for, scope: "wobapphelpers.actions".to_sym,
    default: action.to_sym, model: resource_name)
end
default_options(obj, action) click to toggle source
# File lib/wobapphelpers/helpers/action_view_helper.rb, line 160
def default_options(obj, action)
  {
    title: title(obj, action),
    remote: false,
    class: 'btn btn-secondary',
  }
end
delete_options(obj) click to toggle source
# File lib/wobapphelpers/helpers/action_view_helper.rb, line 168
def delete_options(obj)
  {
    title: title(obj, :destroy),
    remote: false,
    class: 'btn btn-danger',
    data: {},
    method: :delete,
  }
end
get_parts(poly) click to toggle source

returns poly, object mypoly: poly.compact! if is_a? Array

# File lib/wobapphelpers/helpers/action_view_helper.rb, line 118
def get_parts(poly)
  if poly.kind_of? Array
    mypoly = poly.compact
    [mypoly, mypoly[-1]]
  else
    [poly, poly]
  end
end
title(obj, action) click to toggle source
# File lib/wobapphelpers/helpers/action_view_helper.rb, line 127
def title(obj, action)
  if obj.kind_of? Class
    model = obj
  else
    model = obj.class
  end
  t(action.to_s, scope: "wobapphelpers.actions".to_sym,
    model: t('activerecord.models.' + model.model_name.i18n_key.to_s))
end