/// <summary>
    /// Saves web part zone properties.
    /// </summary>
    public bool Save()
    {
        if (ZoneVariantID > 0)
        {
            // Check OnlineMarketing permissions
            if (!CheckPermissions("Manage"))
            {
                ShowInformation(GetString("general.modifynotallowed"));
                return false;
            }
        }

        // Save the data
        if (formElem.SaveData(""))
        {
            DataRow dr = formElem.DataRow;

            // Get basicform's datarow and update the fields
            if ((webPartZone != null) && (dr != null) && (pti != null))
            {
                webPartZone.XMLVersion = 1;
                // New variant
                if (IsNewVariant)
                {
                    webPartZone = pti.TemplateInstance.EnsureZone(webPartZone.ZoneID);

                    // Ensure that all the zones which are not saved in the template already will be saved now
                    // This is a case for new layout zones
                    if (!webPartZone.HasVariants)
                    {
                        TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
                        CMSPortalManager.SaveTemplateChanges(pi, pti.TemplateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree);
                    }

                    webPartZone = webPartZone.Clone();

                    string webPartControlId = string.Empty;

                    // Re-generate web part unique IDs
                    foreach (WebPartInstance wpi in webPartZone.WebParts)
                    {
                        bool webPartIdExists = false;
                        int offset = 0;

                        // Set new web part unique ID
                        string baseId = Regex.Replace(wpi.ControlID, "\\d+$", "");
                        do
                        {
                            webPartControlId = WebPartZoneInstance.GetUniqueWebPartId(baseId, pti.TemplateInstance, offset);
                            // Check if the returned web part control id is already used in the new zone variant
                            webPartIdExists = (webPartZone.GetWebPart(webPartControlId) != null);
                            offset++;
                        } while (webPartIdExists);

                        wpi.ControlID = webPartControlId;
                        wpi.InstanceGUID = new Guid();
                    }
                }

                // If zone type changed, delete all webparts in the zone
                if (dr.Table.Columns.Contains("WidgetZoneType") &&
                    ValidationHelper.GetString(webPartZone.GetValue("WidgetZoneType"), "") != ValidationHelper.GetString(dr["WidgetZoneType"], ""))
                {
                    webPartZone.RemoveAllWebParts();
                }

                foreach (DataColumn column in dr.Table.Columns)
                {
                    webPartZone.MacroTable[column.ColumnName.ToLowerCSafe()] = formElem.MacroTable[column.ColumnName.ToLowerCSafe()];
                    webPartZone.SetValue(column.ColumnName, dr[column]);
                }

                // Ensure the layout zone flag
                webPartZone.LayoutZone = QueryHelper.GetBoolean("layoutzone", false);

                // Save standard zone
                if ((ZoneVariantID == 0) && (!IsNewVariant))
                {
                    // Update page template
                    PageTemplateInfoProvider.SetPageTemplateInfo(pti);
                }
                else
                {
                    // Save zone variant
                    if ((webPartZone != null)
                        && (webPartZone.ParentTemplateInstance != null)
                        && (webPartZone.ParentTemplateInstance.ParentPageTemplate != null)
                        && (!webPartZone.WebPartsContainVariants)) // Save only if any of the child web parts does not have variants
                    {
                        // Save the variant properties
                        VariantSettings variant = new VariantSettings()
                        {
                            ID = ZoneVariantID,
                            ZoneID = webPartZone.ZoneID,
                            PageTemplateID = webPartZone.ParentTemplateInstance.ParentPageTemplate.PageTemplateId,
                        };

                        // Get variant description properties
                        Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable;
                        if (properties != null)
                        {
                            variant.Name = ValidationHelper.GetString(properties["codename"], string.Empty);
                            variant.DisplayName = ValidationHelper.GetString(properties["displayname"], string.Empty);
                            variant.Description = ValidationHelper.GetString(properties["description"], string.Empty);
                            variant.Enabled = ValidationHelper.GetBoolean(properties["enabled"], true);

                            if (PortalContext.ContentPersonalizationEnabled)
                            {
                                variant.Condition = ValidationHelper.GetString(properties["condition"], string.Empty);
                            }
                        }

                        mZoneVariantID = VariantHelper.SetVariant(variantMode, variant, webPartZone.GetXmlNode());

                        // The variants are cached -> Reload
                        pti.TemplateInstance.LoadVariants(true, VariantModeEnum.None);
                    }
                }

                // Reload the form (because of macro values set only by JS)
                formElem.LoadData(dr);

                ShowChangesSaved();

                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
Пример #2
0
    /// <summary>
    /// Saves web part zone properties.
    /// </summary>
    public bool Save()
    {
        if (ZoneVariantID > 0)
        {
            // Check OnlineMarketing permissions
            if (!CheckPermissions("Manage"))
            {
                ShowInformation(GetString("general.modifynotallowed"));
                return(false);
            }
        }

        // Save the data
        if (formElem.SaveData(""))
        {
            DataRow dr = formElem.DataRow;

            // Get basicform's datarow and update the fields
            if ((webPartZone != null) && (dr != null) && (pti != null))
            {
                webPartZone.XMLVersion = 1;
                // New variant
                if (IsNewVariant)
                {
                    webPartZone = pti.TemplateInstance.EnsureZone(webPartZone.ZoneID);

                    // Ensure that all the zones which are not saved in the template already will be saved now
                    // This is a case for new layout zones
                    if (!webPartZone.HasVariants)
                    {
                        TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
                        CMSPortalManager.SaveTemplateChanges(pi, pti.TemplateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree);
                    }

                    webPartZone = webPartZone.Clone();

                    string webPartControlId = string.Empty;

                    // Re-generate web part unique IDs
                    foreach (WebPartInstance wpi in webPartZone.WebParts)
                    {
                        bool webPartIdExists = false;
                        int  offset          = 0;

                        // Set new web part unique ID
                        string baseId = Regex.Replace(wpi.ControlID, "\\d+$", "");
                        do
                        {
                            webPartControlId = WebPartZoneInstance.GetUniqueWebPartId(baseId, pti.TemplateInstance, offset);
                            // Check if the returned web part control id is already used in the new zone variant
                            webPartIdExists = (webPartZone.GetWebPart(webPartControlId) != null);
                            offset++;
                        } while (webPartIdExists);

                        wpi.ControlID    = webPartControlId;
                        wpi.InstanceGUID = new Guid();
                    }
                }

                // If zone type changed, delete all webparts in the zone
                if (dr.Table.Columns.Contains("WidgetZoneType") &&
                    ValidationHelper.GetString(webPartZone.GetValue("WidgetZoneType"), "") != ValidationHelper.GetString(dr["WidgetZoneType"], ""))
                {
                    webPartZone.RemoveAllWebParts();
                }

                foreach (DataColumn column in dr.Table.Columns)
                {
                    webPartZone.MacroTable[column.ColumnName.ToLowerCSafe()] = formElem.MacroTable[column.ColumnName.ToLowerCSafe()];
                    webPartZone.SetValue(column.ColumnName, dr[column]);
                }

                // Ensure the layout zone flag
                webPartZone.LayoutZone = QueryHelper.GetBoolean("layoutzone", false);

                // Save standard zone
                if ((ZoneVariantID == 0) && (!IsNewVariant))
                {
                    // Update page template
                    PageTemplateInfoProvider.SetPageTemplateInfo(pti);
                }
                else
                {
                    // Save zone variant
                    if ((webPartZone != null) &&
                        (webPartZone.ParentTemplateInstance != null) &&
                        (webPartZone.ParentTemplateInstance.ParentPageTemplate != null) &&
                        (!webPartZone.WebPartsContainVariants))    // Save only if any of the child web parts does not have variants
                    {
                        // Save the variant properties
                        VariantSettings variant = new VariantSettings()
                        {
                            ID             = ZoneVariantID,
                            ZoneID         = webPartZone.ZoneID,
                            PageTemplateID = webPartZone.ParentTemplateInstance.ParentPageTemplate.PageTemplateId,
                        };

                        // Get variant description properties
                        Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable;
                        if (properties != null)
                        {
                            variant.Name        = ValidationHelper.GetString(properties["codename"], string.Empty);
                            variant.DisplayName = ValidationHelper.GetString(properties["displayname"], string.Empty);
                            variant.Description = ValidationHelper.GetString(properties["description"], string.Empty);
                            variant.Enabled     = ValidationHelper.GetBoolean(properties["enabled"], true);

                            if (PortalContext.ContentPersonalizationEnabled)
                            {
                                variant.Condition = ValidationHelper.GetString(properties["condition"], string.Empty);
                            }
                        }

                        mZoneVariantID = VariantHelper.SetVariant(variantMode, variant, webPartZone.GetXmlNode());

                        // The variants are cached -> Reload
                        pti.TemplateInstance.LoadVariants(true, VariantModeEnum.None);
                    }
                }

                // Reload the form (because of macro values set only by JS)
                formElem.LoadData(dr);

                ShowChangesSaved();

                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            return(false);
        }
    }