diff --git a/app/components/tag_rule_form_component/tag_rule_form_component.html.haml b/app/components/tag_rule_form_component/tag_rule_form_component.html.haml index a6eee8116a..867a433c67 100644 --- a/app/components/tag_rule_form_component/tag_rule_form_component.html.haml +++ b/app/components/tag_rule_form_component/tag_rule_form_component.html.haml @@ -26,5 +26,5 @@ = rule_data[:text_bottom] %td %div - = render partial: rule_data[:input_template], locals: { rule: rule, index: index } + = render partial: "admin/tag_rules/filter_input" , locals: { rule: rule, index: index, field_name: rule_data[:visibility_field] } diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb index c6f3c043f1..e80d54e06a 100644 --- a/app/helpers/admin/enterprises_helper.rb +++ b/app/helpers/admin/enterprises_helper.rb @@ -83,28 +83,28 @@ module Admin text_top: t('js.admin.tag_rules.shipping_method_tagged_top'), text_bottom: t('js.admin.tag_rules.shipping_method_tagged_bottom'), taggable: "shipping_method", - input_template: "admin/tag_rules/filter_shipping_methods_input", + visibility_field: "shipping_methods", } when "TagRule::FilterPaymentMethods" { text_top: t('js.admin.tag_rules.payment_method_tagged_top'), text_bottom: t('js.admin.tag_rules.payment_method_tagged_bottom'), taggable: "payment_method", - input_template: "admin/tag_rules/filter_payment_methods_input", + visibility_field: "payment_methods", } when "TagRule::FilterOrderCycles" { text_top: t('js.admin.tag_rules.order_cycle_tagged_top'), text_bottom: t('js.admin.tag_rules.order_cycle_tagged_bottom'), taggable: "exchange", - input_template: "admin/tag_rules/filter_order_cycles_input", + visibility_field: "order_cycles", } when "TagRule::FilterProducts" { text_top: t('js.admin.tag_rules.inventory_tagged_top'), text_bottom: t('js.admin.tag_rules.inventory_tagged_bottom'), taggable: "variant", - input_template: "admin/tag_rules/filter_products_input", + visibility_field: "variants", } end diff --git a/app/views/admin/tag_rules/_filter_input.html.haml b/app/views/admin/tag_rules/_filter_input.html.haml new file mode 100644 index 0000000000..4e7f2c73d8 --- /dev/null +++ b/app/views/admin/tag_rules/_filter_input.html.haml @@ -0,0 +1,8 @@ +%div + - visibility_field_name = "preferred_matched_#{field_name}_visibility" + - if rule.is_default + = hidden_field_tag "enterprise[tag_rules_attributes][#{index}][#{visibility_field_name}]", "hidden" + %span.text-normal + = t(:not_visible) + - else + = select_tag "enterprise[tag_rules_attributes][#{index}][#{visibility_field_name}]", options_for_select(@visibility_options, rule.public_send(visibility_field_name.to_sym) ), { "data-controller": "tom-select", class: "primary no-search" } diff --git a/app/views/admin/tag_rules/_filter_order_cycles_input.html.haml b/app/views/admin/tag_rules/_filter_order_cycles_input.html.haml deleted file mode 100644 index ec04f837a8..0000000000 --- a/app/views/admin/tag_rules/_filter_order_cycles_input.html.haml +++ /dev/null @@ -1,9 +0,0 @@ -%div - - if rule.is_default - = hidden_field_tag "enterprise[tag_rules_attributes][#{index}][preferred_matched_order_cycles_visibility]", "hidden" - %span.text-normal - =t(:not_visible) - - else - - #TODO - %input.fullwidth.light.ofn-select2{ id: "enterprise_tag_rules_attributes_#{index}_preferred_matched_order_cycles_visibility", name: "enterprise[tag_rules_attributes][#{index}][preferred_matched_order_cycles_visibility]", data: 'visibilityOptions', "min-search": 5, "ng-model": "rule.preferred_matched_order_cycles_visibility", "ng-if": "!rule.is_default" } - diff --git a/app/views/admin/tag_rules/_filter_payment_methods_input.html.haml b/app/views/admin/tag_rules/_filter_payment_methods_input.html.haml deleted file mode 100644 index 564fd722c2..0000000000 --- a/app/views/admin/tag_rules/_filter_payment_methods_input.html.haml +++ /dev/null @@ -1,10 +0,0 @@ -%div - - - if rule.is_default - = hidden_field_tag "enterprise[tag_rules_attributes][#{index}][preferred_matched_payment_methods_visibility]", "hidden" - %span.text-normal - = t(:not_visible) - - else - - #TODO - %input.fullwidth.light.ofn-select2{ id: "enterprise_tag_rules_attributes_#{index}_preferred_matched_payment_methods_visibility", name: "enterprise[tag_rules_attributes][#{index}][preferred_matched_payment_methods_visibility]", data: 'visibilityOptions', "min-search": 5, "ng-model": "rule.preferred_matched_payment_methods_visibility", "ng-if": "!rule.is_default" } - diff --git a/app/views/admin/tag_rules/_filter_products_input.html.haml b/app/views/admin/tag_rules/_filter_products_input.html.haml deleted file mode 100644 index ff6c4c9f10..0000000000 --- a/app/views/admin/tag_rules/_filter_products_input.html.haml +++ /dev/null @@ -1,9 +0,0 @@ -%div - - if rule.is_default - = hidden_field_tag "enterprise[tag_rules_attributes][#{index}][preferred_matched_variants_visibility]", "hidden" - %span.text-normal - = t(:not_visible) - - else - - #TODO - %input.fullwidth.light.ofn-select2{ id: "enterprise_tag_rules_attributes_#{index}_preferred_matched_variants_visibility", name: "enterprise[tag_rules_attributes][#{index}][preferred_matched_variants_visibility]", data: 'visibilityOptions', "min-search": 5, "ng-model": "rule.preferred_matched_variants_visibility", "ng-if": "!rule.is_default" } - diff --git a/app/views/admin/tag_rules/_filter_shipping_methods_input.html.haml b/app/views/admin/tag_rules/_filter_shipping_methods_input.html.haml deleted file mode 100644 index ad71207ee6..0000000000 --- a/app/views/admin/tag_rules/_filter_shipping_methods_input.html.haml +++ /dev/null @@ -1,9 +0,0 @@ -%div - - if rule.is_default - = hidden_field_tag "enterprise[tag_rules_attributes][#{index}][preferred_matched_shipping_methods_visibility]", "hidden" - %span.text-normal - = t(:not_visible) - - else - - #TODO - %input.fullwidth.light.ofn-select2{ id: "enterprise_tag_rules_attributes_#{index}_preferred_matched_shipping_methods_visibility", name: "enterprise[tag_rules_attributes][#{index}][preferred_matched_shipping_methods_visibility]", data: 'visibilityOptions', "min-search": 5, "ng-model": "rule.preferred_matched_shipping_methods_visibility", "ng-if": "!rule.is_default" } -