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.

5.9 KB
Raw Blame
@using Grand.Domain.Media
@model CustomerModel
@{
    ViewData["DownloadType"] = DownloadType.Customer;
    ViewData["ReferenceId"] = Model.Id;
}
@* the merchandise return notes' shape: the notes grid in a flush card, then a card to add one *@
<div class="grand-card">
    <div class="grand-card__body grand-card__body--flush">
        <vc:admin-widget widget-zone="customer_details_notes_top" additional-data="Model"/>
        <admin-grid id="customernotes-grid"
                    read-url="@Url.Action("CustomerNotesSelect", "Customer", new { customerId = Model.Id, area = Constants.AreaAdmin })"
                    destroy-url="@Url.Action("CustomerNoteDelete", "Customer", new { customerId = Model.Id, area = Constants.AreaAdmin })"
                    pager="Compact"
                    auto-bind="false"
                    confirm-destroy="true">
            <grid-text name="link" value="@Loc["Admin.Customers.CustomerNotes.Fields.Download.Link"]"/>
            <grid-text name="no" value="@Loc["Admin.Customers.CustomerNotes.Fields.Download.Link.No"]"/>
            <grid-column field="CreatedOn" title="@Loc["Admin.Customers.CustomerNotes.Fields.CreatedOn"]" width="180" format="{0:G}"/>
            <grid-column field="Title" title="@Loc["Admin.Customers.CustomerNotes.Fields.Title"]" width="250"/>
            <grid-column field="Note" title="@Loc["Admin.Customers.CustomerNotes.Fields.Note"]" width="350"/>
            <grid-column field="DownloadId" title="@Loc["Admin.Customers.CustomerNotes.Fields.Download"]" width="100">
                <cell-template>
                    <a data-if="DownloadId != ''" href="@Url.Action("DownloadFile", "Download", new { area = Constants.AreaAdmin })/?downloadGuid={{ DownloadGuid }}">{{ $texts.link }}</a>
                    <span data-else>{{ $texts.no }}</span>
                </cell-template>
            </grid-column>
            <grid-column field="DisplayToCustomer" title="@Loc["Admin.Customers.CustomerNotes.Fields.DisplayToCustomer"]" width="100" align="Center">
                <cell-template>
                    <i data-if="DisplayToCustomer" class="bi bi-check-lg text-success" aria-hidden="true"></i>
                    <i data-else class="bi bi-x-lg text-danger" aria-hidden="true"></i>
                </cell-template>
            </grid-column>
            <grid-commands destroy="true" title="@Loc["Admin.Common.Delete"]" width="100"/>
        </admin-grid>
        <vc:admin-widget widget-zone="customer_details_notes_bottom" additional-data="Model"/>
    </div>
</div>
<script>
    $(document).ready(function () {
        $("#@Html.IdFor(model => model.AddCustomerNoteHasDownload)").change(toggleAddCustomerNoteHasDownload);
        toggleAddCustomerNoteHasDownload();
    });
    function toggleAddCustomerNoteHasDownload() {
        if ($('#@Html.IdFor(model => model.AddCustomerNoteHasDownload)').is(':checked')) {
            $('#pnlAddCustomerNoteDownloadId').show();
        }
        else {
            $('#pnlAddCustomerNoteDownloadId').hide();
        }
    }

</script>

<admin-card title="@Loc["Admin.Customers.CustomerNotes.AddTitle"]">
    <div class="grand-fields">
        <admin-field asp-for="AddCustomerTitle"/>
        <admin-field asp-for="AddCustomerNoteMessage">
            <admin-textarea asp-for="AddCustomerNoteMessage"></admin-textarea>
        </admin-field>
        <admin-field asp-for="AddCustomerNoteHasDownload" asp-label-for="AddCustomerNoteDownloadId"/>
        <div id="pnlAddCustomerNoteDownloadId">
            <admin-input asp-for="AddCustomerNoteDownloadId"/>
            <span asp-validation-for="AddCustomerNoteDownloadId"></span>
        </div>
        <admin-field asp-for="AddCustomerNoteDisplayToCustomer"/>
    </div>
    <div class="mt-3">
        <button type="button" id="addCustomerNote" class="btn btn-outline-secondary btn-sm"><i class="bi bi-plus-lg"></i> @Loc["Admin.Customers.CustomerNotes.AddButton"]</button>
    </div>
</admin-card>

<script>
    $(document).ready(function () {
        $('#addCustomerNote').click(function () {
            var customerTitle = $("#@Html.IdFor(model => model.AddCustomerTitle)").val();
            if (customerTitle.length == 0) {
                alert('Title is required');
                return;
            }

            var customerNoteMessage = $("#@Html.IdFor(model => model.AddCustomerNoteMessage)").val();
            if (customerNoteMessage.length == 0) {
                alert('Message text is required');
                return;
            }
            var customerNoteDownloadId = '';
            if ($('#@Html.IdFor(model => model.AddCustomerNoteHasDownload)').is(':checked')) {
                customerNoteDownloadId = $("#@Html.IdFor(model => model.AddCustomerNoteDownloadId)").val();
            }
            var customerNoteDisplayToCustomer = $("#@Html.IdFor(model => model.AddCustomerNoteDisplayToCustomer)").is(':checked');
            $('#addCustomerNote').attr('disabled', true);
            var postData = {
                DisplayToCustomer: customerNoteDisplayToCustomer,
                title: customerTitle,
                message: customerNoteMessage, 
                downloadId: customerNoteDownloadId, 
                customerId: '@Model.Id'
            };
            addAntiForgeryToken(postData);

            $.ajax({
                cache:false,
                type: "POST",
                url: "@(Url.Action("CustomerNoteAdd", "Customer", new { area = Constants.AreaAdmin }))",
                data: postData,
                success: function (data) {
                    var grid = GrandAdmin.grids.get("#customernotes-grid");
                    grid.dataSource.read();
                    $('#addCustomerNote').attr('disabled', false);
                },
                error:function (xhr, ajaxOptions, thrownError){
                    alert('Failed to add customer note.');
                    $('#addCustomerNote').attr('disabled', false);
                }  
            });
        });
    });
</script>