2014-06-26 11:09:40 +00:00
|
|
|
class SiteMenuWidgetsController < ApplicationController
|
2020-01-18 16:31:39 +00:00
|
|
|
def create_json(pages)
|
|
|
|
items = []
|
|
|
|
pages.each do |page|
|
|
|
|
item = {}
|
|
|
|
item["obj"] = page
|
|
|
|
if page.child_page.size > 0
|
|
|
|
item["page_name"] = page.name
|
|
|
|
item["children"] = create_json(page.sorted_published_child_pages)
|
|
|
|
if page.page_type == "page" or page.page_type == "link"
|
|
|
|
item["url"] = (page.page_type == "link") ? "/#{locale.to_s}" + page.external_url : "/#{locale.to_s}" + page.url
|
|
|
|
item["target"] = "_self"
|
|
|
|
else
|
|
|
|
item["url"] = "/#{locale.to_s}" + page.url
|
|
|
|
item["target"] = "_blank"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
item["page_name"] = page.name
|
|
|
|
item["children"] = []
|
|
|
|
if page.page_type == "page"
|
|
|
|
item["url"] = "/#{locale.to_s}" + page.url
|
|
|
|
item["target"] = "_self"
|
|
|
|
else
|
|
|
|
item["url"] = page.external_url
|
|
|
|
item["target"] = (is_internal_url?(page.external_url) ? "_self" : "_blank") rescue "_blank"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
items << item
|
|
|
|
end
|
|
|
|
items
|
|
|
|
end
|
|
|
|
def create_menu_bool_object (items)
|
|
|
|
#item_all = []
|
|
|
|
items.each do |item1|
|
|
|
|
#item = []
|
|
|
|
@count += 1
|
|
|
|
if (!item1["children"].nil? && item1["children"].length!=0)
|
2020-01-21 09:37:25 +00:00
|
|
|
@count1 += 1
|
|
|
|
if (@expand_current_layer && children_is_current(item1['obj'])) || (@expand_next_layer && item1['obj'].id == @page_id)
|
|
|
|
@ul_index << [@count1, @count]
|
2020-01-18 16:31:39 +00:00
|
|
|
end
|
|
|
|
create_menu_bool_object(item1['children'])
|
|
|
|
#item = [children_is_current(item1['obj']),item1['obj'].id==@page_id,create_menu_bool_object(item1['children'])]
|
|
|
|
else
|
|
|
|
#item = [children_is_current(item1['obj']),item1['obj'].id==@page_id]
|
|
|
|
end
|
|
|
|
#item_all << item
|
|
|
|
end
|
|
|
|
#item_all
|
|
|
|
end
|
|
|
|
def children_is_current (page)
|
|
|
|
page.sorted_published_child_pages.select{|v| v.id==@page_id}.length!=0 rescue false
|
|
|
|
end
|
2014-06-26 11:09:40 +00:00
|
|
|
def widget
|
2020-01-18 16:31:39 +00:00
|
|
|
subpart = OrbitHelper.get_current_widget
|
2014-06-30 07:08:29 +00:00
|
|
|
params = OrbitHelper.params
|
|
|
|
page = Page.where(:page_id => params[:page_id]).first
|
2020-01-18 16:31:39 +00:00
|
|
|
@page_id = page.id
|
|
|
|
@expand_layer = false
|
2020-01-21 09:37:25 +00:00
|
|
|
@expand_next_layer = false
|
|
|
|
@expand_current_layer = false
|
2014-07-19 20:17:21 +00:00
|
|
|
if page.parent_page == Page.root
|
2020-01-18 16:31:39 +00:00
|
|
|
@pages = page.sorted_published_child_pages
|
2014-07-19 20:17:21 +00:00
|
|
|
else
|
2020-01-18 16:31:39 +00:00
|
|
|
@pages = page.parent_page.sorted_published_child_pages
|
|
|
|
if subpart.methods.include? 'select_options'.to_sym
|
|
|
|
OrbitWidget.all.select{|tmp| tmp.key.to_s=='site_menu_widget'}.each do |orbit_widget|
|
|
|
|
@show_options = orbit_widget.show_options rescue nil
|
|
|
|
end
|
|
|
|
subpart.select_options.each do |select_option|
|
|
|
|
if !(@show_options.nil?) && select_option.field_name == @show_options.keys.first.to_s
|
|
|
|
value = YAML.load(select_option.value)
|
|
|
|
if value[I18n.locale] == t('site_menu.yes')
|
|
|
|
if page.parent_page.parent_page == Page.root
|
|
|
|
@pages = Array(page.parent_page)
|
|
|
|
else
|
|
|
|
@pages = page.parent_page.parent_page.sorted_published_child_pages
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elsif !(@show_options.nil?) && select_option.field_name == @show_options.keys[1].to_s
|
|
|
|
value = YAML.load(select_option.value)
|
|
|
|
if value[I18n.locale] == t('site_menu.yes')
|
|
|
|
@expand_layer = true
|
2020-01-21 09:37:25 +00:00
|
|
|
@expand_current_layer = true
|
|
|
|
end
|
|
|
|
elsif !(@show_options.nil?) && select_option.field_name == @show_options.keys[2].to_s
|
|
|
|
value = YAML.load(select_option.value)
|
|
|
|
if value[I18n.locale] == t('site_menu.yes')
|
|
|
|
@expand_layer = true
|
|
|
|
@expand_next_layer = true
|
2020-01-18 16:31:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-12-24 01:22:21 +00:00
|
|
|
end
|
|
|
|
end
|
2020-01-18 16:31:39 +00:00
|
|
|
@ul_index=[]
|
|
|
|
@count = -1
|
2020-01-21 10:21:24 +00:00
|
|
|
@count1 = -1
|
2020-01-21 09:37:25 +00:00
|
|
|
@li_index = []
|
2020-01-18 16:31:39 +00:00
|
|
|
title = subpart.title
|
|
|
|
items = create_json(@pages)
|
2020-01-21 09:37:25 +00:00
|
|
|
if @expand_layer
|
|
|
|
create_menu_bool_object(items)
|
2020-01-18 16:31:39 +00:00
|
|
|
temp = @ul_index.reverse.collect do |ul_index|
|
2020-01-21 10:21:24 +00:00
|
|
|
"var ul_tp = $('div[data-subpart-id=#{subpart.id}]').find('ul.dropdown-menu').eq(#{ul_index[0]})
|
2020-01-21 09:37:25 +00:00
|
|
|
ul_tp.removeClass('dropdown-menu')
|
|
|
|
$('div[data-subpart-id=#{subpart.id}]').find('li').eq(#{ul_index[1]}).find('span').eq(0).remove()
|
|
|
|
"
|
|
|
|
end
|
2020-01-18 16:31:39 +00:00
|
|
|
if temp.length != 0
|
|
|
|
temp = temp.join(' ')
|
|
|
|
expand_script = "<script type='text/javascript'>" +
|
|
|
|
"$('div[data-subpart-id=#{subpart.id}]').ready(function(){" +
|
|
|
|
temp + '})'+
|
2020-11-19 06:55:09 +00:00
|
|
|
"</script>
|
|
|
|
<style>.widget-breadcrumb.widget1.no-print ul li a br { display: none;}</style>"
|
2020-01-18 16:31:39 +00:00
|
|
|
else
|
2020-11-19 06:55:09 +00:00
|
|
|
expand_script = '<style>.widget-breadcrumb.widget1.no-print ul li a br { display: none;}</style>'
|
2014-06-26 11:09:40 +00:00
|
|
|
end
|
2020-01-18 16:31:39 +00:00
|
|
|
else
|
|
|
|
expand_script=""
|
2014-06-26 11:09:40 +00:00
|
|
|
end
|
|
|
|
{
|
|
|
|
"pages" => items,
|
2020-01-18 16:31:39 +00:00
|
|
|
"extras" => {"widget_title" => title.to_s,"expand-script"=>expand_script}
|
2014-06-26 11:09:40 +00:00
|
|
|
}
|
2014-12-18 08:41:34 +00:00
|
|
|
|
2014-06-26 11:09:40 +00:00
|
|
|
end
|
2015-10-28 10:57:02 +00:00
|
|
|
|
|
|
|
def is_internal_url?(link)
|
|
|
|
internal = false
|
|
|
|
if !link.nil?
|
|
|
|
link = link.split("?").first
|
|
|
|
temp_url = URI.parse(link)
|
|
|
|
if temp_url.host.nil?
|
|
|
|
internal = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return internal
|
|
|
|
end
|
|
|
|
end
|