app/Plugin/CategoryDisplaySelected42/Resource/template/admin/product_category_add_snippet.twig line 1

Open in your IDE?
  1. <script type="text/javascript">
  2.     $(function () {
  3.         // append to layout
  4.         $(".c-secondaryCol").find('.card.rounded').eq(0).after($("#category_display_selected42_selected_category").detach());
  5.         $('[data-bs-toggle="tooltip"]').tooltip();
  6.         // 「カテゴリ検索を空にする」「カテゴリを全て外す」ボタンを、
  7.         // 「カテゴリ」欄の「カテゴリの追加・編集」ボタンの直上に差し込む。
  8.         // サーバー側のテンプレート文字列一致に頼ると、コアテンプレートの改行・空白の
  9.         // わずかな差異で挿入に失敗することがあるため、DOM操作(既存の選択済みカテゴリ欄の
  10.         // 移動と同じ手法)で確実に配置する。
  11.         var $moveToCategoryButton = $('#category .d-block.text-center').first();
  12.         if ($moveToCategoryButton.length) {
  13.             $moveToCategoryButton.before(
  14.                 '<div class="d-block text-center mb-2">' +
  15.                 '<button type="button" class="btn w-100 btn-ec-regular mb-2" id="category_display_selected42_search_category_reset">カテゴリ検索を空にする</button>' +
  16.                 '<button type="button" class="btn w-100 btn-ec-regular mb-2" id="category_display_selected42_category_reset">カテゴリを全て外す</button>' +
  17.                 '</div>'
  18.             );
  19.         }
  20.         $("#category_display_selected42_selected_category").show();
  21.         $('.category-label').on('click', function() {
  22.             $('#search-category').val($(this).text())
  23.             searchWord($(this).text(), $('.category-li'));
  24.         });
  25.         function resetSearchCategory() {
  26.             $('#search-category').val('')
  27.             searchWord('', $('.category-li'));
  28.         }
  29.         $('#category_display_selected42_category_reset').on('click', function() {
  30.             if (confirm('{{ 'category_display_selected42.admin_product_selected_category.unchecked_register_category'|trans }}')) {
  31.                 var categoryList = $('#category .c-directoryTree--register').find('input[type="checkbox"][id^="admin_product_category"]');
  32.                 categoryList.each(function(){
  33.                     $(this).removeAttr("checked").prop("checked", false).change();
  34.                 });
  35.                 resetSearchCategory();
  36.                 // 「選択済みカテゴリ」欄はページ読み込み時の静的表示のため、
  37.                 // チェックを外しただけでは表示が更新されない。ここで明示的に空表示へ切り替える。
  38.                 $('#category_display_selected42_pic_category .card-body').html(
  39.                     '<div>{{ 'category_display_selected42.admin_product_selected_category.nothing_register_category'|trans }}</div>'
  40.                 );
  41.             } else {
  42.                 //キャンセル
  43.                 return false
  44.             }
  45.         });
  46.         $('#category_display_selected42_search_category_reset').on('click', function() {
  47.             resetSearchCategory();
  48.         });
  49.     })
  50. </script>
  51. <div id="category_display_selected42_selected_category" class="card rounded border-0 mb-4" style="display: none;">
  52.     <div class="card-header">
  53.         <div class="row">
  54.             <div class="col-8">
  55.                 <div class="d-inline-block" data-bs-toggle="tooltip" data-bs-placement="top" title="{{ 'category_display_selected42.admin_product_selected_category.tooltip'|trans }}">
  56.                     <span class="card-title">
  57.                         {{ 'category_display_selected42.admin_product_selected_category.title'|trans }}
  58.                     </span>
  59.                     <i class="fa fa-question-circle fa-lg ms-1"></i>
  60.                 </div>
  61.             </div>
  62.             <div class="col-4 text-end">
  63.                 <a data-bs-toggle="collapse" href="#category_display_selected42_pic_category" aria-expanded="false"
  64.                    aria-controls="category">
  65.                     <i class="fa fa-angle-up fa-lg"></i>
  66.                 </a>
  67.             </div>
  68.         </div>
  69.     </div>
  70.     <div class="collapse show ec-cardCollapse" id="category_display_selected42_pic_category">
  71.         <div class="card-body">
  72.             {% if ChoicedCategoryIds|length > 0 %}
  73.                 <div class="c-directoryTree--register rounded border mb-3 p-3">
  74.                     {% import _self as CategoryDisplaySelected42Macro %}
  75.                     {% for TopCategory in TopCategories %}
  76.                         <ul class="list-unstyled">
  77.                             {{ CategoryDisplaySelected42Macro.CategoryDisplaySelected42Tree(ChoicedCategoryIds, TopCategory, form.Category) }}
  78.                         </ul>
  79.                     {% endfor %}
  80.                 </div>
  81.                 {% macro CategoryDisplaySelected42Tree(ChoicedIds, Category, form) %}
  82.                     {% import _self as CategoryDisplaySelected42SelfMacro %}
  83.                     {% if Category.id in ChoicedIds %}
  84.                         <li class="c-directoryTree--registerItem">
  85.                             <label class="category-label">{{ Category.name }}</label>
  86.                             <ul class="list-unstyled">
  87.                                 {% for child,ChildCategory in Category.children %}
  88.                                     {{ CategoryDisplaySelected42SelfMacro.CategoryDisplaySelected42Tree(ChoicedIds, ChildCategory, form) }}
  89.                                 {% endfor %}
  90.                             </ul>
  91.                         </li>
  92.                     {% endif %}
  93.                 {% endmacro %}
  94.             {% else %}
  95.                 <div>
  96.                     {{ 'category_display_selected42.admin_product_selected_category.nothing_register_category'|trans}}
  97.                 </div>
  98.             {% endif %}
  99.         </div>
  100.     </div>
  101. </div>