From 64c6a43f12021f48d788e805157dabf2fb8f9ff4 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 26 Jun 2014 19:09:40 +0800 Subject: [PATCH] sub menu widget for orbit 4.5 --- .../site_menu_widgets_controller.rb | 45 +++++++++++++++++++ lib/site_menu_widget/engine.rb | 6 +++ 2 files changed, 51 insertions(+) create mode 100644 app/controllers/site_menu_widgets_controller.rb diff --git a/app/controllers/site_menu_widgets_controller.rb b/app/controllers/site_menu_widgets_controller.rb new file mode 100644 index 0000000..e137db1 --- /dev/null +++ b/app/controllers/site_menu_widgets_controller.rb @@ -0,0 +1,45 @@ +class SiteMenuWidgetsController < ApplicationController + + def widget + pages = Page.root.child_pages_enabled_for_sitemap + def create_json(pages) + items = [] + pages.each do |page| + item = {} + if page.child_page.size > 0 + if page.page_type == "page" + item["page_name"] = page.name + item["url"] = "/#{locale.to_s}" + page.url + item["children"] = create_json(page.sorted_published_child_pages) + item["target"] = "_self" + else + item["page_name"] = page.name + item["url"] = "/#{locale.to_s}" + page.url + item["children"] = create_json(page.sorted_published_child_pages) + 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 + item["target"] = "_blank" + item["children"] = [] + end + end + items << item + end + items + end + items = create_json(pages) + { + "pages" => items, + "extras" => {"widget_title" => "Sub Menu"} + } + + end +end \ No newline at end of file diff --git a/lib/site_menu_widget/engine.rb b/lib/site_menu_widget/engine.rb index a5bf3dc..40c975a 100644 --- a/lib/site_menu_widget/engine.rb +++ b/lib/site_menu_widget/engine.rb @@ -1,4 +1,10 @@ module SiteMenuWidget class Engine < ::Rails::Engine + initializer "site_menu_widget" do + OrbitApp.registration "SiteMenuWidget", :type => "OrbitWidget" do + widget_label "SiteMenu" + widget_methods ["widget"] + end + end end end