ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/Shared/EditorTemplates/RichEditor.cshtml
@model String
@inject IPermissionService permissionService
@inject IWorkContext workContext
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment webHostEnvironment
@inject AdminAreaSettings adminAreaSettings
@using Grand.Web.Areas.Admin.Extensions
@using Grand.Core
@using Grand.Services.Security
@{
    // tinyMCE language
    var language = TinyMceHelper.GetTinyMceLanguage(workContext, webHostEnvironment);

    var allowJbimages = false;
    var allowRoxyFileman = await permissionService.Authorize(StandardPermissionProvider.HtmlEditorManagePictures);
    //TinyMCE picture browser does not work in a virtual category
    //so if you're running in a virtual directory, then uncomment the code below:
    //allowJbimages = true;
    //allowRoxyFileman =false;

    var random = CommonHelper.GenerateRandomInteger();

    //extend editor with additional settings
    //Sample setting value (below):
    //settings.plugins.push('print'); settings.toolbar += ' | print';
    var additionalEditorSettings = adminAreaSettings.RichEditorAdditionalSettings;
    //is java-script supported?
    var allowJavaScript = adminAreaSettings.RichEditorAllowJavaScript;

    //allow HTML body? Full page? - http://www.tinymce.com/wiki.php/Plugin:fullpage
    //false by default
    var enableFullPage = Convert.ToBoolean(ViewData["Grand.RichEditor.EnableFullPage"] ?? false);
}
<script>
    $(document).ready(function() {
        @* wooncherk contribution *@
        function RoxyFileBrowser@(random)(field_name, url, type, win) {
            $.ajax({
                cache: false,
                type: "GET",
                url: "@(Url.Action("CreateConfiguration", "RoxyFileman"))",
                success: function (data) {
                    var roxyFileman = '@Url.Content("~/content/roxy_fileman/index.html")';
                    if (roxyFileman.indexOf("?") < 0) {
                        roxyFileman += "?type=" + type;
                    } else {
                        roxyFileman += "&type=" + type;
                    }
                    roxyFileman += '&input=' + field_name + '&value=' + document.getElementById(field_name).value;
                    tinyMCE.activeEditor.windowManager.open({
                        file: roxyFileman,
                        title: 'Roxy Fileman',
                        width: 850,
                        height: 650,
                        resizable: "yes",
                        plugins: "media",
                        inline: "yes",
                        close_previous: "no"
                    }, { window: win, input: field_name });
                    return false;
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(thrownError);
                }
            });
        }

        var defaultEditorSettings@(random) = {
            selector: "#@Html.IdForModel()",
            setup: function (editor) {
                if ($('#DarkLight').is(':checked')) {
                    editor.settings.skin = 'dark';
                } else {
                    editor.settings.skin = 'lightgray';
                }
            },
            theme: "modern",
            schema: "html5",
            fontsize_formats: "8pt 9pt 10pt 11pt 12pt 26pt 36pt",
            height: 200,
            width: '100%',
            autoresize_min_height: 200,
            autoresize_max_height: 200,
            plugins: [
                "advlist autolink autoresize directionality lists link image charmap preview anchor",
                "searchreplace visualblocks code fullscreen textcolor",
                "insertdatetime media table contextmenu paste@(allowJbimages ? " jbimages" : null)@(enableFullPage ? " fullpage" : null)"
            ],
            toolbar: "ltr rtl | insertfile undo redo | styleselect | fontselect | fontsizeselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | media link image@(allowJbimages ? " jbimages" : null)",
            //"relative_urls" required by jbimages plugin to be set to "false"
            relative_urls: false,
            @if (allowJavaScript)
            {
                <text>
                    valid_elements: "*[*]",
                </text>
            }
            @if (allowRoxyFileman)
            {
                <text>
                    //picture manager
                    file_browser_callback: RoxyFileBrowser@(random),
                </text>
            }
            @if (!string.IsNullOrEmpty(language))
            {
                <text>
                    //language
                    language: "@language",
                </text>
            }
            //we should set "convert_urls" set to "false" (because of "relative_urls" requirement)
            //otherwise, it'll break existing links when editing message template
            convert_urls: false,
            //ensure that special chars are not encoded. For example, ä, ö and ü should NOT become "&auml;", "&ouml;" and "&uuml;"
            //Otherwise, database searches become impossible when words contain a character of this kind
            entity_encoding: "raw"
        };
        function getAdditionalEditorSettings@(random)(settings) {
            @Html.Raw(additionalEditorSettings)
            return settings;
        }

        tinyMCE.init(getAdditionalEditorSettings@(random)(defaultEditorSettings@(random)));
    });
</script>

@Html.TextArea(string.Empty, /* Name suffix */
    ViewData.TemplateInfo.FormattedModelValue /* Initial value */
)