Fix approval setting ajax problem
This commit is contained in:
parent
94d61abf83
commit
c4db7e2157
|
@ -1,4 +1,7 @@
|
|||
$(document).ready(function() {
|
||||
permissionCheckbox();
|
||||
});
|
||||
function permissionCheckbox(){
|
||||
$('.check[checked="checked"]').parents(".checkbox").addClass("checked")
|
||||
$(".checkbox").click(function(){
|
||||
if($(this).children(".check").attr("checked")){
|
||||
|
@ -16,4 +19,4 @@ $(document).ready(function() {
|
|||
placement: 'bottom',
|
||||
delay: { show: 100, hide: 300 },
|
||||
});
|
||||
});
|
||||
};
|
|
@ -5,19 +5,13 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle
|
|||
|
||||
def setting
|
||||
@bulletin_categorys = BulletinCategory.all
|
||||
if params.has_key?(:category_id)
|
||||
first_category = BulletinCategory.find params[:category_id]
|
||||
if params[:commit] == 'Update'
|
||||
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
|
||||
@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
|
||||
first_category = @bulletin_categorys.first
|
||||
@bulletin_category = @bulletin_categorys.first
|
||||
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 []
|
||||
respond_to do |format|
|
||||
format.html
|
||||
|
@ -26,11 +20,16 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle
|
|||
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]
|
||||
@bulletin_category = BulletinCategory.find params[:category][:id]
|
||||
end
|
||||
# def index
|
||||
# get_categorys(params[:bulletin_category_id])
|
||||
|
@ -68,6 +67,15 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle
|
|||
#
|
||||
# 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: '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)
|
||||
@bulletin_categorys = []
|
||||
if(is_manager? || is_admin?)
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
<%= content_tag :div ,:id => "users_checkbox_ary",:class => 'clear' do -%>
|
||||
<% sys_users = User.all -%>
|
||||
<% sys_users.each do |user| -%>
|
||||
<% sys_users.each do |sys_user| -%>
|
||||
|
||||
<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>
|
||||
<% 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>
|
||||
<div class='member-avatar'>
|
||||
<% if user.avatar? %>
|
||||
<%= image_tag(user.avatar.thumb.url,:class => "member-img") %>
|
||||
<% 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-#{user.id}", (user.name rescue ''),:class=>"member-name",:id=>nil -%>
|
||||
<%= check_box_tag "[users][#{user.id}]", 'true',users.include?(user),:class => "check" -%>
|
||||
<%= 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>
|
||||
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
<%= javascript_include_tag "inc/modal-preview" %>
|
||||
<% end %>
|
||||
<%#= 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">
|
||||
<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_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' %>
|
||||
</div>
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
|||
<%#= label_tag :role, t("admin.roles") %>
|
||||
<div class="clear">
|
||||
<%= 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} %>
|
||||
<div class="form-actions form-fixed pagination-right">
|
||||
<%= submit_tag "Update", :class => 'btn btn-primary' %>
|
||||
|
@ -36,9 +36,21 @@
|
|||
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
var availableTags = [];
|
||||
$(function() {
|
||||
$(document).ready(function() {
|
||||
|
||||
$(".prevent_enter_submit_form").bind("keypress", function(e) {
|
||||
if (e.keyCode == 13) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$('#category_id').change(function() {
|
||||
$(this).parents('form').submit();
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
dataType: "script",
|
||||
url:$(this).parents("from").attr("href"),
|
||||
data:$(this).parents("form").serialize()
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -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();
|
|
@ -0,0 +1 @@
|
|||
alert( "<% flash.each do |key, msg| %><%= msg %><% end%>");
|
|
@ -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>
|
|
@ -4,9 +4,8 @@ Rails.application.routes.draw do
|
|||
namespace :back_end do
|
||||
match 'public' => "announcements#public",:as => :public
|
||||
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 'update_setting' => "approvals#update_setting" ,:as => :approval_update_setting
|
||||
|
||||
resources :bulletins do
|
||||
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
|
||||
|
|
Reference in New Issue