Beispiel #1
0
    /// <summary>
    /// Sets current layout.
    /// </summary>
    protected void SetCurrentLayout(bool saveToWebPartInstance)
    {
        if ((webPart != null) && (LayoutCodeName != "|new|"))
        {
            if (saveToWebPartInstance)
            {
                if (LayoutCodeName == "|default|")
                {
                    webPart.SetValue("WebPartLayout", "");
                }
                else
                {
                    webPart.SetValue("WebPartLayout", LayoutCodeName);
                }

                bool isWebPartVariant = (variantId > 0) || (zoneVariantId > 0) || isNewVariant;
                if (!isWebPartVariant)
                {
                    // Update page template
                    PageTemplateInfoProvider.SetPageTemplateInfo(pti);
                }
                else
                {
                    // Save the variant properties
                    if ((webPart != null) &&
                        (webPart.ParentZone != null) &&
                        (webPart.ParentZone.ParentTemplateInstance != null) &&
                        (webPart.ParentZone.ParentTemplateInstance.ParentPageTemplate != null))
                    {
                        XmlNode xmlWebParts = (zoneVariantId > 0) ? webPart.ParentZone.GetXmlNode() : webPart.GetXmlNode();

                        VariantHelper.SetVariantWebParts(webPart.VariantMode, (zoneVariantId > 0) ? zoneVariantId : variantId, xmlWebParts);

                        // The variants are cached -> Reload
                        webPart.ParentZone.ParentTemplateInstance.LoadVariants(true, VariantModeEnum.None);
                    }
                }
            }

            string parameters = aliasPath + "/" + zoneId + "/" + webpartId;
            string cacheName  = "CMSVirtualWebParts|" + parameters.ToLowerCSafe().TrimStart('/');

            CacheHelper.Remove(cacheName);
        }
    }
