2014-06-26 11:09:40 +00:00
|
|
|
class SiteMenuWidgetsController < ApplicationController
|
|
|
|
|
|
|
|
def widget
|
2014-06-30 07:08:29 +00:00
|
|
|
params = OrbitHelper.params
|
|
|
|
page = Page.where(:page_id => params[:page_id]).first
|
2014-07-19 20:17:21 +00:00
|
|
|
if page.parent_page == Page.root
|
|
|
|
pages = page.sorted_published_child_pages
|
|
|
|
else
|
2014-07-29 02:09:49 +00:00
|
|
|
pages = page.parent_page.sorted_published_child_pages
|
2014-07-19 20:17:21 +00:00
|
|
|
end
|
2014-12-24 01:22:21 +00:00
|
|
|
|
|
|
|
page.page_parts.collect do |pp|
|
|
|
|
pp.sub_parts.collect do |sp|
|
|
|
|
@title = sp.title if sp.module == "site_menu_widget"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-26 11:09:40 +00:00
|
|
|
def create_json(pages)
|
|
|
|
items = []
|
|
|
|
pages.each do |page|
|
|
|
|
item = {}
|
|
|
|
if page.child_page.size > 0
|
2014-07-19 20:17:21 +00:00
|
|
|
if page.page_type == "page" or page.page_type == "link"
|
2014-06-26 11:09:40 +00:00
|
|
|
item["page_name"] = page.name
|
2014-07-19 20:17:21 +00:00
|
|
|
item["url"] = (page.page_type == "link") ? "/#{locale.to_s}" + page.external_url : "/#{locale.to_s}" + page.url
|
2014-07-29 02:09:49 +00:00
|
|
|
item["children"] = create_json(page.sorted_published_child_pages)
|
2014-06-26 11:09:40 +00:00
|
|
|
item["target"] = "_self"
|
|
|
|
else
|
|
|
|
item["page_name"] = page.name
|
|
|
|
item["url"] = "/#{locale.to_s}" + page.url
|
2014-07-29 02:09:49 +00:00
|
|
|
item["children"] = create_json(page.sorted_published_child_pages)
|
2014-06-26 11:09:40 +00:00
|
|
|
item["target"] = "_blank"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if page.page_type == "page"
|
|
|
|
item["page_name"] = page.name
|
|
|
|
item["url"] = "/#{locale.to_s}" + page.url
|
|
|
|
item["target"] = "_self"
|
|
|
|
item["children"] = []
|
|
|
|
else
|
|
|
|
item["page_name"] = page.name
|
|
|
|
item["url"] = page.external_url
|
2015-10-28 10:57:02 +00:00
|
|
|
item["target"] = (is_internal_url?(page.external_url) ? "_self" : "_blank") rescue "_blank"
|
2014-06-26 11:09:40 +00:00
|
|
|
item["children"] = []
|
|
|
|
end
|
|
|
|
end
|
|
|
|
items << item
|
|
|
|
end
|
|
|
|
items
|
|
|
|
end
|
2014-12-24 01:22:21 +00:00
|
|
|
|
|
|
|
|
2014-06-26 11:09:40 +00:00
|
|
|
items = create_json(pages)
|
|
|
|
{
|
|
|
|
"pages" => items,
|
2014-12-24 01:22:21 +00:00
|
|
|
"extras" => {"widget_title" => @title}
|
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
|