Example #1
0
    /// <summary>
    /// Removes document content for all editor widgets in a given document.
    /// </summary>
    /// <param name="treeNode">Document to update</param>
    /// <param name="pti">Page template instance</param>
    /// <param name="omitUpdate">Indicates whether update on a given document should be omitted</param>
    private void ClearEditorWidgetsContent(TreeNode treeNode, PageTemplateInstance pti, bool omitUpdate)
    {
        var documentWebPartsXml = treeNode.GetStringValue("DocumentWebParts", String.Empty);

        if (String.IsNullOrEmpty(documentWebPartsXml))
        {
            return;
        }

        var webPartIds = new List <string>();

        // Get web part IDs from DocumentWebParts column
        webPartIds.AddRange(GetWebPartIDs(documentWebPartsXml));

        // Get web part IDs from page template (widget zones only) and combine them with existing list.
        webPartIds.AddRange(GetWebPartIDs(pti.GetZonesXML(WidgetZoneTypeEnum.Editor)));

        // Remove web part IDs from DocumentContent
        foreach (var wpId in webPartIds.Distinct())
        {
            treeNode.DocumentContent.EditableWebParts.Remove(wpId);
        }

        treeNode.SetValue("DocumentContent", treeNode.DocumentContent.GetContentXml());

        if (!omitUpdate)
        {
            DocumentHelper.UpdateDocument(treeNode, TreeProvider);
        }
    }
    /// <summary>
    /// Saves widget properties.
    /// </summary>
    public bool Save()
    {
        if (VariantID > 0)
        {
            // Check MVT/CP security
            if (!CheckPermissions("Manage"))
            {
                DisplayError("general.modifynotallowed");
                return(false);
            }
        }

        // Save the data
        if ((CurrentPageInfo != null) && (mTemplateInstance != null) && SaveForm(formCustom))
        {
            ViewModeEnum viewMode = PortalContext.ViewMode;

            // Check manage permission for non-livesite version
            if (!viewMode.IsLiveSite() && viewMode != ViewModeEnum.DashboardWidgets && viewMode != ViewModeEnum.UserWidgets)
            {
                if (CurrentUser.IsAuthorizedPerDocument(CurrentPageInfo.NodeID, CurrentPageInfo.ClassName, NodePermissionsEnum.Modify) != AuthorizationResultEnum.Allowed)
                {
                    DisplayError("general.modifynotallowed");
                    return(false);
                }

                // Check design permissions
                if (PortalContext.IsDesignMode(viewMode, false) && !PortalContext.CurrentUserIsDesigner)
                {
                    RedirectToAccessDenied("CMS.Design", "Design");
                }
            }

            PageTemplateInfo pti = mTemplateInstance.ParentPageTemplate;
            if (PortalContext.IsDesignMode(viewMode) && SynchronizationHelper.IsCheckedOutByOtherUser(pti))
            {
                string   userName = null;
                UserInfo ui       = UserInfoProvider.GetUserInfo(pti.Generalized.IsCheckedOutByUserID);
                if (ui != null)
                {
                    userName = HTMLHelper.HTMLEncode(ui.GetFormattedUserName(IsLiveSite));
                }

                DisplayError(string.Format(GetString("ObjectEditMenu.CheckedOutByAnotherUser"), pti.TypeInfo.ObjectType, pti.DisplayName, userName));
                return(false);
            }

            // Get the zone
            mWebPartZoneInstance = mTemplateInstance.EnsureZone(ZoneId);

            if (mWebPartZoneInstance != null)
            {
                mWebPartZoneInstance.WidgetZoneType = ZoneType;

                // Add new widget
                if (IsNewWidget)
                {
                    bool isLayoutZone = (QueryHelper.GetBoolean("layoutzone", false));
                    int  widgetID     = ValidationHelper.GetInteger(WidgetId, 0);

                    // Create new widget instance
                    mWidgetInstance = PortalHelper.AddNewWidget(widgetID, ZoneId, ZoneType, isLayoutZone, mTemplateInstance);
                }

                // Ensure handling of the currently edited object (if not exists -> redirect)
                UIContext.EditedObject = mWidgetInstance;

                mWidgetInstance.XMLVersion = 1;
                if (IsNewVariant)
                {
                    mWidgetInstance = mWidgetInstance.Clone();

                    // Check whether the editor widgets have been already customized
                    if (CurrentPageInfo.DocumentTemplateInstance.WebPartZones.Count == 0)
                    {
                        // There are no customized editor widgets yet => copy the default editor widgets from the page template under the document (to enable customization)

                        // Save to the document as editor admin changes
                        TreeNode node = DocumentHelper.GetDocument(CurrentPageInfo.DocumentID, mTreeProvider);

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

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

                bool isLayoutWidget = ((mWebPartInfo != null) && ((WebPartTypeEnum)mWebPartInfo.WebPartType == WebPartTypeEnum.Layout));

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

                // Ensure unique id for new widget variant or layout widget
                if (IsNewVariant || (isLayoutWidget && IsNewWidget))
                {
                    string controlId = GetUniqueWidgetId(mWidgetInfo.WidgetName);

                    if (!string.IsNullOrEmpty(controlId))
                    {
                        mWidgetInstance.ControlID = controlId;
                    }
                    else
                    {
                        DisplayError("Unable to generate unique widget id.");
                        return(false);
                    }
                }

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

                bool isWidgetVariant = (VariantID > 0) || IsNewVariant;
                if (!isWidgetVariant)
                {
                    // Save the changes
                    if ((viewMode.IsEdit(true) || viewMode.IsEditLive()) && (ZoneType == WidgetZoneTypeEnum.Editor))
                    {
                        if (DocumentManager.AllowSave)
                        {
                            // Store the editor widgets in the temporary interlayer
                            PortalContext.SaveEditorWidgets(CurrentPageInfo.DocumentID, mTemplateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor));
                        }
                    }
                    else
                    {
                        // Save the changes
                        CMSPortalManager.SaveTemplateChanges(CurrentPageInfo, mTemplateInstance, ZoneType, viewMode, mTreeProvider);
                    }
                }
                else if ((viewMode.IsEdit()) && (ZoneType == WidgetZoneTypeEnum.Editor))
                {
                    Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable;

                    VariantHelper.SaveWebPartVariantChanges(mWidgetInstance, VariantID, 0, VariantMode, properties);

                    // Log widget variant synchronization
                    TreeNode node = DocumentHelper.GetDocument(CurrentPageInfo.DocumentID, mTreeProvider);
                    DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, mTreeProvider);
                }
            }

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

            // Display info message
            ShowChangesSaved();

            // Clear the cached web part
            CacheHelper.TouchKey("webpartinstance|" + InstanceGUID.ToString().ToLowerCSafe());

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Removes document content for all editor widgets in a given document.
    /// </summary>
    /// <param name="treeNode">Document to update</param>
    /// <param name="pti">Page template instance</param>
    /// <param name="omitUpdate">Indicates whether update on a given document should be omitted</param>
    private void ClearEditorWidgetsContent(TreeNode treeNode, PageTemplateInstance pti, bool omitUpdate)
    {
        var documentWebPartsXml = treeNode.GetStringValue("DocumentWebParts", String.Empty);

        if (String.IsNullOrEmpty(documentWebPartsXml))
        {
            return;
        }

        var webPartIds = new List<string>();

        // Get web part IDs from DocumentWebParts column
        webPartIds.AddRange(GetWebPartIDs(documentWebPartsXml));

        // Get web part IDs from page template (widget zones only) and combine them with existing list.
        webPartIds.AddRange(GetWebPartIDs(pti.GetZonesXML(WidgetZoneTypeEnum.Editor)));

        // Remove web part IDs from DocumentContent
        foreach (var wpId in webPartIds.Distinct())
        {
            treeNode.DocumentContent.EditableWebParts.Remove(wpId);
        }

        treeNode.SetValue("DocumentContent", treeNode.DocumentContent.GetContentXml());

        if (!omitUpdate)
        {
            DocumentHelper.UpdateDocument(treeNode, TreeProvider);
        }
    }
Example #4
0
    /// <summary>
    /// Saves widget properties.
    /// </summary>
    public bool Save()
    {
        if (VariantID > 0)
        {
            // Check MVT/CP security
            if (!CheckPermissions("Manage"))
            {
                DisplayError("general.modifynotallowed");
                return(false);
            }
        }

        // Save the data
        if ((pi != 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);
                }
            }

            PageTemplateInfo pti = templateInstance.ParentPageTemplate;
            if ((CMSContext.ViewMode == ViewModeEnum.Design) && CMSObjectHelper.IsCheckedOutByOtherUser(pti))
            {
                string   userName = null;
                UserInfo ui       = UserInfoProvider.GetUserInfo(pti.Generalized.IsCheckedOutByUserID);
                if (ui != null)
                {
                    userName = HTMLHelper.HTMLEncode(ui.GetFormattedUserName(IsLiveSite));
                }

                DisplayError(string.Format(GetString("ObjectEditMenu.CheckedOutByAnotherUser"), pti.ObjectType, pti.DisplayName, userName));
                return(false);
            }

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

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

                // Add new widget
                if (IsNewWidget)
                {
                    bool isLayoutZone = (QueryHelper.GetBoolean("layoutzone", false));
                    int  widgetID     = ValidationHelper.GetInteger(WidgetId, 0);

                    // Create new widget instance
                    widgetInstance = PortalHelper.AddNewWidget(widgetID, ZoneId, ZoneType, isLayoutZone, templateInstance, null);
                }

                widgetInstance.XMLVersion = 1;
                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, templateInstance);

                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, templateInstance, zoneType, CMSContext.ViewMode, tree);
                }
                else if ((CMSContext.ViewMode == ViewModeEnum.Edit) && (zoneType == WidgetZoneTypeEnum.Editor))
                {
                    Hashtable properties = WindowHelper.GetItem("variantProperties") as Hashtable;

                    PortalHelper.SaveWebPartVariantChanges(widgetInstance, VariantID, 0, VariantMode, properties);

                    // 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().ToLowerCSafe());
            }

            return(true);
        }

        return(false);
    }
Example #5
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);
    }