Module: Mokio::Backend::BackendHelper
- Includes:
- Haml::Helpers
- Defined in:
- app/helpers/mokio/backend/backend_helper.rb
Instance Method Summary collapse
-
#bt(title, from_modal_name = nil) ⇒ Object
Translate methods.
- #btc(title, from_modal_name = nil) ⇒ Object
-
#bts(title) ⇒ Object
Sidebar button translate method.
-
#can_manage_site_elements? ⇒ Boolean
Can user manage any site elements.
- #engine_root ⇒ Object
-
#generate_tableize_name(type) ⇒ Object
return table name for type.
- #render_backend_input_active(f) ⇒ Object
- #render_backend_input_active_checkbox(f, name) ⇒ Object
- #render_backend_input_home_page(f) ⇒ Object
-
#render_backend_input_lang_id(f) ⇒ Object
COMMON INPUTS HELPERS.
- #set_sorting_param(obj_class) ⇒ Object
-
#sidebar_btn(type, icon_class, label = "", add_btn = true, check_permissions = true, plus_icon_class = "icomoon-icon-plus") ⇒ Object
Generate sidebar button ==== Examples For
sidebar_btn Mokio::Menu, "icomoon-icon-menu-2"
it generates: <li class=“menu_nav”> <a href=“/backend/menus”> <span class=“icon16 icomoon-icon-menu-2”></span>Menu </a> <a href=“/backend/menus/new”> <span class=“icon14 icomoon-icon-plus”></span> </a> </li>.
Instance Method Details
#bt(title, from_modal_name = nil) ⇒ Object
Translate methods
8 9 10 |
# File 'app/helpers/mokio/backend/backend_helper.rb', line 8 def bt( title, from_modal_name = nil ) t( from_modal_name.nil? ? "backend.#{title}" : "#{from_modal_name.to_s.tableize}.#{title}".gsub("mokio/", "") ) end |
#btc(title, from_modal_name = nil) ⇒ Object
12 13 14 |
# File 'app/helpers/mokio/backend/backend_helper.rb', line 12 def btc( title, from_modal_name = nil ) bt(title, from_modal_name).capitalize end |
#bts(title) ⇒ Object
Sidebar button translate method
19 20 21 |
# File 'app/helpers/mokio/backend/backend_helper.rb', line 19 def bts(title) bt(title, "backend.sidebar") end |
#can_manage_site_elements? ⇒ Boolean
Can user manage any site elements
105 106 107 108 109 110 111 112 113 114 |
# File 'app/helpers/mokio/backend/backend_helper.rb', line 105 def can_manage_site_elements? ( (can? :manage, Mokio::StaticModule) || (can? :create, Mokio::StaticModule) || (can? :manage, Mokio::ModulePosition) || (can? :create, Mokio::ModulePosition) || (can? :manage, Mokio::ExternalScript) || (can? :create, Mokio::ExternalScript) ) end |
#engine_root ⇒ Object
23 24 25 |
# File 'app/helpers/mokio/backend/backend_helper.rb', line 23 def engine_root Mokio::Engine.routes.url_helpers.root_path end |
#generate_tableize_name(type) ⇒ Object
return table name for type
117 118 119 120 121 |
# File 'app/helpers/mokio/backend/backend_helper.rb', line 117 def generate_tableize_name(type) type.gsub!("Mokio::","") type.gsub!("::","_") if(type.include? "::") type.tableize end |
#render_backend_input_active(f) ⇒ Object
137 138 139 |
# File 'app/helpers/mokio/backend/backend_helper.rb', line 137 def render_backend_input_active(f) render_backend_input_active_checkbox(f,'active') end |
#render_backend_input_active_checkbox(f, name) ⇒ Object
145 146 147 |
# File 'app/helpers/mokio/backend/backend_helper.rb', line 145 def render_backend_input_active_checkbox(f,name) f.input name.to_sym,:wrapper => :active_checkbox, disabled: !obj.display_editable_field?("#{name}") end |
#render_backend_input_home_page(f) ⇒ Object
141 142 143 |
# File 'app/helpers/mokio/backend/backend_helper.rb', line 141 def render_backend_input_home_page(f) render_backend_input_active_checkbox(f,'home_page') end |
#render_backend_input_lang_id(f) ⇒ Object
COMMON INPUTS HELPERS
133 134 135 |
# File 'app/helpers/mokio/backend/backend_helper.rb', line 133 def render_backend_input_lang_id(f) f.input :lang_id, collection: Mokio::Lang.all.collect{|lang| [bt(lang.name), lang.id]},include_blank: bt('all'), disabled: !obj.display_editable_field?('lang_id'),wrapper: :select2 end |
#set_sorting_param(obj_class) ⇒ Object
123 124 125 126 127 128 129 |
# File 'app/helpers/mokio/backend/backend_helper.rb', line 123 def set_sorting_param(obj_class) if obj_class.respond_to? :default_datatable_sorting obj_class.default_datatable_sorting else [[0, 'asc']] end end |
#sidebar_btn(type, icon_class, label = "", add_btn = true, check_permissions = true, plus_icon_class = "icomoon-icon-plus") ⇒ Object
Generate sidebar button
Examples
For sidebar_btn Mokio::Menu, "icomoon-icon-menu-2"
it generates:
<li class="menu_nav">
<a href="/backend/menus">
<span class="icon16 icomoon-icon-menu-2"></span>Menu
</a>
<a href="/backend/menus/new">
<span class="icon14 icomoon-icon-plus"></span>
</a>
</li>
For sidebar_btn Mokio::Menu, "icomoon-icon-menu-2", false
it generates:
<li class="menu_nav">
<a href="/backend/menus">
<span class="icon16 icomoon-icon-menu-2"></span>Menu
</a>
</li>
Attributes
-
type
- Item type i.e. Mokio::Menu -
label
- Item label. I.e if empty? for Mokio::Menu =>bts("menu" )
-
icon_class
- Icon css class i.e. “icomoon-icon-earth” -
add_btn
- Determines whether generate “+” button -
check_permissions
- Determines whether check permissionsi.e.(can? : manage, Mokio::Menu)
-
plus_icon_class
Icon css class for “+” button
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 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/helpers/mokio/backend/backend_helper.rb', line 57 def (type, icon_class, label="", add_btn = true, = true, plus_icon_class = "icomoon-icon-plus") table = generate_tableize_name(type.to_s) #Mokio::Menu => menus or Mokio::MyModule::Menu => mymodule_menus model = table.singularize#Mokio::Menu => menu if label.empty? label = bts(model) end create_btn = add_btn manage_btn = true can_manage = can? :manage, type can_create = can? :create, type if unless can_manage manage_btn &&= false end unless can_create create_btn &&= false end end html = "" if create_btn || manage_btn # we always add manage btn html << "<li class='#{model}_nav'>" manage_path = send(table + "_path") html << <<-HTML <a href="#{manage_path}"> <span class="icon16 #{icon_class}"></span>#{label} </a> HTML if create_btn create_path = send("new_" + model + "_path") html << <<-HTML <a href="#{create_path}"> <span class="icon14 #{plus_icon_class}"></span> </a> HTML end html << "</li>" end html.html_safe end |