orbit4-5/app/helpers/orbit_helper.rb

311 lines
7.6 KiB
Ruby
Raw Normal View History

2014-04-01 07:10:21 +00:00
module OrbitHelper
2014-04-21 02:48:36 +00:00
def self.set_params(params)
@params = params
end
def self.set_page_categories(categories)
@categories = categories;
end
2014-07-11 13:12:08 +00:00
def self.set_page_tags(tags)
@tags = tags;
end
def self.set_page_data_count(data_count)
@data_count = data_count
end
def self.page_data_count
@data_count
end
def self.set_page_number(page)
@page_number = page
if @page_number == 0
@page_number = 1
end
end
def self.page_number
@page_number || 1
end
def self.page_categories
@categories
end
2014-07-11 13:12:08 +00:00
def self.page_tags
@tags
end
def self.page_for_tag(tag)
page_for_tag = nil
pages = Page.where(:module => @module_app.key)
pages.each do |page|
if page.tags.count ==1
if page.tags.include?(tag)
page_for_tag = page
end
end
break if !page_for_tag.nil?
end
if page_for_tag.nil?
pages.each do |page|
if page.tags.include?(tag)
page_for_tag = page
end
break if !page_for_tag.nil?
end
end
page_for_tag = pages.first if page_for_tag.nil?
'/'+I18n.locale.to_s+page_for_tag.url+'?tags[]='+tag.id.to_s
end
def self.this_module_app
@module_app
end
def self.widget_module_app
@widget_module_app
end
def self.set_this_module_app(module_app)
@module_app = ModuleApp.where(:key=>module_app).first
end
def self.set_widget_custom_value(value)
@widget_custom_value = value
end
def self.widget_custom_value
@widget_custom_value
end
def self.set_widget_module_app(module_app)
@widget_module_app = ModuleApp.where(:key=>module_app).first
end
def self.set_widget_title(title)
@widget_title = title
end
def self.widget_title
@widget_title
end
2014-07-11 13:12:08 +00:00
def self.set_widget_tags(tags)
@tags = tags;
end
def self.widget_tags
@tags
end
def self.params
2014-04-21 02:48:36 +00:00
@params
end
def self.url_to_show(slug)
if @params[:url]
"/#{@site_locale}#{@params[:url]}/#{slug}"
else
page = Page.where(:module => self.current_widget_module).first
"/#{@site_locale}#{page.url}/#{slug}"
end
end
2014-07-02 09:37:34 +00:00
def self.url_to_plugin_show(slug,module_app)
page = Page.find_by(:module => module_app) rescue ""
2014-07-04 03:50:08 +00:00
@url_to_plugin_show = "#{page.url}/#{slug}" rescue "#"
2014-07-02 09:37:34 +00:00
end
def self.set_widget_item_url(widget)
@url_widget_for_show = ""
module_app = widget.module
pages = Page.where(:module => module_app)
widget_categories = widget.categories
finalpage = nil
pages.each do |p|
if p.categories == widget_categories
finalpage = p
end
break if !finalpage.nil?
end
if finalpage.nil?
pages.each do |p|
if self.array_include(p.categories, widget_categories)
finalpage = p
end
break if !finalpage.nil?
end
end
finalpage = pages.first if finalpage.nil?
if !finalpage.nil?
@url_widget_for_show = "/#{@site_locale.to_s}#{finalpage.url}"
end
end
def self.array_include(arr1,arr2)
final = []
arr2.each do |el|
final.push(arr1.include?el)
end
!final.include?false
end
def self.widget_item_url(obj)
@url_widget_for_show + "/" + obj
end
def self.widget_more_url
@url_widget_for_show
end
2014-04-21 02:48:36 +00:00
def page_url(url)
"#{request.host_with_port}/#{locale}#{url}"
end
def self.set_site_locale(locale)
@site_locale = locale
end
def self.set_widget_data_count(data_count)
@widget_data_count = data_count
end
def self.widget_data_count
@widget_data_count
end
def self.set_widget_categories(categories)
@widget_categories = categories
end
def self.widget_categories
@widget_categories
end
2014-04-21 02:48:36 +00:00
def self.get_site_locale
@site_locale
end
def self.current_widget_module
@controller_name
end
def self.set_current_widget_module(name)
@controller_name = name
end
def get_item_module_infos(page)
if page.parent_page_id.nil?
["Home","icons-house"]
else
module_app = ModuleApp.where(:key => page.module).first
unless module_app.nil?
[module_app.title, (module_app.get_registration.icon_class || module_app.get_registration.get_icon_class_no_sidebar)]
else
if page.module.eql? "sitemap"
["sitemap", "icons-directions"]
else
["", "icon-minus-sign"]
end
end
2014-04-21 02:48:36 +00:00
end
end
2014-05-15 11:32:51 +00:00
def self.orbit_impressionist(object)
impressionist(object)
end
2014-05-29 10:32:27 +00:00
def self.is_mobile_view
!$mobile.blank?
end
2014-04-21 02:48:36 +00:00
# ===============================================================
# Breadcrumbs
# ===============================================================
def back_end_breadcrumb
res = ''
divider = "<span class='divider'>/</span>"
res << "<li><a href='#{admin_dashboards_path}'>#{t(:dashboard_)}</a>#{divider}</li>"
case controller.controller_name
when 'authorizations'
res << "<li><a href='/#{params[:controller]}/#{@module_app.key}'>#{@module_app.title}</a>#{divider}</li>"
case params[:type]
when 'approval'
res << "<li class='active'>#{t(:approval_)}</li>"
when 'category'
res << "<li class='active'>#{t(:category_auth)}</li>"
when nil
res << "<li class='active'>#{t(:module_authorization)}</li>"
else
res << "<li class='active'>#{params[:type].underscore.humanize.capitalize} #{t(:authorization_)}</li>"
end
when 'categories'
2014-05-12 08:18:35 +00:00
if @module_app.key!='category'
res << "<li>#{@module_app.title}#{divider}</li>"
res << "<li class='active'>#{t(:categories)}</li>"
else
res << "<li class='active'>#{@module_app.title}</li>"
end
when 'tags'
if @module_app.key!='tag'
res << "<li>#{@module_app.title}#{divider}</li>"
res << "<li class='active'>#{t(:tags)}</li>"
else
res << "<li class='active'>#{@module_app.title}</li>"
end
2014-04-21 02:48:36 +00:00
else
if params[:action].eql?('index')
res << "<li>#{@module_app.title}</li>"
else
res << "<li><a href='/#{params[:controller]}'>#{@module_app.title}</a>#{divider}</li>"
res << "<li class='active'>#{t(params[:action], scope: 'restful_actions')}</li>"
end
end
res.html_safe
end
def site_breadcrumb
res = ''
divider = "<span class='divider'>/</span>"
res << "<li>#{t(:settings)}#{divider}</li>"
site = Site.first
case controller.controller_name
when 'sites'
case controller.action_name
when 'sitemap'
res << "<li class='active'>#{t(:sitemap)}</li>"
when 'responsive_setting'
res << "<li class='active'>#{t(:mobile_settings)}</li>"
when 'mail_setting'
res << "<li class='active'>#{t(:mail_setting)}</li>"
when 'preference'
res << "<li class='active'>#{t(:preference)}</li>"
when 'search_engine'
res << "<li class='active'>#{t(:search_engine)}</li>"
when 'site_info'
res << "<li class='active'>#{t(:site_info)}</li>"
when 'update_manager'
res << "<li class='active'>#{t(:update_manager)}</li>"
when 'system_info'
res << "<li class='active'>#{t("site.system_preference")}</li>"
end
when 'items'
res << "<li class='active'>#{t(:structure)}</li>"
when 'module_store'
res << "<li class='active'>#{t(:modules)}</li>"
when 'designs'
res << "<li class='active'>#{t(:templates)}</li>"
end
res.html_safe
end
def active_when_current_locale_eq(locale)
locale.to_sym == I18n.locale ? 'active in': ''
end
2014-04-01 07:10:21 +00:00
end