category disable for backend

This commit is contained in:
Matthew K. Fu JuYuan 2012-07-06 18:11:55 +08:00
parent c5fdff764e
commit 56caf4b34e
13 changed files with 190 additions and 88 deletions

View File

@ -154,15 +154,17 @@ class OrbitBackendController< ApplicationController
end
def get_viewable(object_class)
objects = get_objects(object_class).order_by(:created_at, :desc)
def get_viewable(object_class, query=nil)
objects = get_objects(object_class,query).order_by(:created_at, :desc)
Kaminari.paginate_array(objects).page(params[:page]).per(10)
end
def get_objects(object_class, query=nil)
object_class = object_class.classify.constantize
# debugger
# a=1
if query
objects = object_class.all.where(query)
objects = object_class.where(query)
else
objects = object_class.all
end

View File

@ -6,10 +6,10 @@ $mid_site_connection
module MiddleSiteConnection
@mid_host = {
:host => 'mruling.nccu.edu.tw', #mruling.nccu.edu.tw or 127.0.0.1
:port => 3306, #3306 or 8005
:username => "rulingcom",
:password => "5w3iJQ9OJQMGhJibKP6YQje8",
:host => '127.0.0.1', #mruling.nccu.edu.tw or 127.0.0.1
:port => 8005, #3306 or 8005
:username => "root",
:password => "a3G6yWd9",
:database => "RSS23_NCCU_MIDDLE",
:encoding => "UTF8"
}

View File

@ -1,11 +1,44 @@
module OrbitControllerLib
module DivisionForDisable
def get_disable_object_by_user(object_class)
if is_admin? or is_manager?
object_class.admin_manager_all
else
object_class.all
# def get_disable_object_by_user(object_class)
# if is_admin? or is_manager?
# object_class.admin_manager_all
# else
# object_class.all
# end
# end
def get_categories_for_index(object_class,id = nil)
class_ref = object_class.constantize
ivar_name = "@#{object_class.to_s.underscore.pluralize}"
instance_variable_set(ivar_name, [])
if(is_manager? || is_admin?)
instance_variable_set(ivar_name, (id ? class_ref.admin_manager_all.find(id).to_a : class_ref.admin_manager_all))
elsif is_sub_manager?
instance_variable_set(ivar_name, (class_ref.all))
end
instance_variable_get(ivar_name)
end
def get_categorys(object_class,id = nil,func_authed_for_sub_manager = 'submit')
class_ref = object_class.constantize
# ivar_name = "@#{object_class.to_s.underscore.pluralize}"
ivar_name = "@#{object_class.to_s.underscore}s"
instance_variable_set(ivar_name, [])
@bulletin_categorys = []
if(is_manager? || is_admin?)
#instance_variable_set(ivar_name, (id ? class_ref.admin_manager_all.find(id).to_a : class_ref.admin_manager_all))
instance_variable_set(ivar_name, (id ? class_ref.all.find(id).to_a : class_ref.all))
elsif is_sub_manager?
instance_variable_set(ivar_name, class_ref.all.authed_for_user(current_user,func_authed_for_sub_manager))
end
if instance_variable_get(ivar_name).empty? && params[:action] != "index"
flash[:alert] = t("announcement.error.no_avilb_cate_for_posting")
redirect_to :action => :index
end
end
end
end

View File

@ -5,13 +5,24 @@ module OrbitCoreLib
base.instance_eval("field :disable,type: Boolean,:default => false")
base.instance_eval("scope :all,where(disable: false)")
base.instance_eval("scope :admin_manager_all,find(:all)")
base.define_singleton_method :find do |*args|
if args ==[:all]
unscoped
else
unscoped.find(args)
res = unscoped.find(args)
res.count == 1 ? res[0] : res
end
end
base.define_singleton_method :first do |*args|
all.first
end
base.define_singleton_method :last do |*args|
all.last
end
end
end
module ObjectAuthable

View File

@ -51,12 +51,12 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle
object_auth
end
def get_categorys(id = nil)
@bulletin_categorys = []
if(is_manager? || is_admin?)
@bulletin_categorys = (id ? BulletinCategory.find(id).to_a : BulletinCategory.excludes('disabled' => true))
elsif is_sub_manager?
@bulletin_categorys = BulletinCategory.authed_for_user(current_user,'submit_new')
end
end
# def get_categorys(id = nil)
# @bulletin_categorys = []
# if(is_manager? || is_admin?)
# @bulletin_categorys = (id ? BulletinCategory.find(id).to_a : BulletinCategory.excludes('disabled' => true))
# elsif is_sub_manager?
# @bulletin_categorys = BulletinCategory.authed_for_user(current_user,'submit_new')
# end
# end
end

View File

