orbit disable object for categories

This commit is contained in:
Matthew K. Fu JuYuan 2012-07-05 16:00:45 +08:00
parent edef51d58c
commit c5fdff764e
20 changed files with 89 additions and 46 deletions

View File

@ -1,8 +1,6 @@
class SessionsController < Devise::SessionsController
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
include Devise::Controllers::InternalHelpers
MiddleSiteConnection.establish
NccuLdapConnection.establish
# POST /resource/sign_in
def create
@ -13,6 +11,8 @@ class SessionsController < Devise::SessionsController
result = false
ldap_filter = "(uid=#{login_uid})"
if /@rulingcom.com$/.match(login_uid).nil?
MiddleSiteConnection.establish
NccuLdapConnection.establish
if ($nccu_ldap_connection.bind rescue false)
logger.info "=LDAP Binded password ok..."

View File

@ -42,4 +42,8 @@ module OrbitBackendHelper
end
end
def show_toggle_archive_btn(object)
object.disable ? t("object_disable.change_to_false") : t("object_disable.change_to_true")
end
end

View File

@ -511,3 +511,7 @@ zh_tw:
sys:
not_previewable: "不支援預覽"
limit_of_upload_file_size: "上傳檔案大小限制: %{best_size}"
object_disable:
change_to_true: "設為停用"
change_to_false: "重新啓用"

View File

@ -0,0 +1,11 @@
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
end
end
end
end

View File

@ -1,4 +1,19 @@
module OrbitCoreLib
module ObjectDisable
def self.included(base)
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)
end
end
end
end
module ObjectAuthable
def self.included(base)
base.instance_eval("has_many :object_auths,as: :obj_authable,dependent: :delete")

View File

@ -1,9 +1,10 @@
class Panel::Announcement::BackEnd::BulletinCategorysController < OrbitBackendController
include OrbitControllerLib::DivisionForDisable
before_filter :for_app_manager,:except => [:index]
def index
@bulletin_categorys = BulletinCategory.all
#TODO 需要做 manager ,admin 才可以 all. 其他 available就好
@bulletin_category = BulletinCategory.new(:display => 'List')
@url = panel_announcement_back_end_bulletin_categorys_path

View File

@ -39,6 +39,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
# @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_link = BulletinLink.new
@link_url = panel_announcement_back_end_bulletins_path
@ -301,6 +302,8 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
@bulletin = Bulletin.find(params[:id])
@type = params[:type]
@bulletin_categories = BulletinCategory.all
#TODO 需要做 manager ,admin 才可以 all. 其他 available就好
get_tags
end
@ -328,9 +331,9 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
@bulletin_categorys = []
#@unit_list_for_anc = UnitListForAnc.all
if(is_manager? || is_admin?)
@bulletin_categorys = (id ? BulletinCategory.available.find(id).to_a : BulletinCategory.available)
@bulletin_categorys = (id ? BulletinCategory.all.find(id).to_a : BulletinCategory.all)
elsif is_sub_manager?
@bulletin_categorys = BulletinCategory.available.authed_for_user(current_user,'submit')
@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")

View File

@ -52,7 +52,7 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController
protected
def get_categorys
@bulletin_categorys = BulletinCategory.excludes('disabled' => true)
@bulletin_categorys = BulletinCategory.all
end
end

View File

@ -13,8 +13,4 @@ include ActionView::Helpers::UrlHelper
link_to t('announcement.bulletin.cate_auth'),admin_object_auth_ob_auth_path(oa)
end
def show_toggle_archive_btn(bulletin_category)
bulletin_category.disable ? t("bulletin_category.disable_change_to_true") : t("bulletin_category.disable_change_to_false")
end
end

View File

@ -4,7 +4,8 @@ class BulletinCategory
include Mongoid::Document
include Mongoid::Timestamps
include OrbitCoreLib::ObjectAuthable
include OrbitCoreLib::ObjectDisable
ObjectAuthTitlesOptions = %W{submit_new fact_check}
AfterObjectAuthUrl = '/panel/announcement/back_end/bulletin_categorys'
# include Mongoid::MultiParameterAttributes
@ -20,15 +21,7 @@ class BulletinCategory
has_many :bulletins
scope :available,where(disable: false)
def self.find(*args)
if args ==[:all]
unscoped
else
unscoped.find(args)
end
end
def pp_object
i18n_variable[I18n.locale]

View File

@ -92,7 +92,7 @@ en:
update_success: Bulletin Category Updated
update_failed: Bulletin Category Failed
disable_change_to_false: Toggle to archive
disable_change_to_true: Pu back from archive
disable_change_to_true: Put back from archive
# admin:
# action: Action
# add_language: Add language

View File

@ -181,8 +181,6 @@ zh_tw:
delete: 刪除
update_success: 分類更新成功
update_failed: 分類更新失敗
disable_change_to_false: 設為停用
disable_change_to_true: 重新啓用
# Chinese (Taiwan) translations for Ruby on Rails
# by tsechingho (http://github.com/tsechingho)

View File

