From bd9451f923c77a20fae6defe013dcadfad2e5fcb Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Thu, 26 Apr 2012 16:13:21 +0800 Subject: [PATCH] Fix approval setting ajax problem --- .../javascripts/inc/permission-checkbox.js | 5 +- .../back_end/approvals_controller.rb | 36 +++++++++------ .../approvals/_privilege_user.html.erb | 14 +++--- .../back_end/approvals/setting.html.erb | 26 ++++++++--- .../back_end/approvals/setting.js.erb | 3 +- .../back_end/approvals/update_setting.js.erb | 1 + .../fact_checks_can_del/setting.html.erb | 46 ------------------- .../announcement/config/routes.rb | 3 +- 8 files changed, 56 insertions(+), 78 deletions(-) create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/update_setting.js.erb delete mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/fact_checks_can_del/setting.html.erb diff --git a/app/assets/javascripts/inc/permission-checkbox.js b/app/assets/javascripts/inc/permission-checkbox.js index fc91b857..23716f68 100644 --- a/app/assets/javascripts/inc/permission-checkbox.js +++ b/app/assets/javascripts/inc/permission-checkbox.js @@ -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 }, }); -}); \ No newline at end of file +}; \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb index 0578cfc3..2d10dd75 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb @@ -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 - 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') + @bulletin_category = @bulletin_categorys.first + end + 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?) diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/_privilege_user.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/_privilege_user.html.erb index 659fbc43..f4bd4707 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/_privilege_user.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/_privilege_user.html.erb @@ -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| -%>
- <% user.sub_roles.each do |sr| %> + <% sys_user.sub_roles.each do |sr| %> <% 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 %>
- <% 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 %>
- <%= 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 -%>
diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/setting.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/setting.html.erb index af67651a..c49798ba 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/setting.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/approvals/setting.html.erb @@ -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") %>