@ -3,10 +3,9 @@ class Panel::Announcement::BackEnd::BulletinCategorysController < OrbitBackendCo
before_filter :for_app_manager,:except => [:index]
def index
@bulletin_categorys = BulletinCategory.all
@bulletin_categorys = get_categories_for_index("BulletinCategory")
#TODO 需要做 manager ,admin 才可以 all. 其他 available就好
@bulletin_category = BulletinCategory.new(:display => 'List')
@url = panel_announcement_back_end_bulletin_categorys_path
respond_to do |format|
@ -108,7 +107,7 @@ class Panel::Announcement::BackEnd::BulletinCategorysController < OrbitBackendCo
# DELETE /bulletins/1
# DELETE /bulletins/1.xml
def destroy
@bulletin_category = BulletinCategory.find(params[:id]).first
@bulletin_category = BulletinCategory.find(params[:id])
@bulletin_category.disable = @bulletin_category.disable ? false : true
if @bulletin_category.save!

View File

@ -1,16 +1,20 @@
class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
include AdminHelper
include OrbitControllerLib::DivisionForDisable
layout 'new_admin'
before_filter :authenticate_user!
before_filter :get_categorys ,:only => [ :new,:edit,:update]
before_filter :only => [ :new,:edit,:update] do |controller|
controller.get_categorys('BulletinCategory')
end
# before_filter :for_admin_only,:only => [:]
# before_filter :for_app_manager,:only => [:index,:show,]
before_filter :for_app_sub_manager,:except => [:index,:show,:get_sorted_and_filtered_bulletins]
def index
# @bulletins = Bulletin.all
# @bulletins = Bulletin.desc("postdate desc")
get_categorys(params[:bulletin_category_id])
get_categorys('BulletinCategory',params[:bulletin_category_id])
get_tags
@filter = params[:filter]
@ -35,11 +39,11 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
# @bulletins = Bulletin.search(params[:search], params[:category_id])
# @bulletins = Bulletin.all.order_by([params[:sort], params[:direction]])
# @bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered_bulletins : Bulletin.all.page(params[:page]).per(10)
@bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered("bulletin") : get_viewable("bulletin")
@bulletin_categories = BulletinCategory.all
#TODO 需要做 manager ,admin 才可以 all. 其他 available就好
@bulletin_categories = get_categories_for_index("BulletinCategory")
@bulletin_category_ids = @bulletin_categories.collect{|t| t.id.to_s} + [nil]
@bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered("bulletin",:bulletin_category_id.in => @bulletin_category_ids) : get_viewable("bulletin",:bulletin_category_id.in => @bulletin_category_ids)
@bulletin_link = BulletinLink.new
@link_url = panel_announcement_back_end_bulletins_path
@ -327,19 +331,28 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
end
end
def get_categorys(id = nil)
@bulletin_categorys = []
#@unit_list_for_anc = UnitListForAnc.all
if(is_manager? || is_admin?)
@bulletin_categorys = (id ? BulletinCategory.all.find(id).to_a : BulletinCategory.all)
elsif is_sub_manager?
@bulletin_categorys = BulletinCategory.all.authed_for_user(current_user,'submit')
end
if @bulletin_categorys.empty? && params[:action] != "index"
flash[:alert] = t("announcement.error.no_avilb_cate_for_posting")
redirect_to :action => :index
end
end
# def get_categories_for_index(id = nil)
# @bulletin_categories = []
# if(is_manager? || is_admin?)
# @bulletin_categories = (id ? BulletinCategory.admin_manager_all.find(id).to_a : BulletinCategory.admin_manager_all)
# elsif is_sub_manager?
# @bulletin_categories = BulletinCategory.all
# end
# @bulletin_categories
# end
# def get_categorys(id = nil)
# @bulletin_categorys = []
# if(is_manager? || is_admin?)
# @bulletin_categorys = (id ? BulletinCategory.admin_manager_all.find(id).to_a : BulletinCategory.admin_manager_all)
# elsif is_sub_manager?
# @bulletin_categorys = BulletinCategory.all.authed_for_user(current_user,'submit')
# end
# if @bulletin_categorys.empty? && params[:action] != "index"
# flash[:alert] = t("announcement.error.no_avilb_cate_for_posting")
# redirect_to :action => :index
# end
# end
def get_tags
module_app = ModuleApp.first(:conditions => {:key => 'announcement'})

View File

