Fix approval setting ajax problem

This commit is contained in:
Matthew K. Fu JuYuan 2012-04-26 16:13:21 +08:00 committed by Christophe Vilayphiou
parent 94d61abf83
commit c4db7e2157
8 changed files with 56 additions and 78 deletions

View File

@ -1,4 +1,7 @@
$(document).ready(function() { $(document).ready(function() {
permissionCheckbox();
});
function permissionCheckbox(){
$('.check[checked="checked"]').parents(".checkbox").addClass("checked") $('.check[checked="checked"]').parents(".checkbox").addClass("checked")
$(".checkbox").click(function(){ $(".checkbox").click(function(){
if($(this).children(".check").attr("checked")){ if($(this).children(".check").attr("checked")){
@ -16,4 +19,4 @@ $(document).ready(function() {
placement: 'bottom', placement: 'bottom',
delay: { show: 100, hide: 300 }, delay: { show: 100, hide: 300 },
}); });
}); };

View File

@ -5,19 +5,13 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle
def setting def setting
@bulletin_categorys = BulletinCategory.all @bulletin_categorys = BulletinCategory.all
if params.has_key?(:category_id) @options_from_collection_for_select_bulletin_categorys = @bulletin_categorys.collect{|bc| [bc.i18n_variable[I18n.locale],bc.id] }
first_category = BulletinCategory.find params[:category_id] if params.has_key? :category
if params[:commit] == 'Update' @bulletin_category = BulletinCategory.find params[:category][:id]
privilege_users = params[:users].collect{|key,value| User.find key } rescue []
preload_object_auth_ary = first_category.object_auths.where(title: 'fact_check') || (first_category.object_auths.create :title=> 'fact_check')
preload_object_auth = preload_object_auth_ary.first
preload_object_auth.privilege_users = privilege_users
preload_object_auth.save!
end
else else
first_category = @bulletin_categorys.first @bulletin_category = @bulletin_categorys.first
end end
preload_object_auth = first_category.object_auths.where(title: 'fact_check').empty?? (first_category.object_auths.create! :title=> 'fact_check') : first_category.object_auths.where(title: 'fact_check') preload_object_auth = @bulletin_category.object_auths.where(title: 'fact_check').empty?? (@bulletin_category.object_auths.create! :title=> 'fact_check') : @bulletin_category.object_auths.where(title: 'fact_check')
@users_array = preload_object_auth.first.privilege_users rescue [] @users_array = preload_object_auth.first.privilege_users rescue []
respond_to do |format| respond_to do |format|
format.html format.html
@ -26,11 +20,16 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle
end end
def update_setting def update_setting
object_auth = update_setting_by_params
if object_auth.save!
flash[:notice] = "Update Done"
else
flash[:notice] = "Update Failed"
end
end end
def user_list def user_list
@bulletin_category = BulletinCategory.find params[:category_id] @bulletin_category = BulletinCategory.find params[:category][:id]
end end
# def index # def index
# get_categorys(params[:bulletin_category_id]) # get_categorys(params[:bulletin_category_id])
@ -68,6 +67,15 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle
# #
# end # end
protected 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: 'fact_check') || (category.object_auths.create :title=> 'fact_check')
object_auth = object_auth_ary.first
object_auth.privilege_users = privilege_users
object_auth
end
def get_categorys(id = nil) def get_categorys(id = nil)
@bulletin_categorys = [] @bulletin_categorys = []
if(is_manager? || is_admin?) if(is_manager? || is_admin?)

View File

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

View File

@ -7,13 +7,13 @@
<%= javascript_include_tag "inc/modal-preview" %> <%= javascript_include_tag "inc/modal-preview" %>
<% end %> <% end %>
<%#= label_tag :fact_check_setting, t("announcement.bulletin.fact_check_setting") %> <%#= label_tag :fact_check_setting, t("announcement.bulletin.fact_check_setting") %>
<%= form_tag('', :remote => true) %> <%= form_tag('', :remote => true,:class => "prevent_enter_submit_form") %>
<div class="subnav clear"> <div class="subnav clear">
<ul class="nav nav-pills filter pull-left"> <ul class="nav nav-pills filter pull-left">
<li class="accordion-group"> <li class="accordion-group">
<div class="form-search" style="margin: 5px 10px;"> <div class="form-search" style="margin: 5px 10px;">
<%= label_tag :category, t("announcement.bulletin.category") %> <%= label_tag :category, t("announcement.bulletin.category") %>
<%= select_tag "category_id", options_from_collection_for_select(@bulletin_categorys, "id", "key") %> <%= select "category",'id',@options_from_collection_for_select_bulletin_categorys %>
<%= search_field_tag 'user_filter' %> <%= search_field_tag 'user_filter' %>
</div> </div>
@ -25,7 +25,7 @@
<%#= label_tag :role, t("admin.roles") %> <%#= label_tag :role, t("admin.roles") %>
<div class="clear"> <div class="clear">
<%= content_tag :div do -%> <%= content_tag :div do -%>
<% form_tag :action => "update_setting" do %> <% form_tag panel_announcement_back_end_approval_setting_path do %>
<%= render :partial => "privilege_user", :locals => {:users => @users_array} %> <%= render :partial => "privilege_user", :locals => {:users => @users_array} %>
<div class="form-actions form-fixed pagination-right"> <div class="form-actions form-fixed pagination-right">
<%= submit_tag "Update", :class => 'btn btn-primary' %> <%= submit_tag "Update", :class => 'btn btn-primary' %>
@ -36,9 +36,21 @@
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
var availableTags = []; var availableTags = [];
$(function() { $(document).ready(function() {
$('#category_id').change(function() { $(".prevent_enter_submit_form").bind("keypress", function(e) {
$(this).parents('form').submit(); 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> </script>

View File

@ -1 +1,2 @@
$("#users_checkbox_ary").replaceWith('<%= (render :partial => 'privilege_user', :locals => {:users => @users_array}).html_safe%>'); $("#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

@ -1,46 +0,0 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "inc/permission-checkbox" %>
<% end %>
<% content_for :page_specific_javascript do %>
<<<<<<< HEAD
<%= javascript_include_tag "bootstrap" %>
<%#= javascript_include_tag "inc/permission-checkbox" %>
<%#= javascript_include_tag "inc/search" %>
=======
<%= javascript_include_tag "inc/permission-checkbox" %>
<%= javascript_include_tag "inc/search" %>
>>>>>>> 291d5e3a03ba7da62ceb5e3b18012f0c9198dfba
<% end %>
<%#= label_tag :fact_check_setting, t("announcement.bulletin.fact_check_setting") %>
<%= form_tag('', :remote => true) %>
<div class="subnav">
<ul class="nav nav-pills filter">
<li class="accordion-group">
<div class="form-search" style="margin: 5px 10px;">
<%= label_tag :category, t("announcement.bulletin.category") %>
<%= select_tag "category_id", options_from_collection_for_select(@bulletin_categorys, "id", "key") %>
<%= search_field_tag 'user_filter' %>
</div>
</li>
</ul>
</div>
<%#= label_tag :role, t("admin.roles") %>
<div class="clear">
<%= content_tag :div do -%>
<% form_tag :action => "update_setting" do %>
<%= render :partial => "privilege_user", :locals => {:users => @users_array} %>
<div class="form-actions pagination-centered">
<%= submit_tag "Update", :class => 'btn' %>
</div>
<% end -%>
<% end -%>
</div>
<script type="text/javascript" charset="utf-8">
var availableTags = [];
$(function() {
$('#category_id').change(function() {
$(this).parents('form').submit();
});
</script>

View File

@ -4,9 +4,8 @@ Rails.application.routes.draw do
namespace :back_end do namespace :back_end do
match 'public' => "announcements#public",:as => :public match 'public' => "announcements#public",:as => :public
match 'approval_setting' => "approvals#setting" ,:as => :approval_setting,:via => :get match 'approval_setting' => "approvals#setting" ,:as => :approval_setting,:via => :get
match 'approval_setting' => "approvals#update_setting" ,:as => :approval_setting,:via => :post
match 'approval_setting' => "approvals#user_list" ,:as => :approval_user_list,:via => :put match 'approval_setting' => "approvals#user_list" ,:as => :approval_user_list,:via => :put
match 'update_setting' => "approvals#update_setting" ,:as => :approval_update_setting
resources :bulletins do resources :bulletins do
match "link_quick_add/:bulletin_id" => "bulletins#link_quick_add" ,:as => :link_quick_add match "link_quick_add/:bulletin_id" => "bulletins#link_quick_add" ,:as => :link_quick_add
match "link_quick_edit/:bulletin_id" => "bulletins#link_quick_edit" ,:as => :link_quick_edit match "link_quick_edit/:bulletin_id" => "bulletins#link_quick_edit" ,:as => :link_quick_edit