@ -4,7 +4,9 @@ class Panel::News::BackEnd::NewsBulletinCategorysController < OrbitBackendContro
def index
@news_bulletin_categorys = NewsBulletinCategory.all
@news_bulletin_categorys = get_disable_object_by_user(NewsBulletinCategory)
#TODO 需要做 manager ,admin 才可以 all. 其他 available就好
@news_bulletin_category = NewsBulletinCategory.new(:display => 'List')
@url = panel_news_back_end_news_bulletin_categorys_path
@ -108,13 +110,21 @@ class Panel::News::BackEnd::NewsBulletinCategorysController < OrbitBackendContro
# DELETE /news_bulletins/1
# DELETE /news_bulletins/1.xml
def destroy
@news_bulletin_category = NewsBulletinCategory.find(params[:id])
@news_bulletin_category.destroy
@news_bulletin_category = NewsBulletinCategory.find(params[:id]).first
@news_bulletin_category.disable = @news_bulletin_category.disable ? false : true
if @news_bulletin_category.save!
respond_to do |format|
flash[:notice] = t("bulletin_category.update_success")
# flash[:error] += @bulletin_category.disable ? t("bulletin_category.disable_change_to_true") : t("bulletin_category.disable_change_to_false")
format.html { redirect_to(panel_announcement_back_end_news_bulletin_categorys_url) }
# format.xml { head :ok }
format.js
end
else
flash[:error] = t("bulletin_category.update_failed")
format.html { render :action => "index" }
respond_to do |format|
format.html { redirect_to(panel_news_back_end_news_bulletin_categorys_url) }
# format.xml { head :ok }
format.js
end
end
end

View File

@ -5,7 +5,8 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController
# 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]
def index
# @news_bulletins = NewsBulletin.all
# @news_bulletins = NewsBulletin.desc("postdate desc")
@ -38,6 +39,7 @@ 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_link = NewsBulletinLink.new
@link_url = panel_news_back_end_news_bulletins_path
@ -82,15 +84,11 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController
# @news_bulletin.news_bulletin_files.build
# @news_bulletin.news_bulletin_files.new
if get_categorys.empty?
flash[:alert] = t("announcement.error.no_avilb_cate_for_posting")
redirect_to :action => :index
else
get_tags
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @news_bulletin }
end
end
end
@ -104,7 +102,6 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController
@link_url = panel_news_back_end_news_bulletin_path(@news_bulletin)
get_categorys
get_tags
end
end
@ -264,7 +261,7 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController
format.xml { head :ok }
else
get_tags
get_categorys
format.html { render :action => "edit" }
format.xml { render :xml => @news_bulletin.errors, :status => :unprocessable_entity }
end
@ -303,6 +300,8 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController
@news_bulletin = NewsBulletin.find(params[:id])
@type = params[:type]
@news_bulletin_categories = NewsBulletinCategory.all
#TODO 需要做 manager ,admin 才可以 all. 其他 available就好
get_tags
end
@ -320,11 +319,16 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController
@news_bulletin_categorys = []
@unit_list_for_anc = UnitListForAnc.all
if(is_manager? || is_admin?)
@news_bulletin_categorys = (id ? NewsBulletinCategory.find(id).to_a : NewsBulletinCategory.excludes('disabled' => true))
@news_bulletin_categorys = (id ? NewsBulletinCategory.find(id).to_a : NewsBulletinCategory.all)
elsif is_sub_manager?
@news_bulletin_categorys = NewsBulletinCategory.authed_for_user(current_user,'submit')
@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_tags
module_app = ModuleApp.first(:conditions => {:key => 'news'})

View File

@ -4,7 +4,8 @@ class NewsBulletinCategory
include Mongoid::Document
include Mongoid::Timestamps
include OrbitCoreLib::ObjectAuthable
include OrbitCoreLib::ObjectDisable
ObjectAuthTitlesOptions = %W{submit_new fact_check}
AfterObjectAuthUrl = '/panel/news/back_end/news_bulletin_categorys'
# include Mongoid::MultiParameterAttributes
@ -16,8 +17,7 @@ class NewsBulletinCategory
field :display
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
has_many :news_bulletins,:dependent => :destroy
has_many :news_bulletins
def pp_object
i18n_variable[I18n.locale]

View File

@ -6,7 +6,7 @@
<ul class="nav nav-pills hide">
<% if is_admin?%>
<li><%= link_to t('bulletin_category.edit'), edit_panel_news_back_end_news_bulletin_category_path(news_bulletin_category), :remote => true %></li>
<li><%= link_to t('bulletin_category.delete'), panel_news_back_end_news_bulletin_category_path(news_bulletin_category), :confirm => t('announcement.sure?'), :method => :delete, :remote => true %></li>
<li><%= link_to show_toggle_archive_btn(news_bulletin_category), panel_news_back_end_news_bulletin_category_path(news_bulletin_category), :confirm => t('announcement.sure?'), :method => :delete, :remote => true,:class=>"archive_toggle" %></li>
<% end %>
<%if is_manager? || is_admin? %>
<li><%= show_news_cate_permission_link(news_bulletin_category) %></li>

View File

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

View File

@ -75,6 +75,10 @@ zh_tw:
fact_check: 新聞審核
delete: 刪除
edit: 編輯
update_success: 分類更新成功
update_failed: 分類更新失敗
# action: 行動
# add_language: 新增語言
# admin: 管理

View File

@ -4,7 +4,7 @@ class WebLinkCategory
include Mongoid::Document
include Mongoid::Timestamps
include OrbitCoreLib::ObjectAuthable
include OrbitCoreLib::ObjectDisable
# include Mongoid::MultiParameterAttributes
AfterObjectAuthUrl = '/panel/page_content/back_end/page_contexts'
APP_NAME = '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 t('web_resource.delete'), 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 %></li>
<li><%= show_web_link_permission_link web_link_category %></li>
</ul>
</div>