Beispiel #2
0
    /// <summary>
    /// Sets current layout.
    /// </summary>
    protected void SetCurrentLayout(bool saveToWebPartInstance)
    {
        if ((webPart != null) && (LayoutCodeName != "|new|"))
        {
            if (saveToWebPartInstance)
            {
                if (LayoutCodeName == "|default|")
                {
                    webPart.SetValue("WebPartLayout", "");
                }
                else
                {
                    webPart.SetValue("WebPartLayout", LayoutCodeName);
                }

                bool isWebPartVariant = (variantId > 0) || (zoneVariantId > 0) || isNewVariant;
                if (!isWebPartVariant)
                {
                    // Update page template
                    PageTemplateInfoProvider.SetPageTemplateInfo(pti);
                }
                else
                {
                    // Save the variant properties
                    if ((webPart != null) &&
                        (webPart.ParentZone != null) &&
                        (webPart.ParentZone.ParentTemplateInstance != null) &&
                        (webPart.ParentZone.ParentTemplateInstance.ParentPageTemplate != null))
                    {
                        XmlDocument doc         = new XmlDocument();
                        XmlNode     xmlWebParts = null;

                        if (zoneVariantId > 0)
                        {
                            // This webpart is in a zone variant therefore save the whole variant webparts
                            xmlWebParts = webPart.ParentZone.GetXmlNode(doc);
                            if (webPart.VariantMode == VariantModeEnum.MVT)
                            {
                                ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(zoneVariantId, xmlWebParts);
                            }
                            else if (webPart.VariantMode == VariantModeEnum.ContentPersonalization)
                            {
                                ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(zoneVariantId, xmlWebParts);
                            }
                        }
                        else if (variantId > 0)
                        {
                            // This webpart is a web part variant
                            xmlWebParts = webPart.GetXmlNode(doc);
                            if (webPart.VariantMode == VariantModeEnum.MVT)
                            {
                                ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(variantId, xmlWebParts);
                            }
                            else if (webPart.VariantMode == VariantModeEnum.ContentPersonalization)
                            {
                                ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(variantId, xmlWebParts);
                            }
                        }
                    }
                }
            }

            string parameters = aliasPath + "/" + zoneId + "/" + webpartId;
            string cacheName  = "CMSVirtualWebParts|" + parameters.ToLowerCSafe().TrimStart('/');

            CacheHelper.Remove(cacheName);
        }
    }
    /// <summary>
    /// Saves webpart properties.
    /// </summary>
    public bool Save()
    {
        // Check MVT/CP security
        if (VariantID > 0)
        {
            // Check OnlineMarketing permissions.
            if (!CheckPermissions("Manage"))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("general.modifynotallowed");
                return(false);
            }
        }

        // Save the data
        if ((pi != null) && (pti != null) && (templateInstance != null) && SaveForm(form))
        {
            // Add web part if new
            if (IsNewWebPart)
            {
                AddWebPart();
            }

            WebPartInstance originalWebPartInstance = webPartInstance;
            if (IsNewVariant)
            {
                webPartInstance             = webPartInstance.Clone();
                webPartInstance.VariantMode = VariantModeFunctions.GetVariantModeEnum(QueryHelper.GetString("variantmode", String.Empty).ToLower());
            }

            // Get basicform's datarow and update webpart
            SaveFormToWebPart(form);

            bool isWebPartVariant = (VariantID > 0) || (ZoneVariantID > 0) || IsNewVariant;
            if (!isWebPartVariant)
            {
                // Save the changes
                CMSPortalManager.SaveTemplateChanges(pi, pti, templateInstance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tree);
            }
            else
            {
                // Save the variant properties
                if ((webPartInstance != null) &&
                    (webPartInstance.ParentZone != null) &&
                    (!webPartInstance.ParentZone.HasVariants) && // Save only if the parent zone does not have any variants
                    (webPartInstance.ParentZone.ParentTemplateInstance != null) &&
                    (webPartInstance.ParentZone.ParentTemplateInstance.ParentPageTemplate != null))
                {
                    string      variantName             = string.Empty;
                    string      variantDisplayName      = string.Empty;
                    string      variantDisplayCondition = string.Empty;
                    string      variantDescription      = string.Empty;
                    bool        variantEnabled          = true;
                    string      zoneId       = webPartInstance.ParentZone.ZoneID;
                    int         templateId   = webPartInstance.ParentZone.ParentTemplateInstance.ParentPageTemplate.PageTemplateId;
                    Guid        instanceGuid = Guid.Empty;
                    XmlDocument doc          = new XmlDocument();
                    XmlNode     xmlWebParts  = null;

                    if (ZoneVariantID > 0)
                    {
                        // This webpart is in a zone variant therefore save the whole variant webparts
                        xmlWebParts = webPartInstance.ParentZone.GetXmlNode(doc);
                        if (VariantMode == VariantModeEnum.MVT)
                        {
                            // MVT variant
                            ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(ZoneVariantID, xmlWebParts);
                        }
                        else if (VariantMode == VariantModeEnum.ContentPersonalization)
                        {
                            // Content personalization variant
                            ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(ZoneVariantID, xmlWebParts);
                        }
                    }
                    else
                    {
                        // web part/widget variant
                        xmlWebParts  = webPartInstance.GetXmlNode(doc);
                        instanceGuid = InstanceGUID;

                        Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable;
                        if (properties != null)
                        {
                            variantName        = ValidationHelper.GetString(properties["codename"], string.Empty);
                            variantDisplayName = ValidationHelper.GetString(properties["displayname"], string.Empty);
                            variantDescription = ValidationHelper.GetString(properties["description"], string.Empty);
                            variantEnabled     = ValidationHelper.GetBoolean(properties["enabled"], true);
                            if (VariantMode == VariantModeEnum.ContentPersonalization)
                            {
                                variantDisplayCondition = ValidationHelper.GetString(properties["condition"], string.Empty);
                            }
                        }

                        // Save the web part variant properties
                        if (VariantMode == VariantModeEnum.MVT)
                        {
                            // MVT variant
                            ModuleCommands.OnlineMarketingSaveMVTVariant(VariantID, variantName, variantDisplayName, variantDescription, variantEnabled, zoneId, webPartInstance.InstanceGUID, templateId, 0, xmlWebParts);
                        }
                        else if (VariantMode == VariantModeEnum.ContentPersonalization)
                        {
                            // Content personalization variant
                            ModuleCommands.OnlineMarketingSaveContentPersonalizationVariant(VariantID, variantName, variantDisplayName, variantDescription, variantEnabled, variantDisplayCondition, zoneId, webPartInstance.InstanceGUID, templateId, 0, xmlWebParts);
                        }

                        // The variants are cached -> Reload
                        if (originalWebPartInstance != null)
                        {
                            originalWebPartInstance.LoadVariants(true, VariantMode);
                        }
                    }
                }
            }

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

            // Clear the cached web part
            if (InstanceGUID != null)
            {
                CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLower());
            }

            return(true);
        }
        else if ((webPartInstance != null) && (webPartInstance.ParentZone != null))
        {
            // Reload the zone/web part variants when saving of the form fails
            webPartInstance.ParentZone.LoadVariants(true, VariantModeEnum.None);
        }

        return(false);
    }
