using System;
using System.Collections;
using System.ComponentModel;
using System.Web.UI.WebControls;
using CMS.ExtendedControls;
using CMS.FormControls;
using CMS.GlobalHelper;
using CMS.SettingsProvider;
///
/// Text area form control with syntax highlighting support.
///
public partial class CMSFormControls_Inputs_LargeTextArea : FormEngineUserControl
{
#region "Variables"
private bool mAllowMacros = true;
#endregion
#region "Properties"
///
/// Gets or sets whether macros are allowed.
///
/// True, if macros can be inserted, otherwise false
[Browsable(true)]
[Description("Determines whether macros are allowed")]
[Category("Form Control")]
[DefaultValue(true)]
public bool AllowMacros
{
get
{
return (Form != null ? Form.AllowMacroEditing : mAllowMacros);
}
set
{
mAllowMacros = value;
}
}
///
/// Gets the ExtendedTextArea object used in this form control.
///
[Browsable(false)]
public ExtendedTextArea TextArea
{
get
{
return txtArea;
}
}
///
/// Gets or sets whether this form control is enabled.
///
/// True, if form control is enabled, otherwise false
[Browsable(true)]
[Description("Determines whether this form control is enabled")]
[Category("Form Control")]
[DefaultValue(true)]
public override bool Enabled
{
get
{
return base.Enabled;
}
set
{
base.Enabled = txtArea.Enabled = btnMore.Enabled = value;
}
}
///
/// Gets the server control identifier generated by ASP.NET.
///
[Browsable(false)]
public override string InputClientID
{
get
{
return txtArea.ClientID;
}
}
///
/// Gets or sets the value of this form control.
///
/// Text content of this editor
[Browsable(false)]
public override object Value
{
get
{
return txtArea.Text;
}
set
{
txtArea.Text = (string)value;
}
}
///
/// Gets the client ID of the embedded element that provides the value for this control.
///
[Browsable(false)]
public override string ValueElementID
{
get
{
return txtArea.ClientID;
}
}
///
/// Gets or sets the width of this control.
///
/// The width in pixels or percentage
[Browsable(true)]
[Description("Determines the width of this control")]
[Category("Appearance")]
[DefaultValue("250px")]
public Unit Width
{
get
{
return txtArea.Width;
}
set
{
txtArea.Width = value;
}
}
///
/// Gets or sets the height of this control.
///
/// The height in pixels or percentage
[Browsable(true)]
[Description("Determines the width of this control")]
[Category("Appearance")]
[DefaultValue("50px")]
public Unit Height
{
get
{
return txtArea.Height;
}
set
{
txtArea.Height = value;
}
}
///
/// Gets the button that opens the full-featured editor.
///
public Button MoreButton
{
get
{
return btnMore;
}
}
///
/// Indicates if machine translation services are supported for this text box.
///
[Browsable(false)]
public bool AllowTranslationServices
{
get;
set;
}
#endregion
#region "Methods"
///
/// Handles the Load event of the Page control.
///
/// The source of the event
/// The System.EventArgs instance containing the event data
protected void Page_Load(object sender, EventArgs e)
{
CheckMinMaxLength = true;
CheckRegularExpression = true;
// Register general dialog scripts
ScriptHelper.RegisterDialogScript(Page);
// Assign handler that opens modal dialog
btnMore.OnClientClick += string.Format("ShowLargeTextAreaDesigner('{0}', {1}, '{2}'); return false;", ValueElementID, AllowMacros.ToString().ToLowerCSafe(), ResolverName);
// Register modal dialog script
ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ShowLargeTextAreaDesigner", GetDesignerScript());
// Register script that gets/sets values between control and modal dialog
ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "AreaGlobal", GetValueTransferScript());
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (AllowTranslationServices)
{
txtArea.RegisterTranslationScripts();
ltlTranslations.Text = "
" + txtArea.GetTranslationServicesPanel() + "
";
}
}
///
/// Builds and returns a client script that is used to open modal dialog with an editor in advanced mode.
///
/// String that represents a modal dialog JS script.
private string GetDesignerScript()
{
string script = string.Format(
@"function ShowLargeTextAreaDesigner(editorID, allowMacros, resolverName)
{{
modalDialog('{0}?editorid=' + editorID + (allowMacros ? '' : '&allowMacros=false') + ((resolverName == '') ? '' : '&resolverName=' + resolverName), 'ShowLargeTextAreaDesigner', 1034, {1}); return false;
}}",
ResolveUrl("~/CMSFormControls/Selectors/LargeTextAreaDesigner.aspx"),
(680 - (AllowMacros ? 0 : 60))
);
return ScriptHelper.GetScript(script);
}
///
/// Builds and returns a client script that is used to transfer the text between this editor and dialog window.
///
/// String that represents a value transfer script.
private string GetValueTransferScript()
{
// Derelict, needs cleanup
const string script = @"function SetAreaValue(areaId, areaText){
document.getElementById(areaId).value = areaText;
return false;
}
function GetAreaValue(areaId){
return document.getElementById(areaId).value;
return false;
}";
return ScriptHelper.GetScript(script);
}
///
/// Returns value of specified property
///
/// Name of the property
public override object GetValue(string propertyName)
{
switch (propertyName.ToLowerCSafe())
{
case "translationsourcetext":
return txtArea.TranslationSourceText;
case "translationsourcelanguage":
return txtArea.TranslationSourceLanguage;
case "translationtargetlanguage":
return txtArea.TranslationTargetLanguage;
case "allowtranslationservices":
return AllowTranslationServices;
}
return null;
}
///
/// Sets value of specified property.
///
/// Name of the property
/// Value to set
public override void SetValue(string propertyName, object value)
{
switch (propertyName.ToLowerCSafe())
{
case "translationsourcetext":
txtArea.TranslationSourceText = ValidationHelper.GetString(value, null);
break;
case "translationsourcelanguage":
txtArea.TranslationSourceLanguage = ValidationHelper.GetString(value, null);
break;
case "translationtargetlanguage":
txtArea.TranslationTargetLanguage = ValidationHelper.GetString(value, null);
break;
case "allowtranslationservices":
AllowTranslationServices = ValidationHelper.GetBoolean(value, false);
break;
}
}
#endregion
}