<script type="text/javascript">
$(function () {
// append to layout
$(".c-secondaryCol").find('.card.rounded').eq(0).after($("#category_display_selected42_selected_category").detach());
$('[data-bs-toggle="tooltip"]').tooltip();
// 「カテゴリ検索を空にする」「カテゴリを全て外す」ボタンを、
// 「カテゴリ」欄の「カテゴリの追加・編集」ボタンの直上に差し込む。
// サーバー側のテンプレート文字列一致に頼ると、コアテンプレートの改行・空白の
// わずかな差異で挿入に失敗することがあるため、DOM操作(既存の選択済みカテゴリ欄の
// 移動と同じ手法)で確実に配置する。
var $moveToCategoryButton = $('#category .d-block.text-center').first();
if ($moveToCategoryButton.length) {
$moveToCategoryButton.before(
'<div class="d-block text-center mb-2">' +
'<button type="button" class="btn w-100 btn-ec-regular mb-2" id="category_display_selected42_search_category_reset">カテゴリ検索を空にする</button>' +
'<button type="button" class="btn w-100 btn-ec-regular mb-2" id="category_display_selected42_category_reset">カテゴリを全て外す</button>' +
'</div>'
);
}
$("#category_display_selected42_selected_category").show();
$('.category-label').on('click', function() {
$('#search-category').val($(this).text())
searchWord($(this).text(), $('.category-li'));
});
function resetSearchCategory() {
$('#search-category').val('')
searchWord('', $('.category-li'));
}
$('#category_display_selected42_category_reset').on('click', function() {
if (confirm('{{ 'category_display_selected42.admin_product_selected_category.unchecked_register_category'|trans }}')) {
var categoryList = $('#category .c-directoryTree--register').find('input[type="checkbox"][id^="admin_product_category"]');
categoryList.each(function(){
$(this).removeAttr("checked").prop("checked", false).change();
});
resetSearchCategory();
// 「選択済みカテゴリ」欄はページ読み込み時の静的表示のため、
// チェックを外しただけでは表示が更新されない。ここで明示的に空表示へ切り替える。
$('#category_display_selected42_pic_category .card-body').html(
'<div>{{ 'category_display_selected42.admin_product_selected_category.nothing_register_category'|trans }}</div>'
);
} else {
//キャンセル
return false
}
});
$('#category_display_selected42_search_category_reset').on('click', function() {
resetSearchCategory();
});
})
</script>
<div id="category_display_selected42_selected_category" class="card rounded border-0 mb-4" style="display: none;">
<div class="card-header">
<div class="row">
<div class="col-8">
<div class="d-inline-block" data-bs-toggle="tooltip" data-bs-placement="top" title="{{ 'category_display_selected42.admin_product_selected_category.tooltip'|trans }}">
<span class="card-title">
{{ 'category_display_selected42.admin_product_selected_category.title'|trans }}
</span>
<i class="fa fa-question-circle fa-lg ms-1"></i>
</div>
</div>
<div class="col-4 text-end">
<a data-bs-toggle="collapse" href="#category_display_selected42_pic_category" aria-expanded="false"
aria-controls="category">
<i class="fa fa-angle-up fa-lg"></i>
</a>
</div>
</div>
</div>
<div class="collapse show ec-cardCollapse" id="category_display_selected42_pic_category">
<div class="card-body">
{% if ChoicedCategoryIds|length > 0 %}
<div class="c-directoryTree--register rounded border mb-3 p-3">
{% import _self as CategoryDisplaySelected42Macro %}
{% for TopCategory in TopCategories %}
<ul class="list-unstyled">
{{ CategoryDisplaySelected42Macro.CategoryDisplaySelected42Tree(ChoicedCategoryIds, TopCategory, form.Category) }}
</ul>
{% endfor %}
</div>
{% macro CategoryDisplaySelected42Tree(ChoicedIds, Category, form) %}
{% import _self as CategoryDisplaySelected42SelfMacro %}
{% if Category.id in ChoicedIds %}
<li class="c-directoryTree--registerItem">
<label class="category-label">{{ Category.name }}</label>
<ul class="list-unstyled">
{% for child,ChildCategory in Category.children %}
{{ CategoryDisplaySelected42SelfMacro.CategoryDisplaySelected42Tree(ChoicedIds, ChildCategory, form) }}
{% endfor %}
</ul>
</li>
{% endif %}
{% endmacro %}
{% else %}
<div>
{{ 'category_display_selected42.admin_product_selected_category.nothing_register_category'|trans}}
</div>
{% endif %}
</div>
</div>
</div>