RichTextBox.cs
- Last UpdatedMar 12, 2021
- 3 minute read
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Skelta.Forms.Core;
using Skelta.Forms.Core.External;
using Skelta.Forms.Core.CommonObjects;
using Skelta.Forms.Core.Controls;
using Skelta.Forms.Core.Interfaces;
using System.Globalization;
using System.Web;
namespace Kendo.Custom.Controls
{
[DesignerControl(992201, CoreDesigner.NextGenDesigner, DesignerCategory.Custom)]
[SuppressedPropertiesNextGen("DefaultValue;ReadOnly;EnableResponsiveView;ToolTip;OnDataChangedScript;IncludeInSummaryView;ExpValidate;ExpValue;MessageWhenEmpty;StyleSheet;ExpDefaultValue;ExpVisible;ExpMandatory;")]
public class RichTextBox : BaseDataExternalControl
{
public override BaseControl GetNewInstanceForClone()
{
RichTextBox richTextBox = new RichTextBox();
richTextBox.Enabled = this.Enabled;
richTextBox.Visible = this.Visible;
richTextBox.ToolTip = this.ToolTip;
richTextBox.Height = this.Height;
richTextBox.Width = this.Width;
return richTextBox;
}
/// <summary>
/// Gets the Display Name
/// </summary>
public static string TypeDisplayName
{
get
{
return "RichTextBox";
}
}
public override string TypeAssociation
{
get
{
return "Custom";
}
}
bool toolbarVisible = true;
/// <summary>
/// Gets/Sets the Rows
/// </summary>
[DesignerProperty(PropertyOrder.ImagePath, Categories.Appearance, CoreDesigner.NextGenDesigner)]
[BindingAttribute(882940, "Skelta.Forms.Core.CommonObjects.CommonBoolBindingProperty")]
public bool ToolbarVisible
{
get { return toolbarVisible; }
set { toolbarVisible = value; }
}
/// <summary>
/// Adding JS & CSS and setting view model value
/// </summary>
/// <returns></returns>
public override string GetView()
{
AddJsFiles();
return base.GetView();
}
/// <summary>
/// Method to render the control, How it has to look in designer as well as in the preview.
/// </summary>
/// <returns>Controls view </returns>
public override string GetControlHtml()
{
var stringBuilder = new StringBuilder();
stringBuilder.Append("<textarea " + GetControlIdAttribute + " data-bind=\"kendoEditor: { value: " + this.Id + "._value, ");
stringBuilder.Append(GetTools());
stringBuilder.Append("}, ");
stringBuilder.Append(" richTextBoxReadOnly: " + this.Id + "._enable, richTextBoxHeight: " + this.Id + "._height, richTextBoxWidth: " + this.Id + "._width \"");
if (this.TopLevelForm.InDesignMode)
{
int defaultHeight = 200;
int defaultWidth = 400;
if (this.Height > 0)
{
defaultHeight = this.Height;
}
if (this.Width > 0)
{
defaultWidth = this.Width;
}
string style = " style='height: " + defaultHeight.ToString() + "px; width: " + defaultWidth.ToString() + "px;'";
stringBuilder.Append(style);
}
stringBuilder.Append("> </textarea>");
return stringBuilder.ToString();
}
private string GetTools()
{
StringBuilder readOnlyBinding = new StringBuilder();
readOnlyBinding.Append("tools: [");
if (this.toolbarVisible)
{
readOnlyBinding.Append("'bold',");
readOnlyBinding.Append("'italic',");
readOnlyBinding.Append("'underline',");
readOnlyBinding.Append("'strikethrough',");
readOnlyBinding.Append("'justifyLeft',");
readOnlyBinding.Append("'justifyCenter',");
readOnlyBinding.Append("'justifyRight',");
readOnlyBinding.Append("'justifyFull',");
readOnlyBinding.Append("'insertUnorderedList',");
readOnlyBinding.Append("'insertOrderedList',");
readOnlyBinding.Append("'indent',");
readOnlyBinding.Append("'outdent',");
readOnlyBinding.Append("'createLink',");
readOnlyBinding.Append("'unlink',");
readOnlyBinding.Append("'insertImage',");
readOnlyBinding.Append("'subscript',");
readOnlyBinding.Append("'superscript',");
readOnlyBinding.Append("'createTable',");
readOnlyBinding.Append("'addRowAbove',");
readOnlyBinding.Append("'addRowBelow',");
readOnlyBinding.Append("'addColumnLeft',");
readOnlyBinding.Append("'addColumnRight',");
readOnlyBinding.Append("'deleteRow',");
readOnlyBinding.Append("'deleteColumn',");
readOnlyBinding.Append("'viewHtml',");
readOnlyBinding.Append("'formatting',");
readOnlyBinding.Append("'fontName',");
readOnlyBinding.Append("'fontSize',");
readOnlyBinding.Append("'foreColor',");
readOnlyBinding.Append("'backColor',");
readOnlyBinding.Append("'print'");
}
readOnlyBinding.Append("]");
return readOnlyBinding.ToString();
}
/// <summary>
/// Method to add the custom Js files associated to the custom control
/// </summary>
private void AddJsFiles()
{
// 6. kendo.combobox.min.js
if (string.IsNullOrEmpty(this.TopLevelForm.RuntimeJS["kendo.combobox.min.js"]))
{
// "this.TopLevelForm.RuntimeCss" is the collection which holds your custom CSS files.
// It is a key-value pair collection where the key is the file name and the value is the file path(absolute or relative).
//Important point is the JS file should be present inside "BPMUITemplate/Default/NextGenForms/js" folder or else it won't get rendered.
this.TopLevelForm.RuntimeJS.Add("kendo.combobox.min.js", "js/kendo.combobox.min.js");
}
//// 4. kendo.editor.min.js
if (string.IsNullOrEmpty(this.TopLevelForm.RuntimeJS["kendo.editor.min.js"]))
{
// "this.TopLevelForm.RuntimeCss" is the collection which holds your custom CSS files.
// It is a key-value pair collection where the key is the file name and the value is the file path(absolute or relative).
//Important point is the JS file should be present inside "BPMUITemplate/Default/NextGenForms/js" folder or else it won't get rendered.
this.TopLevelForm.RuntimeJS.Add("kendo.editor.min.js", "js/kendo.editor.min.js");
}
if (string.IsNullOrEmpty(this.TopLevelForm.RuntimeJS["knockout.kendo.editor.js"]))
{
// "this.TopLevelForm.RuntimeCss" is the collection which holds your custom CSS files.
// It is a key-value pair collection where the key is the file name and the value is the file path(absolute or relative).
//Important point is the JS file should be present inside "BPMUITemplate/Default/NextGenForms/js" folder or else it won't get rendered.
this.TopLevelForm.RuntimeJS.Add("knockout.kendo.editor.js", "js/knockout.kendo.editor.js");
}
if (string.IsNullOrEmpty(this.TopLevelForm.RuntimeJS["richtextbox.js"]))
{
// "this.TopLevelForm.RuntimeCss" is the collection which holds your custom CSS files.
// It is a key-value pair collection where the key is the file name and the value is the file path(absolute or relative).
//Important point is the JS file should be present inside "BPMUITemplate/Default/NextGenForms/js" folder or else it won't get rendered.
this.TopLevelForm.RuntimeJS.Add("richtextbox.js", "js/richtextbox.js");
}
}
}
}