Beispiel #4
0
    /// <summary>
    /// Sets current layout.
    /// </summary>
    protected void SetCurrentLayout(bool saveToWebPartInstance, bool updateLayout)
    {
        if ((webPart != null) && (LayoutCodeName != "|new|"))
        {
            if (saveToWebPartInstance)
            {
                if (LayoutCodeName == "|default|")
                {
                    webPart.SetValue("WebPartLayout", "");
                }
                else
                {
                    webPart.SetValue("WebPartLayout", LayoutCodeName);
                }

                bool isWebPartVariant = (variantId > 0) || (zoneVariantId > 0) || isNewVariant;
                if (!isWebPartVariant)
                {
                    // Update page template
                    PageTemplateInfoProvider.SetPageTemplateInfo(pti);
                }
                else
                {
                    // Save the variant properties
                    if ((webPart != null) &&
                        (webPart.ParentZone != null) &&
                        (webPart.ParentZone.ParentTemplateInstance != null) &&
                        (webPart.ParentZone.ParentTemplateInstance.ParentPageTemplate != null))
                    {
                        XmlDocument doc         = new XmlDocument();
                        XmlNode     xmlWebParts = null;

                        if (zoneVariantId > 0)
                        {
                            // This webpart is in a zone variant therefore save the whole variant webparts
                            xmlWebParts = webPart.ParentZone.GetXmlNode(doc);
                            if (webPart.VariantMode == VariantModeEnum.MVT)
                            {
                                ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(zoneVariantId, xmlWebParts);
                            }
                            else if (webPart.VariantMode == VariantModeEnum.ContentPersonalization)
                            {
                                ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(zoneVariantId, xmlWebParts);
                            }
                        }
                        else if (variantId > 0)
                        {
                            // This webpart is a web part variant
                            xmlWebParts = webPart.GetXmlNode(doc);
                            if (webPart.VariantMode == VariantModeEnum.MVT)
                            {
                                ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(variantId, xmlWebParts);
                            }
                            else if (webPart.VariantMode == VariantModeEnum.ContentPersonalization)
                            {
                                ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(variantId, xmlWebParts);
                            }
                        }
                    }
                }
            }

            string parameters = this.aliasPath + "/" + this.zoneId + "/" + this.webpartId;
            string cacheName  = "CMSVirtualWebParts|" + parameters.ToLower().TrimStart('/');

            CacheHelper.Remove(cacheName);

            if (updateLayout)
            {
                WebPartInfo wpi = WebPartInfoProvider.GetWebPartInfo(webPart.WebPartType);
                if (wpi != null)
                {
                    WebPartLayoutInfo wpli = WebPartLayoutInfoProvider.GetWebPartLayoutInfo(wpi.WebPartName, LayoutCodeName);
                    if (wpli != null)
                    {
                        if (CurrentUser.IsAuthorizedPerResource("CMS.Design", "EditCode"))
                        {
                            wpli.WebPartLayoutCode = etaCode.Text;
                        }
                        wpli.WebPartLayoutCSS = etaCSS.Text;

                        WebPartLayoutInfoProvider.SetWebPartLayoutInfo(wpli);
                    }
                }
            }
        }
    }
