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.

2.6 KB
Raw Blame
@using Constants = Grand.SharedUIResources.Constants
@model CampaignModel

<link rel="stylesheet" type="text/css" asp-src="@(Constants.WwwRoot)/administration/codemirror/codemirror.css"/>
<script asp-location="Head" asp-src="@(Constants.WwwRoot)/administration/codemirror/codemirror.js"></script>
<script asp-location="Head" asp-src="@(Constants.WwwRoot)/administration/codemirror/mode/xml/xml.js"></script>

@* One card of fields; the body with its token picker takes the whole row. The .mb-3 wrapper stays
   because the token search below looks the token list up through it. *@
<admin-card>
    <div class="grand-fields grand-fields--2col">
        <admin-field asp-for="Name"/>
        <admin-field asp-for="Subject"/>
        <admin-field asp-for="EmailAccountId" asp-items="@(new SelectList(Model.AvailableEmailAccounts, "Id", "DisplayName"))"/>
        <admin-field asp-for="LanguageId" asp-items="Model.AvailableLanguages"/>
    </div>
    <div class="grand-fields mt-3">
        <admin-field asp-for="Body">
            <div class="mb-3">
                <div>
                    <label>@Loc["Admin.Content.MessageTemplates.Fields.AllowedTokens"]</label>
                    <input type="search" name="SearchTokens" class="form-control SearchTokens" placeholder="@Loc["Search"]"/>
                </div>
                <div class="AllowedTokens">
                    @foreach (var token in Model.AllowedTokens)
                    {
                        <button type="button" onclick="AddTokenToEditor(this)" class="btn btn-outline-secondary btn-sm">@token</button>
                    }
                </div>
            </div>
            <admin-input asp-for="Body" asp-template="Codemirror"/>
        </admin-field>
    </div>
</admin-card>
<script>
    $(document).ready(function () {
        $(".SearchTokens").on("input", function (e) { SearchTokens(e); })
        $("input").click(function (e) {
            onInputFocus = $(e.target);
        });
    });

    function AddTokenToEditor(e) {
        var cm = $('.CodeMirror')[0].CodeMirror;
        var doc = cm.getDoc();
        var cursor = doc.getCursor(); // gets the line number in the cursor position
        doc.replaceRange($(e).text(), cursor);
    }

    function SearchTokens(e) {
        var searchVal = $(e.target).val();
        var TokensPnl = $(e.target).closest(".mb-3").find(".AllowedTokens");
        $(TokensPnl).find(".btn").show()
            .each(function (i, c) {
                var Token = $(c).text();
                if (Token.search(new RegExp(searchVal, "i")) == -1) {
                    $(c).hide();
                }
            });
    }
</script>