@ -1,10 +1,10 @@
class Panel::News::BackEnd::NewsBulletinCategorysController < OrbitBackendController
include OrbitControllerLib::DivisionForDisable
before_filter :for_app_manager,:except => [:index]
def index
@news_bulletin_categorys = get_disable_object_by_user(NewsBulletinCategory)
@news_bulletin_categorys = get_categories_for_index("NewsBulletinCategory")
#TODO 需要做 manager ,admin 才可以 all. 其他 available就好
@news_bulletin_category = NewsBulletinCategory.new(:display => 'List')
@ -110,7 +110,7 @@ class Panel::News::BackEnd::NewsBulletinCategorysController < OrbitBackendContro
# DELETE /news_bulletins/1
# DELETE /news_bulletins/1.xml
def destroy
@news_bulletin_category = NewsBulletinCategory.find(params[:id]).first
@news_bulletin_category = NewsBulletinCategory.find(params[:id])
@news_bulletin_category.disable = @news_bulletin_category.disable ? false : true
if @news_bulletin_category.save!

View File

@ -1,16 +1,20 @@
class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController
include OrbitControllerLib::DivisionForDisable
before_filter :authenticate_user!
# before_filter :for_admin_only,:only => [:]
# before_filter :for_app_manager,:only => [:index,:show,]
before_filter :for_app_sub_manager,:except => [:index,:show,:get_sorted_and_filtered_news_bulletins]
before_filter :get_categorys ,:only => [ :new,:edit,:update]
before_filter :only => [ :new,:edit,:update] do |controller|
controller.get_categorys('NewsBulletinCategory')
controller.get_unit_list
end
def index
# @news_bulletins = NewsBulletin.all
# @news_bulletins = NewsBulletin.desc("postdate desc")
get_categorys(params[:news_bulletin_category_id])
get_categorys("NewsBulletinCategory",params[:news_bulletin_category_id])
get_tags
@filter = params[:filter]
@ -37,9 +41,12 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController
# @news_bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered_news_bulletins : NewsBulletin.all.page(params[:page]).per(10)
@news_bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered("news_bulletin") : get_viewable("news_bulletin")
@news_bulletin_categories = NewsBulletinCategory.all
#TODO 需要做 manager ,admin 才可以 all. 其他 available就好
@news_bulletin_categories = get_categories_for_index("NewsBulletinCategory")
@news_bulletin_category_ids = @news_bulletin_categories.collect{|t| t.id.to_s} + [nil]
@news_bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered("news_bulletin",:news_bulletin_category_id.in => @news_bulletin_category_ids) : get_viewable("news_bulletin",:news_bulletin_category_id.in => @news_bulletin_category_ids)
@news_bulletin_link = NewsBulletinLink.new
@link_url = panel_news_back_end_news_bulletins_path
@ -315,20 +322,32 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController
protected
def get_categorys(id = nil)
@news_bulletin_categorys = []
@unit_list_for_anc = UnitListForAnc.all
if(is_manager? || is_admin?)
@news_bulletin_categorys = (id ? NewsBulletinCategory.find(id).to_a : NewsBulletinCategory.all)
elsif is_sub_manager?
@news_bulletin_categorys = NewsBulletinCategory.all.authed_for_user(current_user,'submit')
end
if @news_bulletin_categorys.empty? && params[:action] != "index"
flash[:alert] = t("news.error.no_avilb_cate_for_posting")
redirect_to :action => :index
end
end
# def get_categories_for_index(id = nil)
# @news_bulletin_categories = []
# if(is_manager? || is_admin?)
# @news_bulletin_categories = (id ? NewsBulletinCategory.admin_manager_all.find(id).to_a : NewsBulletinCategory.admin_manager_all)
# elsif is_sub_manager?
# @news_bulletin_categories = NewsBulletinCategory.all
# end
# @news_bulletin_categories
# end
# def get_categorys(id = nil)
# @news_bulletin_categorys = []
# @unit_list_for_anc = UnitListForAnc.all
# if(is_manager? || is_admin?)
# @news_bulletin_categorys = (id ? NewsBulletinCategory.admin_manager_all.find(id).to_a : NewsBulletinCategory.admin_manager_all)
# elsif is_sub_manager?
# @news_bulletin_categorys = NewsBulletinCategory.all.authed_for_user(current_user,'submit')
# end
# if @news_bulletin_categorys.empty? && params[:action] != "index"
# flash[:alert] = t("news.error.no_avilb_cate_for_posting")
# redirect_to :action => :index
# end
# end
def get_unit_list
@unit_list_for_anc = UnitListForAnc.all
end
def get_tags
module_app = ModuleApp.first(:conditions => {:key => 'news'})

View File