Beispiel #5
0
    /// <summary>
    /// Saves webpart properties.
    /// </summary>
    public void Save()
    {
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Design", "EditCode"))
        {
            return;
        }

        webPart.SetValue("WebPartCode", txtCode.Text);


        bool isWebPartVariant = (variantId > 0) || (zoneVariantId > 0) || isNewVariant;

        if (!isWebPartVariant)
        {
            // Update page template
            PageTemplateInfoProvider.SetPageTemplateInfo(pti);
        }
        else
        {
            // Save the variant properties
            if ((webPart != null) &&
                (webPart.ParentZone != null) &&
                (webPart.ParentZone.ParentTemplateInstance != null) &&
                (webPart.ParentZone.ParentTemplateInstance.ParentPageTemplate != null))
            {
                XmlDocument doc         = new XmlDocument();
                XmlNode     xmlWebParts = null;

                if (zoneVariantId > 0)
                {
                    // This webpart is in a zone variant therefore save the whole variant webparts
                    xmlWebParts = webPart.ParentZone.GetXmlNode(doc);
                    if (webPart.VariantMode == VariantModeEnum.MVT)
                    {
                        ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(zoneVariantId, xmlWebParts);
                    }
                    else if (webPart.VariantMode == VariantModeEnum.ContentPersonalization)
                    {
                        ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(zoneVariantId, xmlWebParts);
                    }
                }
                else if (variantId > 0)
                {
                    // This webpart is a web part variant
                    xmlWebParts = webPart.GetXmlNode(doc);
                    if (webPart.VariantMode == VariantModeEnum.MVT)
                    {
                        ModuleCommands.OnlineMarketingSaveMVTVariantWebParts(variantId, xmlWebParts);
                    }
                    else if (webPart.VariantMode == VariantModeEnum.ContentPersonalization)
                    {
                        ModuleCommands.OnlineMarketingSaveContentPersonalizationVariantWebParts(variantId, xmlWebParts);
                    }
                }
            }
        }

        string parameters = aliasPath + "/" + zoneId + "/" + webpartId;
        string cacheName  = "CMSVirtualWebParts|" + parameters.ToLower().TrimStart('/');

        CacheHelper.Remove(cacheName);
    }
