using System;
using System.Linq;
using CMS.EventLog;
using CMS.ExtendedControls;
using CMS.FormEngine;
using CMS.GlobalHelper;
using CMS.SalesForce;
///
/// Displays a mapping of CMS objects to SalesForce entities.
///
public partial class CMSModules_ContactManagement_Controls_UI_SalesForce_Mapping : AbstractUserControl
{
#region "Private members"
private Mapping mMapping;
private FormInfo mFormInfo;
private bool mEnabled = true;
#endregion
#region "Public properties"
///
/// Gets or sets the mapping to display.
///
public Mapping Mapping
{
get
{
return mMapping;
}
set
{
mMapping = value;
}
}
///
/// Gets or sets the value indicating whether the control is enabled.
///
public bool Enabled
{
get
{
return mEnabled;
}
set
{
mEnabled = value;
}
}
#endregion
#region "Protected properties"
protected FormInfo FormInfo
{
get
{
if (mFormInfo == null)
{
ContactFormInfoProvider provider = new ContactFormInfoProvider();
mFormInfo = provider.GetFormInfo();
}
return mFormInfo;
}
}
#endregion
#region "Life-cycle methods"
protected override void OnPreRender(EventArgs e)
{
if (mMapping == null)
{
Visible = false;
}
else
{
ItemRepeater.DataSource = mMapping.Items;
ItemRepeater.DataBind();
if (String.IsNullOrEmpty(mMapping.ExternalIdentifierAttributeName))
{
MessageControl.InnerHtml = GetString("sf.noexternalidentifierattribute");
MessageControl.Attributes.Add("class", "Red");
MessageControl.Visible = true;
}
else
{
MessageControl.InnerHtml = String.Format("{0}: {1}", GetString("sf.mapping.externalidentifierattribute"), HTMLHelper.HTMLEncode(mMapping.ExternalIdentifierAttributeLabel));
MessageControl.Visible = true;
}
if (!Enabled)
{
ContainerControl.Attributes.Add("class", "Gray");
}
}
}
#endregion
#region "Protected methods"
protected string FormatSourceType(MappingItem item)
{
switch (item.SourceType)
{
case MappingItemSourceTypeEnum.Field:
return GetString("sf.sourcetype.field");
case MappingItemSourceTypeEnum.MetaField:
return GetString("sf.sourcetype.metafield");
case MappingItemSourceTypeEnum.PicklistEntry:
return GetString("sf.sourcetype.picklistentry");
}
return String.Empty;
}
protected string FormatSourceLabel(MappingItem item)
{
return item.SourceLabel;
}
#endregion
#region "Private methods"
private string GetFieldCaption(string name)
{
FormFieldInfo field = FormInfo.GetFormField(name);
if (field == null)
{
return String.Empty;
}
return ResHelper.LocalizeString(field.Caption);
}
#endregion
}