Permission setting for announcement for bulletin cate

This commit is contained in:
Matthew K. Fu JuYuan 2012-05-09 14:54:20 +08:00 committed by Christophe Vilayphiou
parent 038378be9a
commit c82d701b55
11 changed files with 211 additions and 45 deletions

View File

@ -7,9 +7,9 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle
@bulletin = Bulletin.find params[:bulletin_id]
end
def approve
end
# def approve
#
# end
def setting
@bulletin_categorys = BulletinCategory.all
@ -39,41 +39,7 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle
def user_list
@bulletin_category = BulletinCategory.find params[:category][:id]
end
# def index
# get_categorys(params[:bulletin_category_id])
#
# @bulletins = params[:sort] ? get_sorted_bulletins : Bulletin.all
# @bulletin_categories = BulletinCategory.all
#
# module_app = ModuleApp.first(:conditions => {:key => 'announcement'})
# @tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc)
#
# respond_to do |format|
# format.html # index.html.erb
# format.js
# format.xml { render :xml => @bulletins }
# end
# end
#
# def new
#
# end
#
# def create
#
# end
#
# def update
#
# end
#
# def edit
#
# end
#
# def destroy
#
# end
protected
def update_setting_by_params
category = BulletinCategory.find params[:category][:id]

View File

@ -0,0 +1,63 @@
class Panel::Announcement::BackEnd::BulletinCategorySettingController < OrbitBackendController
before_filter :authenticate_user!
before_filter :for_app_manager
include AdminHelper
# layout 'admin'
def preview_and_approve
@bulletin = Bulletin.find params[:bulletin_id]
end
# def approve
#
# end
def setting
@bulletin_categorys = []
@bulletin_categorys << BulletinCategory.find(params[:bulletin_category_id])
@options_from_collection_for_select_bulletin_categorys = @bulletin_categorys.collect{|bc| [bc.i18n_variable[I18n.locale],bc.id] }
if params.has_key? :category
@bulletin_category = BulletinCategory.find params[:category][:id]
else
@bulletin_category = @bulletin_categorys.first
end
preload_object_auth = @bulletin_category.object_auths.where(title: 'submit').empty?? (@bulletin_category.object_auths.create! :title=> 'submit') : @bulletin_category.object_auths.where(title: 'submit')
@users_array = preload_object_auth.first.privilege_users rescue []
respond_to do |format|
format.html
format.js
end
end
def update_setting
object_auth = update_setting_by_params
if object_auth.save!
flash[:notice] = "Update Done"
else
flash[:notice] = "Update Failed"
end
end
def user_list
@bulletin_category = BulletinCategory.find params[:category][:id]
end
protected
def update_setting_by_params
category = BulletinCategory.find params[:category][:id]
privilege_users = params[:users].collect{|key,value| User.find key } rescue []
object_auth_ary = category.object_auths.where(title: 'submit') || (category.object_auths.create :title=> 'submit')
object_auth = object_auth_ary.first
object_auth.privilege_users = privilege_users
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
end

View File

@ -2,13 +2,15 @@ module Panel::Announcement::BackEnd::BulletinCategorysHelper
include ActionView::Helpers::UrlHelper
def show_submit_permission_link(bulletin_category)
oa = bulletin_category.get_object_auth_by_title('submit')
def show_permission_link(bulletin_category)
type = 'submit'
oa = bulletin_category.get_object_auth_by_title(type)
if oa.nil?
bulletin_category.object_auths.new(title: 'submit' ).save
oa = bulletin_category.get_object_auth_by_title('submit')
bulletin_category.object_auths.new(title: type ).save
oa = bulletin_category.get_object_auth_by_title(type)
end
link_to t('announcement.bulletin.cate_auth'), edit_admin_object_auth_path(oa)
# link_to t('announcement.bulletin.cate_auth'), edit_admin_object_auth_path(oa)
link_to t('announcement.bulletin.cate_auth'),panel_announcement_back_end_bulletin_category_setting_path(bulletin_category)
end
end

View File

@ -0,0 +1,44 @@
<% if bulletin_category -%>
<div class="modal hide fade in" id="bulletin_category-<%=bulletin_category.id%>">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3><%= t("announcement.bulletin.approval_user_list") %></h3>
</div>
<div class="modal-body">
<div class="clear">
<% bulletin_category.get_object_auth_by_title('submit').auth_users.each do |user| %>
<div class="checkbox clear checked">
<div class='member-avatar'>
<% if user.avatar? %>
<%= image_tag(user.avatar.thumb.url,:class => "member-img") %>
<% else %>
<%= image_tag "person.png",:class => "member-img" %>
<% end %>
</div>
<%= label_tag "lab-user-#{user.id}", (user.name rescue ''),:class=>"member-name",:id=>nil -%>
</div>
<% end -%>
<divl>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal"><%= t("modal.close") %></a>
</div>
<div>
<script type="text/javascript" src="/static/kernel.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#bulletin_category-<%=bulletin_category.id%>").on("show", function () {
});
$(".modal").on("hidden", function () {
$("#show_preview").remove();
});
});
</script>
</div>
</div>
<% end -%>