Beispiel #6
0
    /// <summary>
    /// Saves widget properties.
    /// </summary>
    public bool Save()
    {
        if (VariantID > 0)
        {
            // Check MVT/CP security
            if (!CheckPermissions("Manage"))
            {
                ShowError("general.modifynotallowed");
                return(false);
            }
        }

        // Save the data
        if ((pi != null) && (pti != null) && (templateInstance != null) && SaveForm(formCustom))
        {
            // Check manage permission for non-livesite version
            if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) && (CMSContext.ViewMode != ViewModeEnum.DashboardWidgets))
            {
                if (CMSContext.CurrentUser.IsAuthorizedPerDocument(pi.NodeId, pi.ClassName, NodePermissionsEnum.Modify) != AuthorizationResultEnum.Allowed)
                {
                    return(false);
                }
            }

            // Get the zone
            zone = templateInstance.EnsureZone(ZoneId);

            if (zone != null)
            {
                zone.WidgetZoneType = zoneType;

                // Add new widget
                if (IsNewWidget)
                {
                    AddWidget();
                }

                if (IsNewVariant)
                {
                    widgetInstance = widgetInstance.Clone();

                    if (pi.DocumentTemplateInstance.WebPartZones.Count == 0)
                    {
                        // Save to the document as editor admin changes
                        TreeNode node = DocumentHelper.GetDocument(pi.DocumentId, tree);

                        // Extract and set the document web parts
                        node.SetValue("DocumentWebParts", templateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor));

                        // Save the document
                        DocumentHelper.UpdateDocument(node, tree);
                    }
                }

                // Get basicform's datarow and update widget
                SaveFormToWidget(formCustom);

                if (IsNewVariant)
                {
                    // Ensures unique id for new widget variant
                    widgetInstance.ControlID = WebPartZoneInstance.GetUniqueWebPartId(wi.WidgetName, zone.ParentTemplateInstance);
                }

                // Allow set dashboard in design mode
                if ((zoneType == WidgetZoneTypeEnum.Dashboard) && String.IsNullOrEmpty(PortalContext.DashboardName))
                {
                    PortalContext.SetViewMode(ViewModeEnum.Design);
                }

                bool isWidgetVariant = (VariantID > 0) || IsNewVariant;
                if (!isWidgetVariant)
                {
                    // Save the changes
                    CMSPortalManager.SaveTemplateChanges(pi, pti, templateInstance, zoneType, CMSContext.ViewMode, tree);
                }
                else if ((CMSContext.ViewMode == ViewModeEnum.Edit) && (zoneType == WidgetZoneTypeEnum.Editor))
                {
                    // Save the variant properties
                    if ((widgetInstance != null) &&
                        (widgetInstance.ParentZone != null) &&
                        (widgetInstance.ParentZone.ParentTemplateInstance != null) &&
                        (widgetInstance.ParentZone.ParentTemplateInstance.ParentPageTemplate != null))
                    {
                        string      variantName             = string.Empty;
                        string      variantDisplayName      = string.Empty;
                        string      variantDisplayCondition = string.Empty;
                        string      variantDescription      = string.Empty;
                        bool        variantEnabled          = true;
                        string      zoneId       = widgetInstance.ParentZone.ZoneID;
                        int         templateId   = widgetInstance.ParentZone.ParentTemplateInstance.ParentPageTemplate.PageTemplateId;
                        Guid        instanceGuid = Guid.Empty;
                        XmlDocument doc          = new XmlDocument();
                        XmlNode     xmlWebParts  = null;

                        xmlWebParts  = widgetInstance.GetXmlNode(doc);
                        instanceGuid = InstanceGUID;

                        Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable;
                        if (properties != null)
                        {
                            variantName        = ValidationHelper.GetString(properties["codename"], string.Empty);
                            variantDisplayName = ValidationHelper.GetString(properties["displayname"], string.Empty);
                            variantDescription = ValidationHelper.GetString(properties["description"], string.Empty);
                            variantEnabled     = ValidationHelper.GetBoolean(properties["enabled"], true);

                            if (VariantMode == VariantModeEnum.ContentPersonalization)
                            {
                                variantDisplayCondition = ValidationHelper.GetString(properties["condition"], string.Empty);
                            }
                        }

                        // Save the web part variant properties
                        if (VariantMode == VariantModeEnum.MVT)
                        {
                            ModuleCommands.OnlineMarketingSaveMVTVariant(VariantID, variantName, variantDisplayName, variantDescription, variantEnabled, zoneId, widgetInstance.InstanceGUID, templateId, pi.DocumentId, xmlWebParts);
                        }
                        else if (VariantMode == VariantModeEnum.ContentPersonalization)
                        {
                            ModuleCommands.OnlineMarketingSaveContentPersonalizationVariant(VariantID, variantName, variantDisplayName, variantDescription, variantEnabled, variantDisplayCondition, zoneId, widgetInstance.InstanceGUID, templateId, pi.DocumentId, xmlWebParts);
                        }

                        // Clear the document template
                        templateInstance.ParentPageTemplate.ParentPageInfo.DocumentTemplateInstance = null;

                        // Log widget variant synchronization
                        TreeNode node = DocumentHelper.GetDocument(pi.DocumentId, tree);
                        DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree);
                    }
                }
            }

            // Reload the form (because of macro values set only by JS)
            formCustom.ReloadData();

            // Clear the cached web part
            if (InstanceGUID != null)
            {
                CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLower());
            }

            return(true);
        }

        return(false);
    }