using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CMS.CMSHelper;
using CMS.GlobalHelper;
using CMS.OnlineMarketing;
using CMS.UIControls;
using Action = CMS.UIControls.UniGridConfig.Action;
public partial class CMSModules_OnlineMarketing_Dialogs_ContentPersonalizationVariantList : CMSVariantDialogPage
{
#region "Variables"
///
/// Indicates whether editing a web part or a zone variant.
///
private VariantTypeEnum variantType = VariantTypeEnum.Zone;
// Setup the list control properties
private int pageTemplateId = 0;
private string zoneId = string.Empty;
private Guid instanceGuid = Guid.Empty;
private string aliasPath = string.Empty;
private string webPartId = string.Empty;
#endregion
#region "Page methods"
///
/// Raises the event.
///
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.contentpersonalization", "Read"))
{
RedirectToAccessDenied(String.Format(GetString("general.permissionresource"), "Read", "Content personalization"));
}
variantType = listElem.VariantType = VariantTypeFunctions.GetVariantTypeEnum(QueryHelper.GetString("varianttype", string.Empty));
// Check permissions and redirect
OnlineMarketingContext.CheckPermissions(variantType);
// Get the alias path of the current node
if (Node == null)
{
listElem.StopProcessing = true;
}
// Setup the list control properties
pageTemplateId = listElem.PageTemplateID = QueryHelper.GetInteger("templateid", 0);
zoneId = listElem.ZoneID = QueryHelper.GetText("zoneid", string.Empty);
instanceGuid = listElem.InstanceGUID = QueryHelper.GetGuid("instanceguid", Guid.Empty);
aliasPath = QueryHelper.GetString("aliaspath", string.Empty);
webPartId = QueryHelper.GetString("webpartid", string.Empty);
btnClose.Text = GetString("general.close");
}
///
/// Handles the Load event of the Page control.
///
protected void Page_Load(object sender, EventArgs e)
{
// Setup the modal dialog
SetCulture();
RegisterEscScript();
ScriptHelper.RegisterDialogScript(this);
ScriptHelper.RegisterWOpenerScript(this);
// Setup the title, image, help
PageTitle title = CurrentMaster.Title;
title.HelpName = "helpTopic";
title.TitleText = GetString("contentpersonalizationvariant.list");
title.TitleImage = GetImageUrl("Objects/OM_MVTVariant/object.png");
// Must be set be to help icon created
title.HelpTopicName = "contentpersonalizationvariant_list";
// Set the dark header (+ dark help icon)
CurrentMaster.PanelBody.CssClass += " DialogsPageHeader";
title.HelpIconUrl = GetImageUrl("General/HelpLargeDark.png");
// Get Edit action button
Action editAction = null;
editAction = listElem.Grid.GridActions.Actions[0] as Action;
editAction.OnClick = "OpenVariantProperties({0}); return false;";
// Set NodeID in order to check the access to the document
listElem.NodeID = NodeID;
listElem.AllowSorting = false;
listElem.OnAction += new CommandEventHandler(listElem_OnAction);
}
///
/// Raises the event.
///
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
// Setup the modal dialog
RegisterModalPageScripts();
// Choose the correct javascript method for opening web part/zone properties
string functionName = string.Empty;
// Set a script to open the web part properties modal dialog
string parameters = string.Empty;
// Set the script to show the corresponding variant
string setVariant = string.Empty;
switch (variantType)
{
case VariantTypeEnum.WebPart:
functionName = "ConfigureWebPart";
parameters = "'" + zoneId + "','" + webPartId + "','" + aliasPath + "','" + instanceGuid + "'," + pageTemplateId;
setVariant = "SetVariant('Variant_WP_" + instanceGuid.ToString("N") + "', variantId);";
break;
case VariantTypeEnum.Widget:
functionName = "ConfigureWidget";
parameters = "'" + zoneId + "','" + webPartId + "','" + aliasPath + "','" + instanceGuid + "'," + pageTemplateId;
setVariant = "SetVariant('Variant_WP_" + instanceGuid.ToString("N") + "', variantId);";
break;
case VariantTypeEnum.Zone:
functionName = "ConfigureWebPartZone";
parameters = "'" + zoneId + "','" + aliasPath + "'," + pageTemplateId + "," + QueryHelper.GetText("islayoutzone", "false");
setVariant = "SetVariant('Variant_Zone_" + zoneId + "', variantId);";
break;
}
// Setup the script for opening web part/zone properties
string script = @"
function OpenVariantProperties(variantId)
{
CloseDialog();
if ((wopener." + functionName + @") && (wopener.SetVariant))
{
wopener." + setVariant + @"
wopener." + functionName + "(" + parameters + @");
}
} ";
ltrScript.Text = ScriptHelper.GetScript(script);
}
///
/// Handles the OnAction event of the listElem control. This events is raised when deleting a variant in the grid or changing its position (moving up/down)
///
protected void listElem_OnAction(object sender, EventArgs e)
{
// Set the flag that a variant has been deleted or moved up/down
ScriptManager.RegisterStartupScript(this, typeof(string), "refreshWOpener", "window.refreshPageOnClose = true;", true);
}
#endregion
}