@ -1,8 +1,9 @@
class Panel::WebResource::BackEnd::WebLinkCategorysController < OrbitBackendController
before_filter :for_app_manager,:except => [:index]
include OrbitControllerLib::DivisionForDisable
def index
@web_link_categorys = WebLinkCategory.all
@web_link_categorys = get_categories_for_index("WebLinkCategory")
@web_link_category = WebLinkCategory.new(:display => 'List')
@url = panel_web_resource_back_end_web_link_categorys_path
@ -86,12 +87,18 @@ class Panel::WebResource::BackEnd::WebLinkCategorysController < OrbitBackendCont
# DELETE /web_links/1.xml
def destroy
@web_link_category = WebLinkCategory.find(params[:id])
@web_link_category.destroy
@web_link_category.disable = @web_link_category.disable ? false : true
if @web_link_category.save!
respond_to do |format|
format.html { redirect_to(panel_web_resource_back_end_web_link_categorys_url) }
# format.xml { head :ok }
format.js
end
else
flash[:error] = t("web_link_category.update_failed")
format.html { render :action => "index" }
end
end
end

View File

@ -1,12 +1,12 @@
class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController
include OrbitControllerLib::DivisionForDisable
before_filter :authenticate_user!
# before_filter :for_app_manager,:except => [:index,:show]
before_filter :for_app_sub_manager,:except => [:index]
def index
get_categorys(params[:web_link_category_id])
get_categorys("WebLinkCategory",params[:web_link_category_id])
@filter = params[:filter]
new_filter = params[:new_filter]
@ -23,9 +23,12 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController
elsif new_filter
@filter = {new_filter[:type] => [new_filter[:id].to_s]}
end
@web_link_categories = get_categories_for_index("WebLinkCategory")
@web_link_category_ids = @web_link_categories.collect{|t| t.id.to_s} + [nil]
# @web_links = WebLink.search(params[:category_id])
@web_links = (params[:sort] || @filter) ? get_sorted_and_filtered_web_links : WebLink.all.page(params[:page]).per(10)
#@web_links = (params[:sort] || @filter) ? get_sorted_and_filtered_web_links : WebLink.all.page(params[:page]).per(10)
@web_links = (params[:sort] || @filter) ? get_sorted_and_filtered("web_link",:web_link_category_id.in => @web_link_category_ids) : get_viewable("web_link",:web_link_category_id.in => @web_link_category_ids)
get_tags
@ -51,6 +54,7 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController
# GET /web_links/new
# GET /web_links/new.xml
def new
@web_link = WebLink.new
get_categorys
@ -132,16 +136,30 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController
protected
def get_categorys(id = nil)
@web_link_categorys = (id ? WebLinkCategory.find(id).to_a : WebLinkCategory.excludes('disabled' => true))
@web_link_categorys = []
if(is_manager? || is_admin?)
@web_link_categorys = (id ? WebLinkCategory.find(id).to_a : WebLinkCategory.excludes('disabled' => true))
elsif is_sub_manager?
@web_link_categorys = WebLinkCategory.authed_for_user(current_user,'edit')
end
end
# def get_index_categories(id = nil)
# @bulletin_categorys = []
# if(is_manager? || is_admin?)
# @bulletin_categorys = (id ? BulletinCategory.admin_manager_all.find(id).to_a : BulletinCategory.admin_manager_all)
# elsif is_sub_manager?
# @bulletin_categorys = BulletinCategory.all
# end
# @bulletin_categorys
# end
# def get_categorys(id = nil)
# @web_link_categorys = []
# if(is_manager? || is_admin?)
# @web_link_categorys = (id ? WebLinkCategory.admin_manager_all.find(id).to_a : WebLinkCategory.admin_manager_all))
# elsif is_sub_manager?
# @web_link_categorys = WebLinkCategory.all.authed_for_user(current_user,'edit')
# end
# if @web_link_categorys.empty? && params[:action] != "index"
# flash[:alert] = t("announcement.error.no_avilb_cate_for_posting")
# redirect_to :action => :index
# end
# end
def get_tags
module_app = ModuleApp.first(:conditions => {:key => 'web_resource'})

View File

@ -7,7 +7,7 @@
<div class="quick-edit">
<ul class="nav nav-pills hide">
<li><%= link_to t('web_resource.edit'), edit_panel_web_resource_back_end_web_link_category_path(web_link_category), :remote => true %></li>
<li><%= link_to show_toggle_archive_btn(web_link_category), panel_web_resource_back_end_web_link_category_path(web_link_category), :confirm => t('announcement.sure?'), :method => :delete, :remote => true %></li>
<li><%= link_to show_toggle_archive_btn(web_link_category), panel_web_resource_back_end_web_link_category_path(web_link_category), :confirm => t('announcement.sure?'), :method => :delete, :remote => true ,:class=> "archive_toggle"%></li>
<li><%= show_web_link_permission_link web_link_category %></li>
</ul>
</div>

View File

@ -1 +1 @@
$("#<%= dom_id @web_link_category %>").remove();
$("#<%= dom_id @web_link_category %>").find(".archive_toggle").text("<%= show_toggle_archive_btn(@web_link_category) %> ");