2012-02-04 01:10:55 +00:00
|
|
|
module Locomotive
|
|
|
|
module BaseHelper
|
|
|
|
|
|
|
|
def title(title = nil)
|
|
|
|
if title.nil?
|
|
|
|
@content_for_title
|
|
|
|
else
|
|
|
|
@content_for_title = title
|
|
|
|
''
|
|
|
|
end
|
2010-06-03 15:32:40 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def inputs_folded?(resource)
|
|
|
|
resource.persisted? && resource.errors.empty?
|
|
|
|
end
|
2011-11-16 12:42:42 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def submenu_entry(name, url, options = {}, &block)
|
|
|
|
default_options = { :i18n => true, :css => name.dasherize.downcase }
|
|
|
|
default_options.merge!(options)
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
css = "#{'on' if name == sections(:sub)} #{options[:css]}"
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
label_link = default_options[:i18n] ? t("locomotive.shared.menu.#{name}") : name
|
|
|
|
if block_given?
|
|
|
|
popup = content_tag(:div, capture(&block), :class => 'popup', :style => 'display: none')
|
|
|
|
link = link_to(content_tag(:span, preserve(label_link) + content_tag(:em)) + content_tag(:em), url, :class => css)
|
|
|
|
content_tag(:li, link + popup, :class => 'hoverable')
|
|
|
|
else
|
|
|
|
content_tag(:li, link_to(content_tag(:span, label_link), url, :class => css))
|
|
|
|
end
|
2010-05-26 00:41:10 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def local_action_button(text, url, options = {})
|
|
|
|
text = text.is_a?(Symbol) ? t(".#{text}") : text
|
|
|
|
link_to(url, options) do
|
|
|
|
content_tag(:em, escape_once(' ')) + text
|
|
|
|
end
|
2011-11-08 14:34:25 +00:00
|
|
|
end
|
2011-07-25 21:07:32 +00:00
|
|
|
|
2012-02-09 10:36:10 +00:00
|
|
|
def locale_picker_link
|
|
|
|
if current_site.locales.size > 1 && localized?
|
|
|
|
content_tag :div, render('locomotive/shared/locale_picker_link'), :class => 'action'
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def flash_message
|
|
|
|
if not flash.empty?
|
|
|
|
first_key = flash.keys.first
|
|
|
|
content_tag :div, flash[first_key],
|
|
|
|
:id => "flash-#{first_key}",
|
|
|
|
:class => 'application-message'
|
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
2011-11-04 15:55:51 +00:00
|
|
|
end
|
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def backbone_view_class_name
|
|
|
|
action = case controller.action_name
|
|
|
|
when 'create' then 'New'
|
|
|
|
when 'update' then 'Edit'
|
|
|
|
else
|
|
|
|
controller.action_name
|
|
|
|
end.camelize
|
2011-11-21 01:27:05 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
"Locomotive.Views.#{controller.controller_name.camelize}.#{action}View"
|
|
|
|
end
|
2011-11-21 01:27:05 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def backbone_view_data
|
|
|
|
content_for?(:backbone_view_data) ? content_for(:backbone_view_data) : ''
|
|
|
|
end
|
2011-11-21 01:27:05 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def nocoffee_tag
|
|
|
|
link_to 'noCoffee', 'http://www.nocoffee.fr', :id => 'nocoffee'
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
# sites
|
2011-11-03 13:01:08 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def application_domain
|
|
|
|
domain = Locomotive.config.domain
|
|
|
|
domain += ":#{request.port}" if request.port != 80
|
|
|
|
domain
|
|
|
|
end
|
2011-11-03 13:01:08 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def manage_subdomain_or_domains?
|
|
|
|
Locomotive.config.manage_subdomain? || Locomotive.config.manage_domains?
|
|
|
|
end
|
2011-11-03 13:01:08 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def manage_subdomain?
|
|
|
|
Locomotive.config.manage_subdomain?
|
|
|
|
end
|
2011-11-03 13:01:08 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def manage_domains?
|
|
|
|
Locomotive.config.manage_domains?
|
|
|
|
end
|
2011-11-03 13:01:08 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def multi_sites?
|
|
|
|
Locomotive.config.multi_sites?
|
|
|
|
end
|
2011-11-03 13:01:08 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def public_page_url(page, options = {})
|
|
|
|
if content = options.delete(:content)
|
|
|
|
File.join(current_site_public_url, page.fullpath.gsub('content_type_template', ''), content._slug)
|
|
|
|
else
|
|
|
|
File.join(current_site_public_url, page.fullpath)
|
|
|
|
end
|
2011-11-10 21:41:20 +00:00
|
|
|
end
|
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
# memberships
|
2011-11-29 13:58:19 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
def options_for_membership_roles(options = {})
|
|
|
|
list = (unless options[:skip_admin]
|
|
|
|
Locomotive::Ability::ROLES.map { |r| [t("locomotive.memberships.roles.#{r}"), r] }
|
|
|
|
else
|
|
|
|
(Locomotive::Ability::ROLES - ['admin']).map { |r| [t("locomotive.memberships.roles.#{r}"), r] }
|
|
|
|
end)
|
2011-11-29 13:58:19 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
options_for_select(list)
|
|
|
|
end
|
2011-11-29 13:58:19 +00:00
|
|
|
|
2011-11-10 21:41:20 +00:00
|
|
|
|
2012-02-04 01:10:55 +00:00
|
|
|
end
|
|
|
|
end
|