ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/ContactAttribute/_CreateOrUpdate.TabCondition.cshtml
@model ContactAttributeModel
<vc:admin-widget widget-zone="contact_attribute_details_condition_top" additional-data="Model" />
@{
    if (!String.IsNullOrEmpty(Model.Id))
    {
        <script>
                    $(document).ready(function () {
                        $("#@Html.FieldIdFor(model => model.ConditionModel.EnableCondition)").click(toggleEnableCondition);
                        toggleEnableCondition();
                    });

                    function toggleEnableCondition() {
                        if ($('#@Html.FieldIdFor(model => model.ConditionModel.EnableCondition)').is(':checked')) {
                            $('#pnlAttributes').show();
                        } else {
                            $('#pnlAttributes').hide();
                        }
                    }
        </script>

        <div class="form-horizontal">
            <div class="form-body">
                <div class="form-group">
                    <admin-label asp-for="ConditionModel.EnableCondition" />
                    <div class="col-md-9 col-sm-9">
                        <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
                            <admin-input asp-for="ConditionModel.EnableCondition" />
                             <div class="control__indicator"></div>
                        </label>
                        <span asp-validation-for="ConditionModel.EnableCondition"></span>
                    </div>
                </div>
            </div>
        </div>
        <div id="pnlAttributes">
            @if (Model.ConditionModel.ConditionAttributes.Count > 0)
            {
                <div class="form-horizontal">
                    <div class="form-body">
                        <div class="form-group">
                            <admin-label asp-for="ConditionModel.SelectedAttributeId" />
                            <div class="col-md-9 col-sm-9">
                                <admin-select asp-for="ConditionModel.SelectedAttributeId" asp-items="Model.ConditionModel.ConditionAttributes.Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString() })" />
                                <script>
                                    $(document).ready(function() {
                                        $("#@Html.FieldIdFor(model => model.ConditionModel.SelectedAttributeId)").change(toggleConditionAttributes);
                                        toggleConditionAttributes();
                                    });
                                    function toggleConditionAttributes() {
                                        var selectedContactAttributeId = $("#@Html.FieldIdFor(model => model.ConditionModel.SelectedAttributeId)").val();
                                        $('[id^="pnl_attribute_values_"]').hide();
                                        $('#pnl_attribute_values_' + selectedContactAttributeId).show();
                                    }
                                </script>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3"></label>
                            <div class="col-md-9 col-sm-9">
                                @for (int i = 0; i < Model.ConditionModel.ConditionAttributes.Count; i++)
                                {
                                    <input type="hidden" asp-for="@Model.ConditionModel.ConditionAttributes[i].Id" />
                                    <div id="@string.Format("pnl_attribute_values_{0}", Model.ConditionModel.ConditionAttributes[i].Id)">
                                        @switch (Model.ConditionModel.ConditionAttributes[i].AttributeControlType)
                                        {
                                            case AttributeControlType.DropdownList:
                                                <admin-select asp-for="@Model.ConditionModel.ConditionAttributes[i].SelectedValueId" asp-items="Model.ConditionModel.ConditionAttributes[i].Values" />
                                                break;
                                            case AttributeControlType.RadioList:
                                            case AttributeControlType.ColorSquares:
                                            case AttributeControlType.ImageSquares:
                                                foreach (var value in Model.ConditionModel.ConditionAttributes[i].Values)
                                                {
                                        <div>
                                            <input type="radio" asp-for="@Model.ConditionModel.ConditionAttributes[i].SelectedValueId" value="@value.Value" checked="@value.Selected" />
                                            <label class="control-label">@value.Text</label>
                                        </div>
                                                }
                                                break;
                                            case AttributeControlType.Checkboxes:
                                                for (var j = 0; j < Model.ConditionModel.ConditionAttributes[i].Values.Count; j++)
                                                {
                                                    <div>
                                                        <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
                                                            <input type="hidden" asp-for="@Model.ConditionModel.ConditionAttributes[i].Values[j].Value" />
                                                            <admin-input asp-for="@Model.ConditionModel.ConditionAttributes[i].Values[j].Selected" />
                                                            @Model.ConditionModel.ConditionAttributes[i].Values[j].Text
                                                             <div class="control__indicator"></div>
                                                        </label>
                                                    </div>
                                                }
                                                break;
                                            case AttributeControlType.ReadonlyCheckboxes:
                                            case AttributeControlType.TextBox:
                                            case AttributeControlType.MultilineTextbox:
                                            case AttributeControlType.Datepicker:
                                            case AttributeControlType.FileUpload:
                                            default:
                                                //not supported as conditions
                                                break;
                                        }
                                    </div>
                                }
                            </div>
                        </div>
                    </div>
                </div>
            }
            else
            {
                <div class="note note-info">
                    @T("Admin.Catalog.Attributes.ContactAttributes.Condition.NoAttributeExists")
                </div>
            }
        </div>
    }
    else
    {
        <div class="note note-info">
            @T("Admin.Catalog.Attributes.ContactAttributes.Condition.SaveBeforeEdit")
        </div>
    }
}
<vc:admin-widget widget-zone="contact_attribute_details_condition_bottom" additional-data="Model" />