Project Description
Advanced Visibility Options - is an extension to SharePoint providing configurable List Field Iterator with PowerShell scripts.

Introduction


Project was designed to extend existing List Field Iterator functionality (Show as RO, Hide field on sharepoint List and Document Libraries forms: New, Edit, Display). It was considered to be Bewise Display settings solution ported to SP2010 with PowerShell support to provide andvanced logic to determine field visibility.

Building the Sample


This is a farm scoped solution, Open Visual Studio build, package and deploy .wsp to you SharePoint Farm

Description


Solution provides configurable List Field Iterator to manage field visibility behavior. Atm only plain powershell scripts are supported. After activating feature navigate to content type settings page.

Link.png

Then click on Advanced Visibility Settings link to enable or disable solution functionality.

CTSettingsPage.png

On this page you can manage powershell scripts for each field within a content type.

FieldSettingsPage.png

Unfortunately atm only plain text powershell scripts are supported, if you have any implementation for visual disigner and/or want to contribute to this project feel free to contact me.

Source Code Files

protected override void CreateChildControls()
{
this.Controls.Clear();

if (this.ControlTemplate == null)
throw new ArgumentException("Could not find ListFieldIterator control template.");

for (int i = 0; i < base.Fields.Count; i++)
{
SPField field = base.Fields[i];

if (!IsFieldExcluded(field))
{
TemplateContainer child = new TemplateContainer();
this.Controls.Add(child);

FieldVisibilityConfig fieldCfg = Config[field.Id];
if (fieldCfg != null && fieldCfg.Enabled)
{
var scriptResult = fieldCfg.ScriptFunction.ExecuteScript(
"GetControlMode",
HttpContext.Current, SPContext.Current, m_ContentType, field, this);
if (scriptResult != null && scriptResult.Count() > 0)
{
string firstRow = scriptResult.FirstOrDefault();

if (!string.IsNullOrEmpty(firstRow))
{
SPControlMode controlMode = (SPControlMode)Enum.Parse(typeof(SPControlMode), firstRow);
SetControlMode(child, controlMode);
}
}
else
SetControlMode(child, base.ControlMode);
}

SetFieldName(child, field.InternalName);
this.ControlTemplate.InstantiateIn(child);
}
}
}

protected override bool IsFieldExcluded(SPField field)
{
bool bBaseValue = base.IsFieldExcluded(field);
if (bBaseValue)
return true;

if (field.Hidden)
return true;
if (!field.Required && field.ShowInEditForm.HasValue && field.ShowInEditForm.Value == false && this.ControlMode == SPControlMode.Edit)
return true;
if (!field.Required && field.ShowInDisplayForm.HasValue && field.ShowInDisplayForm.Value == false && this.ControlMode == SPControlMode.Display)
return true;
if (!field.Required && field.ShowInNewForm.HasValue && field.ShowInNewForm.Value == false && this.ControlMode == SPControlMode.New)
return true;


FieldVisibilityConfig fieldCfg = Config[field.Id];
if (fieldCfg != null && fieldCfg.Enabled)
{
var scriptResult = fieldCfg.ScriptFunction.ExecuteScript(
"GetControlMode",
HttpContext.Current, SPContext.Current, m_ContentType, field, this);
if (scriptResult != null && scriptResult.Count() > 0)
{
string firstRow = scriptResult.FirstOrDefault();

if (string.IsNullOrEmpty(firstRow))
return true;
}
}
return false;
}


Looking for the contributor for that project.

TODO:
- Visual Designer to improve UI experience
- Unit Tests

Last edited Jul 23, 2012 at 9:18 AM by HeToC, version 6