diff --git a/app/assets/javascripts/lib/items/page_part.js.erb b/app/assets/javascripts/lib/items/page_part.js.erb index 2e2851787..5f8b2c19a 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 36e764e69..d99ece03b 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" %> -