View File

@ -0,0 +1,26 @@
<%= content_tag :div ,:id => "users_checkbox_ary",:class => 'clear' do -%>
<% sys_users = User.all -%>
<% sys_users.each do |sys_user| -%>
<div class="checkblock">
<% sys_user.sub_roles.each do |sr| %>
<div class="for_unit" style="display:none;"> <%= sr.key %></div>
<% end %>
<%= content_tag :div,:data=>{'original-title'=>t('announcement.bulletin.approval_setting_window_title'),:content => "#{sys_user.sub_roles.collect{|sr| sr.i18n_variable[I18n.locale]}.join(',')}"},:class=>"checkbox clear" do %>
<div class="check-icon">
</div>
<div class='member-avatar'>
<% if sys_user.avatar? %>
<%= image_tag(sys_user.avatar.thumb.url,:class => "member-img") %>
<% else %>
<%= image_tag "person.png",:class => "member-img" %>
<% end %>
</div>
<%= label_tag "lab-user-#{sys_user.id}", (sys_user.name rescue ''),:class=>"member-name",:id=>nil -%>
<%= check_box_tag "[users][#{sys_user.id}]", 'true',users.include?(sys_user),:class => "check" -%>
<%end -%>
</div>
<% end -%>
<% end -%>

View File

@ -0,0 +1,56 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "inc/permission-checkbox" %>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "inc/permission-checkbox" %>
<%= javascript_include_tag "inc/search" %>
<%= javascript_include_tag "inc/modal-preview" %>
<% end %>
<%#= label_tag :fact_check_setting, t("announcement.bulletin.fact_check_setting") %>
<%= form_tag('', :remote => true,:class => "prevent_enter_submit_form") %>
<div class="subnav clear">
<ul class="nav nav-pills filter pull-left">
<li class="accordion-group">
<div class="form-search" style="margin: 5px 10px;">
<%= label_tag :category, t("announcement.bulletin.category") %>
<%= select "category",'id',@options_from_collection_for_select_bulletin_categorys %>
<%= search_field_tag 'user_filter' %>
</div>
</li>
</ul>
<%= link_to t("announcement.bulletin.approval_user_list"), panel_announcement_back_end_bulletin_category_user_list_path , :class=>'preview_trigger btn btn-success pull-right'%>
</div>
<%#= label_tag :role, t("admin.roles") %>
<div class="clear">
<%= content_tag :div do -%>
<% form_tag panel_announcement_back_end_approval_setting_path do %>
<%= render :partial => "privilege_user", :locals => {:users => @users_array} %>
<div class="form-actions form-fixed pagination-right">
<%= submit_tag "Update", :class => 'btn btn-primary' %>
</div>
<% end -%>
<% end -%>
</div>
<script type="text/javascript" charset="utf-8">
var availableTags = [];
$(document).ready(function() {
$(".prevent_enter_submit_form").bind("keypress", function(e) {
if (e.keyCode == 13) {
return false;
}
});
$('#category_id').change(function() {
$.ajax({
type: 'GET',
dataType: "script",
url:$(this).parents("from").attr("href"),
data:$(this).parents("form").serialize()
});
});
});
</script>

View File

@ -0,0 +1,2 @@
$("#users_checkbox_ary").replaceWith('<%= escape_javascript(render :partial => "privilege_user", :locals => {:users => @users_array})%>');
permissionCheckbox();

View File

@ -0,0 +1 @@
alert( "<% flash.each do |key, msg| %><%= msg %><% end%>");

View File

@ -0,0 +1,2 @@
$('#show_preview').html("<%= escape_javascript(render(:partial => 'modal_list',:locals => {:bulletin_category => @bulletin_category})) %>");
var start_modal_with_id = "bulletin_category-<%=@bulletin_category.id%>"

View File

@ -5,7 +5,7 @@
<div class="quick-edit">
<ul class="nav nav-pills hide">
<%if is_manager? || is_admin? %>
<li><%= show_submit_permission_link(bulletin_category) %></li>
<li><%= show_permission_link(bulletin_category) %></li>
<% end %>
<% if is_admin?%>
<li><%= link_to t('bulletin_category.edit'), edit_panel_announcement_back_end_bulletin_category_path(bulletin_category), :remote => true %></li>

View File

@ -21,7 +21,11 @@ Rails.application.routes.draw do
match "file_quick_edit/:bulletin_id" => "bulletins#file_quick_edit" ,:as => :file_quick_edit
end
resources :bulletin_categorys
resources :bulletin_categorys do
match 'submit_setting' => "bulletin_category_setting#setting" ,:as => :setting,:via => :get
match 'submit_setting' => "bulletin_category_setting#update_setting" ,:as => :setting,:via => :post
match 'submit_setting' => "bulletin_category_setting#user_list" ,:as => :user_list,:via => :put
end
resources :bulletin_links, :controller => 'bulletin_links' do
match "link_quick_edit/:bulletin_link_id" => "bulletin_links#link_quick_edit" ,:as => :link_quick_edit