From 942817185963e61aa597137542a9a88116e23b38 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 21 Nov 2013 18:34:59 +0800 Subject: [PATCH] all problem fixed for all categories and tags in plugin widget --- .../javascripts/lib/items/page_part.js.erb | 28 +++++++++++++++---- app/views/admin/page_parts/edit.html.erb | 15 +++++----- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/lib/items/page_part.js.erb b/app/assets/javascripts/lib/items/page_part.js.erb index 2e285178..5f8b2c19 100644 --- a/app/assets/javascripts/lib/items/page_part.js.erb +++ b/app/assets/javascripts/lib/items/page_part.js.erb @@ -107,15 +107,18 @@ $(function() { } event.preventDefault(); }); - $('#module_widget').on('change', '.checkbox-groups input', function(event) { var $checked = $(this); if($checked.attr('type') == 'checkbox') { - if($checked.hasClass('select_all') && $checked.prop('checked')) { - $checked.closest('.checkbox').siblings('.groups').find('input[type="checkbox"]').prop('checked', false); - } else if($checked.prop('checked') && !$checked.hasClass('lang-enable')) { - $checked.closest('.groups').siblings('.checkbox').find('.select_all').prop('checked', false); - } else { + if($checked.hasClass('select_all')) { + if($checked.prop('checked')){ + $checked.closest('.checkbox').siblings('.groups').find('input[type="checkbox"]').prop('checked', true); + $checked.closest('.checkbox').siblings('.groups').find("input[type=hidden]").removeAttr('name'); + }else{ + $checked.closest('.checkbox').siblings('.groups').find('input[type="checkbox"]').prop('checked', false); + $checked.closest('.checkbox').siblings('.groups').find("input[type=hidden]").attr('name', 'page_part['+$checked.closest('.checkbox-groups').data('for')+'][]'); + } + } else if($checked.hasClass('lang-enable')) { if($checked.prop('checked')) { $checked.closest('.active-link').addClass('active').siblings('active-link').removeClass('active').end().find('.active-mune').slideDown(300); if(_status) { @@ -129,6 +132,19 @@ $(function() { $(this).find('input:eq(0)').prop('checked', true); }) } + } else { + var checkboxes_size = $checked.closest('.groups').find("input[type=checkbox]").length, + checked_size = $checked.closest('.groups').find("input:checked").length; + if(checkboxes_size == checked_size) + $checked.closest('.groups').siblings('.checkbox').find('.select_all').prop('checked', true); + else + $checked.closest('.groups').siblings('.checkbox').find('.select_all').prop('checked', false); + + if(checked_size == 0) + $checked.closest('.groups').find("input[type=hidden]").attr('name', 'page['+$checked.closest('.checkbox-groups').data('for')+'][]'); + else + $checked.closest('.groups').find("input[type=hidden]").removeAttr('name'); + } return false; } else if($checked.attr('type') == 'radio' && !$(this).closest('div').hasClass('active-mune')) { diff --git a/app/views/admin/page_parts/edit.html.erb b/app/views/admin/page_parts/edit.html.erb index 36e764e6..d99ece03 100644 --- a/app/views/admin/page_parts/edit.html.erb +++ b/app/views/admin/page_parts/edit.html.erb @@ -97,25 +97,26 @@ <%= f.select :widget_path, @widget_paths, {}, selected: (@part.widget_path rescue nil), class: "input-xlarge change" %> -
+
<%= f.label :categories, t(:categories), class: "control-label muted" %>
<%= content_tag :label, class: "checkbox" do %> - <%= check_box_tag nil, nil, false, class: "select_all" %> <%= t(:all) %> + <%= check_box_tag nil, nil, (@part.category.size == @module_app_categories.size ? true : false), class: "select_all" %> <%= t(:all) %> <% end %>
<%= content_tag_for(:label, @module_app_categories, class: "checkbox inline") do |category|%> <%= check_box_tag("page_part[category][]", category.id, (@part.category.include?(category.id.to_s) rescue false) ) %> <%= category.title %> <% end if @module_app_categories %> +
-
+
<%= f.label :tags, t(:tags), class: "control-label muted" %>
<%= content_tag :label, class: "checkbox" do %> - <%= check_box_tag nil, nil, true, class: "select_all" %> <%= t(:all) %> + <%= check_box_tag nil, nil, (@part.tag.size == @module_app_tags.size ? true : false), class: "select_all" %> <%= t(:all) %> <% end %>
<%= content_tag_for(:label, @module_app_tags, class: "checkbox inline") do |tag|%> @@ -162,8 +163,8 @@ \ No newline at end of file