Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

9.7 KB
Raw Blame
@using Grand.Business.Core.Interfaces.Storage
@using Grand.Domain.Media
@model IList<ContactUsModel.ContactAttributeModel>
@inject IDownloadService downloadService

@if (Model.Any())
{
    <div class="form-group contact-attributes">
        @foreach (var attribute in Model)
        {
            var controlId = $"contact_attribute_{attribute.Id}";
            var controlName = $"attributes[{attribute.Id}]";
            var textPrompt = !string.IsNullOrEmpty(attribute.TextPrompt) ? attribute.TextPrompt : attribute.Name;
            <div id="@($"contact_attribute_label_{attribute.Id}")" class="col-12 px-0">
                <span class="col-form-label text-prompt">
                    @textPrompt
                </span>
                @if (attribute.IsRequired)
                {
                    <span class="required">*</span>
                }

                @switch (attribute.AttributeControlType)
                {
                    case AttributeControlType.TextBox:
                    {
                        <label for="@(controlId)" class="visually-hidden">"@(controlId)</label>
                        <input name="@(controlName)" type="text" class="form-control textbox" id="@(controlId)" value="@(attribute.DefaultValue)"/>
                    }
                        break;
                    case AttributeControlType.DropdownList:
                    {
                        <label for="@(controlId)" class="visually-hidden">"@(controlId)</label>
                        <select id="@(controlId)" class="form-control form-select" name="@(controlName)">
                            @if (!attribute.IsRequired)
                            {
                                <option value="">---</option>
                            }
                            @foreach (var attributeValue in attribute.Values)
                            {
                                var attributeName = attributeValue.Name;
                                <option selected="@attributeValue.IsPreSelected" value="@(attributeValue.Id)">@attributeName</option>
                            }
                        </select>
                    }
                        break;
                    case AttributeControlType.RadioList:
                    {
                        <ul class="option-list ps-0">
                            @foreach (var attributeValue in attribute.Values)
                            {
                                var attributeName = attributeValue.Name;
                                <li>
                                    <fieldset>
                                        <legend class="visually-hidden">
                                            @(controlId)
                                        </legend>
                                        <label class="form-check">
                                            <input class="form-check-input" id="@(controlId)_@(attributeValue.Id)" type="radio" name="@(controlName)" value="@attributeValue.Id" checked="@attributeValue.IsPreSelected"/>
                                            <span class="form-check-label"></span>
                                            <span class="custom-control-description" for="@(controlId)_@(attributeValue.Id)">@attributeName</span>
                                        </label>

                                    </fieldset>
                                </li>
                            }
                        </ul>
                    }
                        break;
                    case AttributeControlType.Checkboxes:
                    case AttributeControlType.ReadonlyCheckboxes:
                    {
                        <fieldset>
                            <ul class="option-list ps-0">
                                @foreach (var attributeValue in attribute.Values.OrderBy(x => x.DisplayOrder))
                                {
                                    var attributeName = attributeValue.Name;
                                    <li>
                                        <label class="form-check">
                                            <input class="form-check-input" id="@(controlId)_@(attributeValue.Id)" type="checkbox" name="@(controlName)" value="@(attributeValue.Id)" checked="@(attributeValue.IsPreSelected)" @(attribute.AttributeControlType == AttributeControlType.ReadonlyCheckboxes ? Html.Raw(" disabled=\"disabled\"") : null)/>
                                            <span class="form-check-label"></span>
                                            <span class="custom-control-description" for="@(controlId)_@(attributeValue.Id)">@attributeName</span>
                                        </label>
                                    </li>
                                }
                            </ul>
                        </fieldset>
                    }
                        break;

                    case AttributeControlType.MultilineTextbox:
                    {
                        <textarea id="@(controlId)" name="@(controlId)">@(attribute.DefaultValue)</textarea>
                    }
                        break;
                    case AttributeControlType.Datepicker:
                    {
                        <date-picker-dropdown control-day="@($"attributes[{attribute.Id}_day]")"
                                              control-month="@($"attributes[{attribute.Id}_month]")"
                                              control-year="@($"attributes[{attribute.Id}_year]")"
                                              begin-year="@(DateTime.Now.Year)"
                                              end-year="@(DateTime.Now.Year + 1)"
                                              selected-day="attribute.SelectedDay ?? 0"
                                              selected-month="attribute.SelectedMonth ?? 0"
                                              selected-year="attribute.SelectedYear ?? 0"
                                              PartialViewName="Partials/DatePickerDropDowns"
                                              class="input-group"/>
                    }
                        break;
                    case AttributeControlType.FileUpload:
                    {
                        Download download = null;
                        if (!string.IsNullOrEmpty(attribute.DefaultValue))
                        {
                            download = await downloadService.GetDownloadByGuid(new Guid(attribute.DefaultValue));
                        }

                        //ex. ['jpg', 'jpeg', 'png', 'gif'] or []
                        var allowedFileExtensions = string.Join(", ", attribute.AllowedFileExtensions.Select(x => "" + x.Trim() + "").ToList());

                        @* one hidden value per attribute - two inputs of the same name posted ",<guid>",
                           which is no guid - and everything the upload script touches kept inside this
                           attribute's container, so a second file attribute does not update the first *@
                        <div class="contact-attribute-upload">
                            <input class="form-control" type="file" accept="@Html.Raw(allowedFileExtensions)" id="upload_@(attribute.Id)" name="qqfile" data-url="@Url.RouteUrl("UploadFileContactAttribute", new { attributeId = attribute.Id })" onchange="uploadFile(this)">
                            <input class="hidden-upload-input" type="hidden" id="@(controlId)" name="@(controlName)" value="@download?.DownloadGuid"/>
                            <div class="download-message alert my-2" style="display:none;"></div>
                            <a id="@(controlId)downloadurl" class="download-file btn btn-outline-info" style="display:none;">
                                Download
                            </a>
                        </div>
                    }
                        break;
                    case AttributeControlType.ColorSquares:
                    {
                        <ul class="option-list color-squares w-100 d-inline-flex flex-wrap px-0 mb-0" id="color-squares-@(attribute.Id)">
                            @foreach (var attributeValue in attribute.Values)
                            {
                                var attributeName = attributeValue.Name;
                                <li class="me-1 p-0" @(attributeValue.IsPreSelected ? Html.Raw(" class=\"selected-value border border-primary\"") : null)>
                                    <label for="@(controlId)_@(attributeValue.Id)" class="mb-0">
                                        <input id="@(controlId)_@(attributeValue.Id)" type="radio" name="@(controlName)" value="@attributeValue.Id" checked="@attributeValue.IsPreSelected"/>
                                        <span class="color-container" title="@attributeName">
                                            <span class="color" style="background-color:@(attributeValue.ColorSquaresRgb);">&nbsp;</span>
                                        </span>
                                    </label>
                                </li>
                            }
                        </ul>
                    }
                        break;
                    case AttributeControlType.ImageSquares:
                    {
                        //not support attribute type
                    }
                        break;
                }
            </div>
        }
    </div>
    @* once for the whole form, after it: it wires the change requests that show and hide the
       conditional attributes, whatever control types the form has *@
    <script type="application/json" data-grand-vm="contactAttributes">@Json.Serialize(new {
        routes = new { change = Url.Action("contactattributechange", "contact") }
    })</script>
}