ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/Customer/_CreateOrUpdate.TabInfo.cshtml
@model CustomerModel

@if (Model.CountryEnabled && Model.StateProvinceEnabled)
{
    <script>
        $(document).ready(function() {
            $("#@Html.FieldIdFor(model => model.CountryId)").change(function() {
                var selectedItem = $(this).val();
                var ddlStates = $("#@Html.FieldIdFor(model => model.StateProvinceId)");

                var postData = {
                    countryId: selectedItem,
                    addSelectStateItem: "true"
                };

                $.ajax({
                    cache: false,
                    type: "GET",
                    url: "@(Url.Action("GetStatesByCountryId", "Home"))",
                    data: postData,
                    success: function(data) {
                        ddlStates.html('');
                        $.each(data, function(id, option) {
                            ddlStates.append($('<option></option>').val(option.id).html(option.name));
                        });
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
                        alert('Failed to retrieve states.');
                    }
                });
            });
        });
    </script>
}
    <div class="form-horizontal">
        <vc:admin-widget widget-zone="customer_details_info_top" additional-data="Model" />
        <div class="form-body">
            @if (Model.UsernamesEnabled)
            {
                if (String.IsNullOrEmpty(Model.Id) || Model.AllowUsersToChangeUsernames)
                {
                    <div class="form-group">
                        <admin-label asp-for="Username" />
                        <div class="col-md-9 col-sm-9">
                            <admin-input asp-for="Username" />
                            <span asp-validation-for="Username"></span>
                        </div>
                    </div>
                }
                else
                {
                    <div class="form-group">
                        <admin-label asp-for="Username" />
                        <div class="col-md-9 col-sm-9">
                            <label class="control-label"> @Model.Username</label>
                            <input asp-for="Username" type="hidden" />
                        </div>
                    </div>
                }
            }
            <div class="form-group">
                <admin-label asp-for="Email" />
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="Email" />
                    <span asp-validation-for="Email"></span>
                </div>
            </div>
            <div class="form-group">
                <admin-label asp-for="Password" />
                <div class="col-md-9 col-sm-9">
                    <div class="input-group">
                        <div class="input-icon">
                            <i class="fa fa-lock fa-fw"></i>
                            <admin-input asp-for="Password" />
                        </div>
                        <span class="input-group-append">
                            <input type="submit" name="changepassword" class="btn btn-success" value="@T("Admin.Customers.Customers.Fields.Password.Change")" />
                        </span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <admin-label asp-for="CustomerTags" />
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="CustomerTags" />
                    <span asp-validation-for="CustomerTags"></span>
                </div>
            </div>
            @if (!String.IsNullOrEmpty(Model.Id) && Model.AssociatedExternalAuthRecords.Count > 0)
            {
                <div class="form-group">
                    <admin-label asp-for="AssociatedExternalAuthRecords" />
                    <div class="col-md-9 col-sm-9">
                        <div id="externalauthrecords-grid"></div>
                        <script>

                            //local datasource
                            var externalauthrecords = [
                            @for (int i = 0; i < Model.AssociatedExternalAuthRecords.Count; i++)
                            {
                                var aear = Model.AssociatedExternalAuthRecords[i];
                                <text>
                                {
                                    AuthMethodName: "@aear.AuthMethodName",
                                    Email: "@aear.Email",
                                    ExternalIdentifier: "@aear.ExternalIdentifier"
                                }
                                 </text>
                                if (i != Model.AssociatedExternalAuthRecords.Count - 1)
                                {
                                    <text>,</text>
                                }
                            }
                            ];

                            $(document).ready(function () {
                                $("#externalauthrecords-grid").kendoGrid({
                                    dataSource: {
                                        data: externalauthrecords,
                                        schema: {
                                            model: {
                                                fields: {
                                                    AuthMethodName: { type: "string" },
                                                    Email: { type: "string" },
                                                    ExternalIdentifier: { type: "string" }
                                                }
                                            }
                                        },
                                        error: function (e) {
                                            display_kendoui_grid_error(e);
                                            // Cancel the changes
                                            this.cancelChanges();
                                        }
                                    },
                                    pageable: {
                                        refresh: true,
                                        numeric: false,
                                        previousNext: false,
                                        info: false
                                    },
                                    scrollable: false,
                                    columns: [
                                        {
                                            field: "AuthMethodName",
                                            title: "@T("Admin.Customers.Customers.AssociatedExternalAuth.Fields.AuthMethodName")",
                                            width: 100
                                        }, {
                                            field: "Email",
                                            title: "@T("Admin.Customers.Customers.AssociatedExternalAuth.Fields.Email")",
                                            width: 100
                                        },{
                                            field: "ExternalIdentifier",
                                            title: "@T("Admin.Customers.Customers.AssociatedExternalAuth.Fields.ExternalIdentifier")",
                                            width: 300
                                        }
                                    ]
                                });
                            });

                        </script>
                    </div>
                </div>
            }
            <div class="form-group">
                <admin-label asp-for="VendorId" />
                <div class="col-md-9 col-sm-9">
                    <admin-select asp-for="VendorId" asp-items="Model.AvailableVendors" />
                    <span asp-validation-for="VendorId"></span>
                    <em>@T("Admin.Customers.Customers.VendorShouldBeInVendorsRole")</em>
                </div>
            </div>
            <div class="form-group">
                <admin-label asp-for="StaffStoreId" />
                <div class="col-md-9 col-sm-9">
                    <admin-select asp-for="StaffStoreId" asp-items="Model.AvailableStores" />
                    <span asp-validation-for="StaffStoreId"></span>
                </div>
            </div>
            <div class="form-group">
                <admin-label asp-for="Owner" />
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="Owner" />
                    <span asp-validation-for="Owner"></span>
                </div>
            </div>
            @if (Model.GenderEnabled)
            {
                <div class="form-group">
                    <admin-label asp-for="Gender" />
                    <div class="col-md-9 col-sm-9">
                        <div class="gender">
                            @Html.RadioButton("Gender", "M", (Model.Gender == "M"), new { id = "Gender_Male" })
                            <label class="forcheckbox" for="Gender_Male">@T("Admin.Customers.Customers.Fields.Gender.Male")</label>
                        </div>
                        <div class="gender">
                            @Html.RadioButton("Gender", "F", (Model.Gender == "F"), new { id = "Gender_Female" })
                            <label class="forcheckbox" for="Gender_Female">@T("Admin.Customers.Customers.Fields.Gender.Female")</label>
                        </div>
                    </div>
                </div>
            }
            <div class="form-group">
                <admin-label asp-for="FirstName" />
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="FirstName" />
                    <span asp-validation-for="FirstName"></span>
                </div>
            </div>
            <div class="form-group">
                <admin-label asp-for="LastName" />
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="LastName" />
                    <span asp-validation-for="LastName"></span>
                </div>
            </div>
            @if (Model.DateOfBirthEnabled)
            {
                <div class="form-group">
                    <admin-label asp-for="DateOfBirth" />
                    <div class="col-md-9 col-sm-9">
                        <admin-input asp-for="DateOfBirth" />
                        <span asp-validation-for="DateOfBirth"></span>
                    </div>
                </div>
            }
            @if (Model.CompanyEnabled)
            {
                <div class="form-group">
                    <admin-label asp-for="Company" />
                    <div class="col-md-9 col-sm-9">
                        <admin-input asp-for="Company" />
                        <span asp-validation-for="Company"></span>
                    </div>
                </div>
            }
            @if (Model.StreetAddressEnabled)
            {
                <div class="form-group">
                    <admin-label asp-for="StreetAddress" />
                    <div class="col-md-9 col-sm-9">
                        <admin-input asp-for="StreetAddress" />
                        <span asp-validation-for="StreetAddress"></span>
                    </div>
                </div>
            }
            @if (Model.StreetAddress2Enabled)
            {
                <div class="form-group">
                    <admin-label asp-for="StreetAddress2" />
                    <div class="col-md-9 col-sm-9">
                        <admin-input asp-for="StreetAddress2" />
                        <span asp-validation-for="StreetAddress2"></span>
                    </div>
                </div>
            }
            @if (Model.ZipPostalCodeEnabled)
            {
                <div class="form-group">
                    <admin-label asp-for="ZipPostalCode" />
                    <div class="col-md-9 col-sm-9">
                        <admin-input asp-for="ZipPostalCode" />
                        <span asp-validation-for="ZipPostalCode"></span>
                    </div>
                </div>
            }
            @if (Model.CityEnabled)
            {
                <div class="form-group">
                    <admin-label asp-for="City" />
                    <div class="col-md-9 col-sm-9">
                        <admin-input asp-for="City" />
                        <span asp-validation-for="City"></span>
                    </div>
                </div>
            }
            @if (Model.CountryEnabled)
            {
                <div class="form-group">
                    <admin-label asp-for="CountryId" />
                    <div class="col-md-9 col-sm-9">
                        <admin-select asp-for="CountryId" asp-items="Model.AvailableCountries" />
                        <span asp-validation-for="CountryId"></span>
                    </div>
                </div>
            }
            @if (Model.CountryEnabled && Model.StateProvinceEnabled)
            {
                <div class="form-group">
                    <admin-label asp-for="StateProvinceId" />
                    <div class="col-md-9 col-sm-9">
                        <admin-select asp-for="StateProvinceId" asp-items="Model.AvailableStates" />
                        <span asp-validation-for="StateProvinceId"></span>
                    </div>
                </div>
            }
            @if (Model.PhoneEnabled)
            {
                <div class="form-group">
                    <admin-label asp-for="Phone" />
                    <div class="col-md-9 col-sm-9">
                        <admin-input asp-for="Phone" />
                        <span asp-validation-for="Phone"></span>
                    </div>
                </div>
            }
            @if (Model.FaxEnabled)
            {
                <div class="form-group">
                    <admin-label asp-for="Fax" />
                    <div class="col-md-9 col-sm-9">
                        <admin-input asp-for="Fax" />
                        <span asp-validation-for="Fax"></span>
                    </div>
                </div>
            }
            @if (Model.CustomerAttributes.Count > 0)
            {
                <div class="form-group">
                    <partial name="_CustomerAttributes" model="Model.CustomerAttributes" />
                </div>
            }
            <div class="form-group">
                <admin-label asp-for="AdminComment" />
                <div class="col-md-9 col-sm-9">
                    <admin-textarea asp-for="AdminComment"></admin-textarea>
                    <span asp-validation-for="AdminComment"></span>
                </div>
            </div>
            <div class="form-group">
                <admin-label asp-for="IsTaxExempt" />
                <div class="col-md-9 col-sm-9">
                    <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
                        <admin-input asp-for="IsTaxExempt" />
                        <div class="control__indicator"></div>
                    </label>
                    <span asp-validation-for="IsTaxExempt"></span>
                </div>
            </div>
            <div class="form-group">
                <admin-label asp-for="FreeShipping" />
                <div class="col-md-9 col-sm-9">
                    <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
                        <admin-input asp-for="FreeShipping" />
                        <div class="control__indicator"></div>
                    </label>
                    <span asp-validation-for="FreeShipping"></span>
                </div>
            </div>
            @if (Model.AllowCustomersToSetTimeZone)
            {
                <div class="form-group">
                    <admin-label asp-for="TimeZoneId" />
                    <div class="col-md-9 col-sm-9">
                        <admin-select asp-for="TimeZoneId" asp-items="Model.AvailableTimeZones" />
                        <span asp-validation-for="TimeZoneId"></span>
                    </div>
                </div>
            }
            @if (!String.IsNullOrEmpty(Model.AffiliateId))
            {
                <div class="form-group">
                    <admin-label asp-for="AffiliateId" />
                    <div class="col-md-9 col-sm-9">
                        <a class="k-button" href="@Url.Action("Edit", "Affiliate", new { id = Model.AffiliateId })"><span class="k-icon k-i-eye"></span>&nbsp;@Model.AffiliateName - @T("Admin.Common.View")</a>
                        <button type="submit" name="remove-affiliate" class="k-button red"><span class="k-icon k-i-delete"></span>&nbsp;@T("Admin.Customers.Customers.Fields.Affiliate.Remove")</button>
                    </div>
                </div>
            }
            @if (Model.DisplayVatNumber)
            {
                <div class="form-group">
                    <admin-label asp-for="VatNumber" />
                    <div class="col-md-9 col-sm-9">
                        <div class="input-group-control">
                            <admin-input asp-for="VatNumber" />
                            <label class="control-label">
                                (@string.Format(T("Admin.Customers.Customers.Fields.VatNumberStatus").Text, Model.VatNumberStatusNote))
                            </label>
                            <input type="submit" name="markVatNumberAsValid" class="btn green" value="@T("Admin.Customers.Customers.Fields.VatNumber.MarkAsValid")" />
                            <input type="submit" name="markVatNumberAsInvalid" class="btn red" value="@T("Admin.Customers.Customers.Fields.VatNumber.MarkAsInvalid")" />
                        </div>
                        <span asp-validation-for="VatNumber"></span>
                    </div>
                </div>
            }
            @if (Model.AvailableNewsletterSubscriptionStores != null && Model.AvailableNewsletterSubscriptionStores.Count > 0)
            {
                <div class="form-group">
                    <admin-label asp-for="SelectedNewsletterSubscriptionStoreIds" />
                    <div class="col-md-9 col-sm-9">
                        @foreach (var store in Model.AvailableNewsletterSubscriptionStores)
                        {
                            <div>
                                <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
                                    <input type="checkbox" name="SelectedNewsletterSubscriptionStoreIds" value="@store.Id" checked="@(Model.SelectedNewsletterSubscriptionStoreIds != null && Model.SelectedNewsletterSubscriptionStoreIds.Contains(store.Id))" />(@(store.Name))
                                    <div class="control__indicator"></div>
                                </label>

                            </div>

                        }
                    </div>
                </div>
            }
            else
            {
                <div class="note note-info">
                    @T("Admin.Customers.Customers.Fields.CustomerRoles.NoRoles")
                </div>
            }
            <div class="form-group">
                <admin-label asp-for="Active" />
                <div class="col-md-9 col-sm-9">
                    <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
                        <admin-input asp-for="Active" />
                        <div class="control__indicator"></div>
                    </label>
                    <span asp-validation-for="Active"></span>
                </div>
            </div>
            @if (!String.IsNullOrEmpty(Model.Id))
            {
                <div class="form-group">
                    <admin-label asp-for="LastIpAddress" />
                    <div class="col-md-9 col-sm-9">
                        <label class="control-label">@Model.LastIpAddress</label>
                    </div>
                </div>
            }
            @if (!String.IsNullOrEmpty(Model.Id) && !String.IsNullOrEmpty(Model.UrlReferrer))
            {
                <div class="form-group">
                    <admin-label asp-for="UrlReferrer" />
                    <div class="col-md-9 col-sm-9">
                        <label class="control-label">@Model.UrlReferrer</label>
                    </div>
                </div>
            }
            @if (!String.IsNullOrEmpty(Model.Id))
            {
                <div class="form-group">
                    <admin-label asp-for="CreatedOn" />
                    <div class="col-md-9 col-sm-9">
                        <label class="control-label">@Model.CreatedOn</label>
                    </div>
                </div>
            }
            @if (!String.IsNullOrEmpty(Model.Id))
            {
                <div class="form-group">
                    <admin-label asp-for="LastActivityDate" />
                    <div class="col-md-9 col-sm-9">
                        <label class="control-label">@Model.LastActivityDate</label>
                    </div>
                </div>
            }
            @if (!String.IsNullOrEmpty(Model.Id) && !String.IsNullOrEmpty(Model.LastVisitedPage))
            {
                <div class="form-group">
                    <admin-label asp-for="LastVisitedPage" />
                    <div class="col-md-9 col-sm-9">
                        <label class="control-label">@Model.LastVisitedPage</label>
                    </div>
                </div>
            }
            @if (!String.IsNullOrEmpty(Model.Id) && !String.IsNullOrEmpty(Model.LastUrlReferrer))
            {
                <div class="form-group">
                    <admin-label asp-for="LastUrlReferrer" />
                    <div class="col-md-9 col-sm-9">
                        <label class="control-label">@Model.LastUrlReferrer</label>
                    </div>
                </div>
            }
            @if (!String.IsNullOrEmpty(Model.Id) && Model.LastPurchaseDate.HasValue)
            {
                <div class="form-group">
                    <admin-label asp-for="LastPurchaseDate" />
                    <div class="col-md-9 col-sm-9">
                        <label class="control-label">@Model.LastPurchaseDate</label>
                    </div>
                </div>
            }
        </div>
        <vc:admin-widget widget-zone="customer_details_info_bottom" additional-data="Model" />
    </div>

