Rock.Web.UI.Controls.HtmlEditor.RenderBaseControl C# (CSharp) Method

RenderBaseControl() public method

Renders the base control.
public RenderBaseControl ( System.Web.UI.HtmlTextWriter writer ) : void
writer System.Web.UI.HtmlTextWriter The writer.
return void
        public void RenderBaseControl( HtmlTextWriter writer )
        {
            string summernoteInitScriptFormat = @"
            $(document).ready( function() {{
            var summerNoteEditor_{0} = $('#{0}').summernote({{
            height: '{2}', //set editable area's height
            toolbar: Rock.htmlEditor.toolbar_RockCustomConfig{11},

            popover: {{
              image: [
            ['imagesize', ['imageSize100', 'imageSize50', 'imageSize25']],
            ['custom', ['rockimagebrowser']],
            ['float', ['floatLeft', 'floatRight', 'floatNone']],
            ['remove', ['removeMedia']]
              ],
              link: [
            ['link', ['linkDialogShow', 'unlink']]
              ],
              air: [
            ['color', ['color']],
            ['font', ['bold', 'underline', 'clear']],
            ['para', ['ul', 'paragraph']],
            ['table', ['table']],
            ['insert', ['link', 'picture']]
              ]
            }},

            callbacks: {{
               {12}
            }},

            buttons: {{
            rockfilebrowser: RockFileBrowser,
            rockimagebrowser: RockImageBrowser,
            rockmergefield: RockMergeField,
            rockcodeeditor: RockCodeEditor,
            rockpastetext: RockPasteText,
            rockpastefromword: RockPasteFromWord
            }},

            rockFileBrowserOptions: {{
            enabled: {3},
            documentFolderRoot: '{4}',
            imageFolderRoot: '{5}',
            imageFileTypeWhiteList: '{6}',
            fileTypeBlackList: '{7}'
            }},

            rockMergeFieldOptions: {{
            enabled: {9},
            mergeFields: '{8}'
            }},
            rockTheme: '{10}',

            codeEditorOptions: {{
            controlId: '{13}',
            inCodeEditorModeHiddenFieldId: '{14}'
            }},

            // summernote-cleaner.js plugin options
            cleaner:{{
                el:'#{0}',  // Element ID or Class used to Initialise Summernote.
                notTime:2400, // Time to display Notifications.
                action:'paste', // both|button|paste 'button' only cleans via toolbar button, 'paste' only clean when pasting content, both does both options.
            }}

            }});

            if ({15} && RockCodeEditor) {{
            RockCodeEditor(summerNoteEditor_{0}.data('summernote'), true).click();
            }}

            }});
            ";

            bool rockMergeFieldEnabled = MergeFields.Any();
            bool rockFileBrowserEnabled = false;

            // only show the File/Image plugin if they have Auth to the file browser page
            var fileBrowserPage = new Rock.Model.PageService( new RockContext() ).Get( Rock.SystemGuid.Page.HTMLEDITOR_ROCKFILEBROWSER_PLUGIN_FRAME.AsGuid() );
            if ( fileBrowserPage != null )
            {
                var currentPerson = this.RockBlock().CurrentPerson;
                if ( currentPerson != null )
                {
                    if ( fileBrowserPage.IsAuthorized( Authorization.VIEW, currentPerson ) )
                    {
                        rockFileBrowserEnabled = true;
                    }
                }
            }

            var globalAttributesCache = GlobalAttributesCache.Read();

            string imageFileTypeWhiteList = globalAttributesCache.GetValue( "ContentImageFiletypeWhitelist" );
            string fileTypeBlackList = globalAttributesCache.GetValue( "ContentFiletypeBlacklist" );

            string documentFolderRoot = this.DocumentFolderRoot;
            string imageFolderRoot = this.ImageFolderRoot;
            if ( this.UserSpecificRoot )
            {
                var currentUser = this.RockBlock().CurrentUser;
                if ( currentUser != null )
                {
                    documentFolderRoot = System.Web.VirtualPathUtility.Combine( documentFolderRoot.EnsureTrailingBackslash(), currentUser.UserName.ToString() );
                    imageFolderRoot = System.Web.VirtualPathUtility.Combine( imageFolderRoot.EnsureTrailingBackslash(), currentUser.UserName.ToString() );
                }
            }

            string callbacksOption = null;
            if ( !string.IsNullOrEmpty( this.OnChangeScript ) )
            {
                callbacksOption = string.Format(
            @" onKeyup: function() {{
            {0}
            }}",
               this.OnChangeScript );
            }

            string summernoteInitScript = string.Format(
                summernoteInitScriptFormat,
                this.ClientID,   // {0}
                null, // {1}
                this.Height, // {2}
                rockFileBrowserEnabled.ToTrueFalse().ToLower(),                 // {3}
                Rock.Security.Encryption.EncryptString( documentFolderRoot ),   // {4} encrypt the folders so the folder can only be configured on the server
                Rock.Security.Encryption.EncryptString( imageFolderRoot ),      // {5}
                imageFileTypeWhiteList,                                         // {6}
                fileTypeBlackList,                                              // {7}
                this.MergeFields.AsDelimited( "," ),                            // {8}
                rockMergeFieldEnabled.ToTrueFalse().ToLower(),                  // {9}
                ( (RockPage)this.Page ).Site.Theme,                             // {10}
                this.Toolbar.ConvertToString(),                                 // {11}
                callbacksOption,                                                // {12}
                _ceEditor.ClientID,                                             // {13}
                _hfInCodeEditorMode.ClientID,                                   // {14}
                StartInCodeEditorMode.ToTrueFalse().ToLower()                   // {15}
                );

            ScriptManager.RegisterStartupScript( this, this.GetType(), "summernote_init_script_" + this.ClientID, summernoteInitScript, true );

            // add script on demand only when there will be an htmleditor rendered
            if ( ScriptManager.GetCurrent( this.Page ).IsInAsyncPostBack )
            {
                ScriptManager.RegisterClientScriptInclude( this.Page, this.Page.GetType(), "summernote-lib", ( (RockPage)this.Page ).ResolveRockUrl( "~/Scripts/summernote/summernote.min.js", true ) );
                var bundleUrl = System.Web.Optimization.BundleResolver.Current.GetBundleUrl( "~/Scripts/Bundles/RockHtmlEditorPlugins" );
                ScriptManager.RegisterClientScriptInclude( this.Page, this.Page.GetType(), "summernote-plugins", bundleUrl );
            }

            // set this textbox hidden until we can run the js to attach summernote to it
            this.Style[HtmlTextWriterStyle.Display] = "none";

            base.RenderControl( writer );
        }