sidebar rewrited

This commit is contained in:
Matthew K. Fu JuYuan 2012-12-05 18:35:58 +08:00
parent ca290f3519
commit 99f28a0cba
14 changed files with 395 additions and 16 deletions

View File

@ -4,7 +4,10 @@
<% content_for :page_specific_javascript do %> <% content_for :page_specific_javascript do %>
<%= javascript_include_tag "/static/kernel.js" %> <%= javascript_include_tag "/static/kernel.js" %>
<% end %> <% end %>
<%=OrbitApp::Module::SideBarRegisition.all.first.render(request,params,current_user,@module_app) %>
<%OrbitApp::Module::SideBarRegisition.all.each do |t| %>
<%= t.render(request,params,current_user,@module_app) %>
<% end %>
<div class="content"> <div class="content">
<% flash.each do |key, msg| %> <% flash.each do |key, msg| %>

View File

@ -1,11 +1,12 @@
module ContextLinkRenderer module ContextLinkRenderer
include Renderer include Renderer
def render(request,params,module_app,user) def render(request,params,current_module_app,current_user,belong_module_app)
@module_app = module_app @current_module_app = current_module_app
@belong_module_app = belong_module_app
@request = request @request = request
@params = params @params = params
@current_user = user @current_user = current_user
if display? if display?
content_tag :li, link_to((I18n.t(@label_i18n) + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, eval(@path)), :class => (active? ? 'active' : nil) content_tag :li, link_to((I18n.t(@label_i18n) + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, eval(@path)), :class => (active? ? 'active' : nil)
end end
@ -18,9 +19,9 @@ protected
when :all when :all
true true
when :manager when :manager
@module_app.is_manager? @current_user @belong_module_app.is_manager? @current_user
when :sub_manager when :sub_manager
@module_app.is_sub_manager? @current_user @belong_module_app.is_sub_manager? @current_user
else else
(eval(available_for_in_sym).include? @current_user rescue false) (eval(available_for_in_sym).include? @current_user rescue false)
end # of case end # of case

View File

@ -2,8 +2,9 @@ module SideBarRenderer
include Renderer include Renderer
include AdminHelper include AdminHelper
def render(request,params,user,module_app) def render(request,params,user,current_module_app)
@module_app = module_app @belong_module_app = get_module_app
@current_module_app = current_module_app
@request = request @request = request
@params = params @params = params
@current_user = user @current_user = user
@ -12,7 +13,7 @@ module SideBarRenderer
buf = link_to( content_tag(:i, nil, :class => @icon_class ) + content_tag(:span, I18n.t( @head_label )), eval(@head_link)) buf = link_to( content_tag(:i, nil, :class => @icon_class ) + content_tag(:span, I18n.t( @head_label )), eval(@head_link))
buf << content_tag( :ul, :class => ("nav nav-list active") )do # visible_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals')||active_for_ob_auths_object("BulletinCategory")) buf << content_tag( :ul, :class => ("nav nav-list active") )do # visible_for_controllers('bulletins', '/panel/announcement/back_end/tags', 'bulletin_categorys', 'approvals')||active_for_ob_auths_object("BulletinCategory"))
@context_links.sort_by! {| obj | obj.priority}.collect do |link| @context_links.sort_by! {| obj | obj.priority}.collect do |link|
link.render(request,params,@module_app,@current_user) link.render(request,params,@current_module_app,@current_user,@belong_module_app)
end.join.html_safe end.join.html_safe
end end
end end
@ -24,7 +25,7 @@ module SideBarRenderer
def display? #控制sidebar 要不要算圖 def display? #控制sidebar 要不要算圖
if is_manager? || is_admin? #如果是系統管理員 或 是模組管理員 if is_manager? || is_admin? #如果是系統管理員 或 是模組管理員
true true
elsif (@module_app.open rescue false) # 如果app 被設定成 開放 elsif (@current_module_app.open rescue false) # 如果app 被設定成 開放
true true
elsif is_member? #如果app 是封閉 那至少需要是 member elsif is_member? #如果app 是封閉 那至少需要是 member
true true

View File

@ -39,8 +39,12 @@ module OrbitApp
setup_module_app setup_module_app
end end
def get_module_app
ModuleApp.first(conditions: {:key=>@key,:title=>name})
end
def setup_module_app def setup_module_app
module_app = ModuleApp.first(conditions: {:key=>@key,:title=>name}) module_app = get_module_app
module_app = ModuleApp.new(:key=>@key,:title=>name) if module_app.nil? module_app = ModuleApp.new(:key=>@key,:title=>name) if module_app.nil?
begin begin
@ -90,7 +94,7 @@ module OrbitApp
end end
def side_bar(&block) def side_bar(&block)
@side_bar = SideBarRegisition::SideBar.new(@name,@key,&block) @side_bar = SideBarRegisition::SideBar.new(@name,@key,method(:get_module_app),&block)
end end
def personal_plugin(params) def personal_plugin(params)

View File

@ -17,6 +17,10 @@ module OrbitApp
return nil return nil
end end
def render_all(request,params,user,current_module_app)
@@side_bars.collect{|t| t.render(request,params,user,current_module_app)}.join.html_safe
end
def all def all
return @@side_bars return @@side_bars
end end
@ -37,7 +41,7 @@ module OrbitApp
# def is_manager? # def is_manager?
# binding.pry # binding.pry
# end # end
def initialize(name = '',key,&block) def initialize(name = '',key,get_module_app,&block)
@head_label = name @head_label = name
@context_links = [] @context_links = []
@available_for = [] @available_for = []
@ -47,12 +51,16 @@ module OrbitApp
@head_link = "" @head_link = ""
@app_base_path = '' @app_base_path = ''
@module_app_key = key @module_app_key = key
@get_module_app = get_module_app
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
# setup_module_app(module_app_key) # setup_module_app(module_app_key)
finalize! finalize!
SideBarRegisition.add(self) SideBarRegisition.add(self)
end end
def get_module_app
@get_module_app.call
end
def head_label_i18n(var,options ={}) def head_label_i18n(var,options ={})
@head_label = var @head_label = var
@ -76,7 +84,7 @@ module OrbitApp
end end
def context_link(*var) def context_link(*var)
var[1].merge!(:module_app_key=>@module_app_key) unless @module_app_key.nil? var[1].merge!({:module_app_key=>@module_app_key,:get_module_app=>@get_module_app}) unless @module_app_key.nil?
new_context_link = ContextLink.new(*var) new_context_link = ContextLink.new(*var)
@context_links << new_context_link @context_links << new_context_link
end end
@ -126,6 +134,11 @@ module OrbitApp
@active_for_object_auth = options[:active_for_object_auth] || [] @active_for_object_auth = options[:active_for_object_auth] || []
@active_for_app_auth = options[:active_for_app_auth] || [] @active_for_app_auth = options[:active_for_app_auth] || []
@module_app_key = options[:module_app_key] @module_app_key = options[:module_app_key]
@get_module_app = options[:get_module_app]
end
def get_module_app
@get_module_app.call
end end
def active? def active?

View File

@ -0,0 +1,49 @@
module AdBanner
OrbitApp.registration "AdBanner",:type=> 'ModuleApp' do
module_label 'ad_banner.ad_banner'
base_url File.expand_path File.dirname(__FILE__)
# personal_plugin :enable => true,:path=>"panel/ad_banner/plugin/profile",:i18n=>'admin.ad_banner'
version "0.1"
organization "Rulingcom"
author "RD dep"
intro "I am intro"
update_info 'some update_info'
# front_end do
# app_page 'bulletins'
# end
# category ["BulletinCategory"]
# widgets do
# # default_widget do
# # query 'Bulletin.all'
# # image :image
# # end
# # categories_query 'BulletinCategory.all'
# # tags_query 'AdBannerTag.all'
# # customize_widget "index","ad_banner.widget.index",:fields=>["title","category","postdate"],:style=>["cu_style_1","cu_style_2","cu_style_3","cu_style_4","cu_style_5"]
# # customize_widget "bulletins_and_web_links","ad_banner.widget.bulletins_and_web_links"
# # item "index","ad_banner.widget.index",:default_template=>true,:fields=>["title","category","postdate"]
# # item "bulletins_and_web_links","ad_banner.widget.bulletins_and_web_links"
# end
side_bar do
head_label_i18n 'admin.ad_banner',:icon_class=>"icons-landscape"
available_for [:admin,:guest,:manager,:sub_manager]
active_for_controllers ({:private=>['ad_banners', 'ad_images']})
head_link_path "admin_ad_banners_path"
context_link 'module_authorization',
:link_path=>"admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {key: 'ad_banner'}))",
:priority=>6,
:active_for_app_auth => 'ad_banners',
:available_for => [:admin]
end
end
end

View File

@ -32,7 +32,7 @@ module Announcement
end end
side_bar do side_bar do
head_label_i18n 'admin.announcement',:icon_class=>"icons-announcement" head_label_i18n 'admin.announcement',:icon_class=>"icons-megaphone"
available_for [:admin,:guest,:manager,:sub_manager] available_for [:admin,:guest,:manager,:sub_manager]
active_for_controllers ({:private=>['bulletins', 'bulletin_categorys', 'approvals','tags']}) active_for_controllers ({:private=>['bulletins', 'bulletin_categorys', 'approvals','tags']})
active_for_object_auth ['BulletinCategory'] active_for_object_auth ['BulletinCategory']
@ -74,7 +74,7 @@ module Announcement
:link_path=>"admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: 'Announcement'}))", :link_path=>"admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: 'Announcement'}))",
:priority=>6, :priority=>6,
:active_for_app_auth => 'Announcement', :active_for_app_auth => 'Announcement',
:available_for => [:manager] :available_for => [:admin]
end end
end end
end end

62
vendor/built_in_modules/archive/init.rb vendored Normal file
View File

@ -0,0 +1,62 @@
module Archive
OrbitApp.registration "Archive",:type=> 'ModuleApp' do
module_label 'miss_module_i18n.archive'
base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true,:path=>"panel/archive/plugin/profile",:i18n=>'admin.archive'
version "0.1"
organization "Rulingcom"
author "RD dep"
intro "I am intro"
update_info 'some update_info'
front_end do
app_page 'archive_files'
end
widgets do
# default_widget do
# query 'Bulletin.all'
# image :image
# end
# categories_query 'BulletinCategory.all'
# tags_query 'ArchiveTag.all'
customize_widget "archive_files","archive.widget.archive_files",:style=>[]
end
side_bar do
head_label_i18n 'miss_module_i18n.archive',:icon_class=>"icons-archive"
available_for [:admin,:guest,:manager,:sub_manager]
active_for_controllers ({:private=>['archive_file_categorys'],:public=>['panel/archive/back_end/tags']})
active_for_object_auth ['BulletinCategory']
head_link_path "panel_archive_back_end_archive_files_path"
context_link 'miss_module_i18n._archive.all',
:link_path=>"panel_archive_back_end_archive_files_path" ,
:priority=>1,
:active_for_action=>{:archive_file=>:index},
:available_for => [:all]
context_link 'add',
:link_path=>"new_panel_archive_back_end_archive_file_path" ,
:priority=>2,
:active_for_action=>{:archive_file=>:new},
:available_for => [:admin]
context_link 'categories',
:link_path=>"panel_archive_back_end_archive_file_categorys_path" ,
:priority=>3,
:active_for_action=>{:archive_file_categorys=>:index},
:available_for => [:manager]
context_link 'tags',
:link_path=>"panel_archive_back_end_tags_path" ,
:priority=>4,
# :active_for_action=>{:bulletin_categorys=>:index},
:available_for => [:admin]
end
end
end

View File

@ -0,0 +1,34 @@
module Calendar
OrbitApp.registration "Calendar",:type=> 'ModuleApp' do
module_label 'miss_module_i18n.calendar'
base_url File.expand_path File.dirname(__FILE__)
# personal_plugin :enable => true,:path=>"panel/calendar/plugin/profile",:i18n=>'admin.calendar'
version "0.1"
organization "Rulingcom"
author "RD dep"
intro "I am intro"
update_info 'some update_info'
side_bar do
head_label_i18n 'miss_module_i18n.calendar',:icon_class=>"icons-calendar"
available_for [:admin,:guest,:manager,:sub_manager]
active_for_controllers ({:private=>['cals','calendar_categories'],:public=>['panel/calendar/back_end/tags']})
head_link_path "panel_calendar_back_end_cals_path"
context_link 'calendar.calendars',
:link_path=>"new_panel_calendar_back_end_cal_path" ,
:priority=>1,
:active_for_action=>{:cals=>:new},
:available_for => [:manager]
context_link 'tags',
:link_path=>"panel_calendar_back_end_tags_path" ,
:priority=>4,
# :active_for_action=>{:bulletin_categorys=>:index},
:available_for => [:manager]
end
end
end

59
vendor/built_in_modules/gallery/init.rb vendored Normal file
View File

@ -0,0 +1,59 @@
module Gallery
OrbitApp.registration "Gallery",:type=> 'ModuleApp' do
module_label 'miss_module_i18n.gallery'
base_url File.expand_path File.dirname(__FILE__)
# personal_plugin :enable => true,:path=>"panel/gallery/plugin/profile",:i18n=>'admin.gallery'
version "0.1"
organization "Rulingcom"
author "Visual dep"
intro "A simple and amazing gallery"
update_info 'some update_info'
front_end do
app_page 'albums'
end
category ["gallery_categories"]
widgets do
# default_widget do
# query 'Bulletin.all'
# image :image
# end
categories_query 'GalleryCategory.all'
# tags_query 'GalleryTag.all'
customize_widget "albums","gallery.widget.albums",:fields=>[],:style=>[]
end
side_bar do
head_label_i18n 'miss_module_i18n.gallery',:icon_class=>"icons-pictures"
available_for [:admin,:guest,:manager,:sub_manager]
active_for_controllers ({:private=>['albums','album_images','gallery_categories','/panel/gallery/back_end/tags']})
active_for_object_auth ['BulletinCategory']
head_link_path "panel_gallery_back_end_albums_path"
context_link 'gallery.categories',
:link_path=>"panel_gallery_back_end_gallery_categories_path" ,
:priority=>3,
:active_for_action=>{:gallery_categories=>:index},
:available_for => [:manager]
context_link 'tags',
:link_path=>"panel_gallery_back_end_tags_path" ,
:priority=>4,
# :active_for_action=>{:bulletin_categorys=>:index},
:available_for => [:manager]
context_link 'module_authorization',
:link_path=>"admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {key: 'gallery'}))",
:priority=>6,
:active_for_app_auth => 'gallery',
:available_for => [:admin]
end
end
end

43
vendor/built_in_modules/gprs/init.rb vendored Normal file
View File

@ -0,0 +1,43 @@
module Location
OrbitApp.registration "Location",:type=> 'ModuleApp' do
module_label 'miss_module_i18n.location'
base_url File.expand_path File.dirname(__FILE__)
# personal_plugin :enable => true,:path=>"panel/location/plugin/profile",:i18n=>'admin.location'
# version "0.1"
# organization "Rulingcom"
# author "RD dep"
# intro "I am intro"
# update_info 'some update_info'
# front_end do
# app_page 'bulletins'
# end
# category ["BulletinCategory"]
# widgets do
# default_widget do
# query 'Bulletin.all'
# image :image
# end
# categories_query 'BulletinCategory.all'
# tags_query 'LocationTag.all'
# customize_widget "index","location.widget.index",:fields=>["title","category","postdate"],:style=>["cu_style_1","cu_style_2","cu_style_3","cu_style_4","cu_style_5"]
# customize_widget "bulletins_and_web_links","location.widget.bulletins_and_web_links"
# # item "index","location.widget.index",:default_template=>true,:fields=>["title","category","postdate"]
# # item "bulletins_and_web_links","location.widget.bulletins_and_web_links"
# end
side_bar do
head_label_i18n 'miss_module_i18n.location',:icon_class=>"icons-location"
available_for [:admin,:guest,:manager,:sub_manager]
active_for_controllers ({:private=>['locations']})
head_link_path "panel_gprs_back_end_locations_path"
end
end
end

View File

@ -0,0 +1,10 @@
zh_tw:
miss_module_i18n:
archive: 檔案室
_archive:
all: 全部檔案
calendar: 日曆模組
calendars: 日曆
gallery: 相簿
location: Location

View File

@ -0,0 +1,33 @@
module PageContent
OrbitApp.registration "PageContent",:type=> 'ModuleApp' do
module_label 'page'
base_url File.expand_path File.dirname(__FILE__)
# personal_plugin :enable => true,:path=>"panel/announcement/plugin/profile",:i18n=>'admin.announcement'
version "0.1"
organization "Rulingcom"
author "RD dep"
intro "I am intro"
update_info 'some update_info'
front_end do
app_page 'page_contexts'
end
side_bar do
head_label_i18n 'page',:icon_class=>"icons-page"
available_for [:admin,:guest,:manager,:sub_manager]
active_for_controllers ({:private=>['page_contexts']})
active_for_object_auth ['PageContext']
head_link_path "panel_page_content_back_end_page_contexts_path"
context_link 'module_authorization',
:link_path=>"admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {key: 'page_content'}))",
:priority=>1,
:active_for_app_auth => 'PageContext',
:available_for => [:admin]
end
end
end

View File

@ -0,0 +1,67 @@
module WebResource
OrbitApp.registration "WebResource",:type=> 'ModuleApp' do
module_label 'link'
base_url File.expand_path File.dirname(__FILE__)
# personal_plugin :enable => true,:path=>"panel/web_resource/plugin/profile",:i18n=>'admin.web_resource'
version "0.1"
organization "Rulingcom"
author "RD dep"
intro "I am intro"
update_info 'some update_info'
category ["WebLinkCategory"]
widgets do
# default_widget do
# query 'Bulletin.all'
# image :image
# end
categories_query 'BulletinCategory.all'
tags_query 'WebResourceTag.all'
customize_widget "home_list","web_resource.widget.home_list"
end
side_bar do
head_label_i18n 'link',:icon_class=>"icons-link"
available_for [:admin,:guest,:manager,:sub_manager]
active_for_controllers ({:private=>['web_links', 'web_link_categorys']})
active_for_object_auth ['WebLinkCategory']
head_link_path "panel_web_resource_back_end_web_links_path"
context_link 'list_',
:link_path=>"panel_web_resource_back_end_web_links_path" ,
:priority=>1,
:active_for_action=>{:bulletins=>:index},
:available_for => [:all]
context_link 'link',
:link_path=>"new_panel_web_resource_back_end_web_link_path" ,
:priority=>2,
:active_for_action=>{:bulletins=>:new},
:available_for => [:sub_manager]
context_link 'categories',
:link_path=>"panel_web_resource_back_end_web_link_categorys_path" ,
:priority=>3,
:active_for_action=>{:bulletin_categorys=>:index},
:available_for => [:manager]
context_link 'tags',
:link_path=>"panel_web_resource_back_end_tags_path" ,
:priority=>4,
# :active_for_action=>{:bulletin_categorys=>:index},
:available_for => [:manager]
context_link 'module_authorization',
:link_path=>"admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {key: 'web_resource'}))",
:priority=>6,
:active_for_app_auth => 'web_resource',
:available_for => [:admin]
end
end
end