| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 
 | using DevExpress.Utils;
using DevExpress.Web.ASPxHtmlEditor;
using DevExpress.Web.ASPxUploadControl;
using DevExpress.Web.Mvc;
using DevExpress.Web.ASPxFileManager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
 
namespace LivDevis.Helpers.DevExpress
{
    public class HtmlEditorHelper
    {
        public const string ImagesDirectory = "~/Content/DevExpress/HtmlEditor/Images/";
        public const string ThumbnailsDirectory = "~/Content/DevExpress/HtmlEditor/Thumbnails/";
        public const string UploadDirectory = ImagesDirectory + "Upload/";
        public const string ImportContentDirectory = "~/Content/DevExpress/HtmlEditor/Imported";
 
        public static readonly ValidationSettings ImageUploadValidationSettings = new ValidationSettings
        {
            AllowedFileExtensions = new string[] { ".jpg", ".jpeg", ".jpe", ".gif", ".png" },
            MaxFileSize = 4000000
        };
 
        static HtmlEditorValidationSettings validationSettings;
        public static HtmlEditorValidationSettings ValidationSettings
        {
            get
            {
                if (validationSettings == null)
                {
                    validationSettings = new HtmlEditorValidationSettings();
                    validationSettings.RequiredField.IsRequired = true;
                }
                return validationSettings;
            }
        }
 
        static MVCxHtmlEditorImageSelectorSettings imageSelectorSettings;
        public static HtmlEditorImageSelectorSettings ImageSelectorSettings
        {
            get
            {
                if (imageSelectorSettings == null)
                {
                    imageSelectorSettings = new MVCxHtmlEditorImageSelectorSettings(null);
                    HtmlEditorHelper.SetHtmlEditorImageSelectorSettings(imageSelectorSettings);
                }
                return imageSelectorSettings;
            }
        }
 
        public static void OnValidation(object sender, HtmlEditorValidationEventArgs e)
        {
            const int MaxLength = 50;
            string CustomErrorText = string.Format("Custom validation fails because the HTML content′s length exceeds {0} characters.", MaxLength);
 
            if (e.Html.Length > MaxLength)
            {
                e.IsValid = false;
                e.ErrorText = CustomErrorText;
            }
        }
 
        public static MVCxHtmlEditorImageSelectorSettings SetHtmlEditorImageSelectorSettings(MVCxHtmlEditorImageSelectorSettings settingsImageSelector)
        {
            settingsImageSelector.UploadCallbackRouteValues = new { Controller = "HtmlEditor", Action = "FeaturesImageSelectorUpload" };
 
            settingsImageSelector.Enabled = true;
            settingsImageSelector.CommonSettings.RootFolder = HtmlEditorHelper.ImagesDirectory;
            settingsImageSelector.CommonSettings.ThumbnailFolder = HtmlEditorHelper.ThumbnailsDirectory;
            settingsImageSelector.CommonSettings.AllowedFileExtensions = new string[] { ".jpg", ".jpeg", ".jpe", ".gif", ".png" };
            settingsImageSelector.EditingSettings.AllowCreate = true;
            settingsImageSelector.EditingSettings.AllowDelete = true;
            settingsImageSelector.EditingSettings.AllowMove = true;
            settingsImageSelector.EditingSettings.AllowRename = true;
            settingsImageSelector.UploadSettings.Enabled = true;
            settingsImageSelector.FoldersSettings.ShowLockedFolderIcons = true;
 
            settingsImageSelector.PermissionSettings.AccessRules.Add(
                new FileManagerFolderAccessRule
                {
                    Path = "",
                    Upload = Rights.Deny
                },
                new FileManagerFolderAccessRule
                {
                    Path = "Upload",
                    Upload = Rights.Allow
                });
            return settingsImageSelector;
        }
 
        public static HtmlEditorSettings SetHtmlEditorExportSettings(HtmlEditorSettings settings)
        {
            settings.Name = "heImportExport";
            settings.CallbackRouteValues = new { Controller = "HtmlEditor", Action = "ImportExportPartial" };
            settings.ExportRouteValues = new { Controller = "HtmlEditor", Action = "ExportTo" };
            settings.Width = Unit.Percentage(100);
 
            var toolbar = settings.Toolbars.Add();
            toolbar.Items.Add(new ToolbarUndoButton());
            toolbar.Items.Add(new ToolbarRedoButton());
            toolbar.Items.Add(new ToolbarBoldButton(true));
            toolbar.Items.Add(new ToolbarItalicButton());
            toolbar.Items.Add(new ToolbarUnderlineButton());
            toolbar.Items.Add(new ToolbarStrikethroughButton());
            toolbar.Items.Add(new ToolbarInsertImageDialogButton(true));
            ToolbarExportDropDownButton saveButton = new ToolbarExportDropDownButton(true);
            saveButton.CreateDefaultItems();
            toolbar.Items.Add(saveButton);
 
            settings.CssFiles.Add("~/Content/DevExpress/HtmlEditor/Css/Export.css");
 
            return settings;
        }
    }
 
    public class HtmlEditorFeaturesOptions
    {
        public HtmlEditorFeaturesOptions()
        {
            UpdateDeprecatedElements = true;
            UpdateBoldItalic = true;
            EnterMode = HtmlEditorEnterMode.Default;
            AllowContextMenu = DefaultBoolean.True;
            AllowDesignView = true;
            AllowHtmlView = true;
            AllowPreview = true;
        }
 
        public bool AllowScripts { get; set; }
        public bool AllowIFrames { get; set; }
        public bool AllowFormElements { get; set; }
        public bool UpdateDeprecatedElements { get; set; }
        public bool UpdateBoldItalic { get; set; }
        public HtmlEditorEnterMode EnterMode { get; set; }
        public DefaultBoolean AllowContextMenu { get; set; }
        public bool AllowDesignView { get; set; }
        public bool AllowHtmlView { get; set; }
        public bool AllowPreview { get; set; }
    }
} | 
Partager