fixed page setting select all bug

This commit is contained in:
Harry Bomrah 2013-11-07 19:14:53 +08:00
parent 94548a6f31
commit db850a2995
3 changed files with 36 additions and 14 deletions

View File

@ -189,8 +189,11 @@ function pageSetting(id, edit, ps) {
if(_arr !== -1) {
$pageCategory.find('input[type="checkbox"]').eq(index).prop('checked', true);
}
var $all = $pageCategory.siblings('.checkbox').children('.select_all')
_selectData.module.category.length > 1 && _selectData.module.category.length == index + 1 ? $all.prop('checked', true) : $all.prop('checked', false);
var $all = $pageCategory.siblings('.checkbox').children('.select_all'),
$hiddenInput = $pageCategory.siblings('input[type="hidden"]');
_selectData.module.category.length ? $hiddenInput.removeAttr('name') : $hiddenInput.attr('name', 'page[category][]');
_selectData.module.category.length == index + 1 ? $all.prop('checked', true) : $all.prop('checked', false);
console.log($hiddenInput, _selectData.module.category)
});
$pageCategoryGroup.show();
}
@ -201,8 +204,10 @@ function pageSetting(id, edit, ps) {
if(_arr !== -1) {
$pageTags.find('input[type="checkbox"]').eq(index).prop('checked', true);
}
var $all = $pageTags.siblings('.checkbox').children('.select_all')
_selectData.module.tags.length > 1 && _selectData.module.tags.length == index + 1 ? $all.prop('checked', true) : $all.prop('checked', false);
var $all = $pageTags.siblings('.checkbox').children('.select_all'),
$hiddenInput = $pageTags.siblings('input[type="hidden"]');
_selectData.module.tags.length ? $hiddenInput.removeAttr('name') : $hiddenInput.attr('name', 'page[tag][]');
_selectData.module.tags.length == index + 1 ? $all.prop('checked', true) : $all.prop('checked', false);
});
$pageTagsGroup.show();
}
@ -397,6 +402,7 @@ $(function() {
if(event.target.id == 'page_module_app_id') {
$pageCategory.empty();
var $hiddenInputA = $pageCategory.siblings('input[type="hidden"]');
if(val.category.length > 0) {
$.each(val.category, function(index, val) {
if(val !== 0) {
@ -406,14 +412,17 @@ $(function() {
$pageCategory.find('input[type="checkbox"]').eq(index).prop('checked', true);
}
var $all = $pageCategory.siblings('.checkbox').children('.select_all');
_boolean && _val == _select.main && _select.category.length > 1 && _select.category.length == index + 1 ? $all.prop('checked', true) : $all.prop('checked', false);
_val == _select.main && _select.category.length ? $hiddenInputA.removeAttr('name') : $hiddenInputA.attr('name', 'page[category][]');
_boolean && _val == _select.main && _select.category.length == index + 1 ? $all.prop('checked', true) : $all.prop('checked', false);
}
});
$pageCategoryGroup.show();
$pageCategoryGroup.slideDown(300);
} else {
$pageCategoryGroup.hide();
$pageCategoryGroup.slideUp(300);
$hiddenInputA.removeAttr('name');
}
$pageTags.empty();
var $hiddenInputB = $pageTags.siblings('input[type="hidden"]');
if(val.tags.length > 0) {
$.each(val.tags, function(index, val) {
if(val !== 0) {
@ -423,12 +432,14 @@ $(function() {
$pageTags.find('input[type="checkbox"]').eq(index).prop('checked', true);
}
var $all = $pageTags.siblings('.checkbox').children('.select_all');
_boolean && _val == _select.main && _select.tags.length > 1 && _select.tags.length == index + 1 ? $all.prop('checked', true) : $all.prop('checked', false);
_val == _select.main && _select.tags.length ? $hiddenInputB.removeAttr('name') : $hiddenInputB.attr('name', 'page[tag][]');
_boolean && _val == _select.main && _select.tags.length == index + 1 ? $all.prop('checked', true) : $all.prop('checked', false);
}
});
$pageTagsGroup.show();
$pageTagsGroup.slideDown(300);
} else {
$pageTagsGroup.hide();
$pageTagsGroup.slideUp(300);
$hiddenInputB.removeAttr('name');
}
}
return false;
@ -461,8 +472,10 @@ $(function() {
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('input[type="hidden"]').removeAttr('name');
} else {
$checked.closest('.checkbox').siblings('.groups').find('input[type="checkbox"]').prop('checked', false);
$checked.closest('.checkbox').siblings('input[type="hidden"]').attr('name', 'page['+$checked.closest('.checkbox-groups').data('for')+'][]');
}
} else if($checked.hasClass('lang-enable')) {
var checkboxes = $checked.closest('.groups').find('input[type="checkbox"]');
@ -483,10 +496,11 @@ $(function() {
var _l = $checked.closest('.groups').find('input[type="checkbox"]').length,
_c = $checked.closest('.groups').find('input[type="checkbox"]:checked').length;
if(_l == _c) {
$checked.closest('.groups').siblings('.checkbox').find('.select_all').prop('checked', true)
$checked.closest('.groups').siblings('.checkbox').find('.select_all').prop('checked', true);
} else {
$checked.closest('.groups').siblings('.checkbox').find('.select_all').prop('checked', false)
$checked.closest('.groups').siblings('.checkbox').find('.select_all').prop('checked', false);
};
_c == 0 ? $checked.closest('.groups').siblings('input[type="hidden"]').attr('name', 'page['+$checked.closest('.checkbox-groups').data('for')+'][]') : $checked.closest('.groups').siblings('input[type="hidden"]').removeAttr('name');
}
return false;
} else if($checked.attr('type') == 'radio' && !$(this).closest('div').hasClass('active-mune')) {

View File

@ -21,6 +21,12 @@ class Admin::PagesController < Admin::ItemsController
end
def update
if params[:page][:category][0] == ""
params[:page][:category] = []
end
if params[:page][:tag][0] == ""
params[:page][:tag] = []
end
@item = Page.find(params[:id])
if @item.module_app && @item.module_app.key == 'page_content' && @item.page_contexts.blank?
@item.page_contexts.build(:create_user_id => current_user.id, :update_user_id => current_user.id )

View File

@ -28,20 +28,22 @@
<%= select_tag "page[app_frontend_url]", nil, class: "input-xlarge change" %>
</div>
<div class="checkbox-groups hide" id="page-category-groups">
<div class="checkbox-groups hide" id="page-category-groups" data-for="category">
<%= f.label :categories, t(:categories) %>
<%= content_tag :label, class: "checkbox" do %>
<%= check_box_tag nil, nil, true, class: "select_all" %> <%= t(:all) %>
<% end %>
<div class="groups" id="page-category"></div>
<input type="hidden">
</div>
<div class="checkbox-groups hide" id="page-tags-groups">
<div class="checkbox-groups hide" id="page-tags-groups" data-for="tag">
<%= f.label :tags, t(:tags) %>
<%= content_tag :label, class: "checkbox" do %>
<%= check_box_tag nil, nil, true, class: "select_all" %> <%= t(:all) %>
<% end %>
<div class="groups" id="page-tags"></div>
<input type="hidden">
</div>
<div class="display-mode"></div>