module Mokio
module Backend
module BackendHelper
include Haml::Helpers
#
# Translate methods
#
def bt( title, from_modal_name = nil )
t( from_modal_name.nil? ? "backend.#{title}" : "#{from_modal_name.to_s.tableize}.#{title}".gsub("mokio/", "") )
end
def btc( title, from_modal_name = nil )
bt(title, from_modal_name).capitalize
end
#
# Sidebar button translate method
#
def bts(title)
bt(title, "backend.sidebar")
end
def engine_root
Mokio::Engine.routes.url_helpers.root_path
end
# Generate sidebar button
# ==== Examples
# For sidebar_btn Mokio::Menu, "icomoon-icon-menu-2"
# it generates:
#
sidebar_btn Mokio::Menu, "icomoon-icon-menu-2", false
# it generates:
# bts("menu" )
# * +icon_class+ - Icon css class i.e. "icomoon-icon-earth"
# * +add_btn+ - Determines whether generate "+" button
# * +check_permissions+ - Determines whether check permissions
# i.e.(can? : manage, Mokio::Menu)
# * +plus_icon_class+ Icon css class for "+" button
def sidebar_btn(type, icon_class, label="", add_btn = true, check_permissions = true, plus_icon_class = "icomoon-icon-plus")
table = type.to_s.demodulize.tableize #Mokio::Menu => 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 check_permissions
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 << "