示例#1
0
    /// <summary>
    /// Handles UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of the action which should be performed</param>
    /// <param name="actionArgument">ID of the item the action should be performed with</param>
    protected void gridElem_OnAction(string actionName, object actionArgument)
    {
        if (!CheckPermissions("CMS.ContentPersonalization", "Manage"))
        {
            return;
        }

        int variantId = ValidationHelper.GetInteger(actionArgument, 0);

        if (variantId > 0)
        {
            string action = actionName.ToLowerCSafe();
            switch (action)
            {
            case "delete":
            {
                // Get the instance in order to clear the cache
                ContentPersonalizationVariantInfo vi = ContentPersonalizationVariantInfoProvider.GetContentPersonalizationVariant(variantId);

                // Delete the object
                ContentPersonalizationVariantInfoProvider.DeleteContentPersonalizationVariant(variantId);
                RaiseOnAction(string.Empty, null);

                // Log widget variant synchronization
                if ((vi != null) && (vi.VariantDocumentID > 0))
                {
                    // Log synchronization
                    DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, tree);
                }
            }
            break;

            case "up":
            case "down":
            {
                // Get the instance in order to clear the cache
                ContentPersonalizationVariantInfo vi = ContentPersonalizationVariantInfoProvider.GetContentPersonalizationVariant(variantId);

                // Use try/catch due to license check
                try
                {
                    if (action == "up")
                    {
                        // Move up
                        ContentPersonalizationVariantInfoProvider.MoveVariantUp(variantId);
                    }
                    else
                    {
                        // Move down
                        ContentPersonalizationVariantInfoProvider.MoveVariantDown(variantId);
                    }

                    RaiseOnAction(string.Empty, null);

                    // Log widget variant synchronization
                    if (vi.VariantDocumentID > 0)
                    {
                        // Log synchronization
                        DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, tree);
                    }
                }
                catch (Exception ex)
                {
                    lblError.Visible = true;
                    lblError.Text    = ex.Message;
                }
            }
            break;
            }
        }
    }
示例#2
0
    /// <summary>
    /// Raises event postback event.
    /// </summary>
    /// <param name="eventArgument">Event argument</param>
    /// <param name="uniqueCode">Unique code</param>
    /// <param name="variantId">Variant ID</param>
    public void RaisePostBackEvent(string eventArgument, string uniqueCode, int variantId)
    {
        // Check permissions
        if (!CheckPermissions("Manage") ||
            stopProcessing)
        {
            return;
        }

        // Get the argument
        string arg = eventArgument.ToLowerCSafe();

        if (arg == "remove")
        {
            // Remove variant action
            int documentId = 0;

            if (VariantMode == VariantModeEnum.MVT)
            {
                // Is MVT zone => remove the MVT variant
                MVTVariantInfo variantObj = MVTVariantInfoProvider.GetMVTVariantInfo(variantId);
                if (variantObj != null)
                {
                    // Delete the variant
                    MVTVariantInfoProvider.DeleteMVTVariantInfo(variantObj);
                    documentId = variantObj.MVTVariantDocumentID;
                }
            }
            else if (VariantMode == VariantModeEnum.ContentPersonalization)
            {
                // Is Content personalization zone => remove the Content personalization variant
                ContentPersonalizationVariantInfo variantObj = ContentPersonalizationVariantInfoProvider.GetContentPersonalizationVariant(variantId);
                if (variantObj != null)
                {
                    // Delete the variant
                    ContentPersonalizationVariantInfoProvider.DeleteContentPersonalizationVariant(variantObj);
                    documentId = variantObj.VariantDocumentID;
                }
            }
            else
            {
                return;
            }

            // Log widget variant synchronization
            if (documentId > 0)
            {
                TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
                TreeNode     node = DocumentHelper.GetDocument(documentId, tree);
                DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree);
            }

            switch (SliderMode)
            {
            // Remove zone variant
            case VariantTypeEnum.Zone:
                if ((WebPartZoneControl != null) && (WebPartZoneControl.ZoneInstance != null))
                {
                    // Remove the variant from WebPartZoneControl.ZoneInstance.ZoneInstanceVariants.
                    // It is necessary to remove the variants from the PartInstanceVariants list manually because the PageLoad method has already run
                    // and the PartInstanceVariants list was populated with the old values.
                    WebPartZoneControl.RemoveVariantFromCache(variantId);
                }
                break;

            // Remove web part or widget variant
            case VariantTypeEnum.WebPart:
            case VariantTypeEnum.Widget:
                if ((WebPartControl != null) && (WebPartControl.PartInstance != null))
                {
                    // Remove the variant from WebPartControls.PartInstance.PartInstanceVariants.
                    // It is necessary to remove the variants from the PartInstanceVariants list manually because the PageLoad method has already run
                    // and the PartInstanceVariants list was populated with the old values.
                    WebPartControl.RemoveVariantFromCache(variantId);

                    // If there are no other variants present, set the VariantMode to None to allow refreshing the add variant buttons.
                    if ((WebPartControl.PartInstance.PartInstanceVariants == null) || (WebPartControl.PartInstance.PartInstanceVariants.Count == 0))
                    {
                        mVariantMode = VariantModeEnum.None;
                    }
                }
                break;

            default:
                break;
            }

            // Refresh the variant slider position => choose the last variant
            ltrScript.Text = ScriptHelper.GetScript(
                @"cpVariantSliderPositionElem = GetCPVariantSliderPositionElem();
                UpdateVariantPosition('" + uniqueCode + @"', '-1');
                SaveSlidersConfiguration();");
        }
    }
示例#3
0
    /// <summary>
    /// Handles UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of the action which should be performed</param>
    /// <param name="actionArgument">ID of the item the action should be performed with</param>
    protected void gridElem_OnAction(string actionName, object actionArgument)
    {
        if (!CheckPermissions("CMS.ContentPersonalization", PERMISSION_MODIFY))
        {
            return;
        }

        int variantId = ValidationHelper.GetInteger(actionArgument, 0);

        if (variantId > 0)
        {
            string action = actionName.ToLowerCSafe();
            switch (action)
            {
            case "delete":
            {
                // Get the instance in order to clear the cache
                ContentPersonalizationVariantInfo vi = ContentPersonalizationVariantInfoProvider.GetContentPersonalizationVariant(variantId);

                // Delete the object
                ContentPersonalizationVariantInfoProvider.DeleteContentPersonalizationVariant(variantId);
                RaiseOnAction(string.Empty, null);

                // Log widget variant synchronization
                if ((vi != null) && (vi.VariantDocumentID > 0))
                {
                    // Log synchronization
                    DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, tree);
                }
            }
            break;

            case "up":
            case "down":
            {
                // Get the instance in order to clear the cache
                ContentPersonalizationVariantInfo vi = ContentPersonalizationVariantInfoProvider.GetContentPersonalizationVariant(variantId);

                // Use try/catch due to license check
                try
                {
                    if (action == "up")
                    {
                        // Move up
                        ContentPersonalizationVariantInfoProvider.MoveVariantUp(variantId);
                    }
                    else
                    {
                        // Move down
                        ContentPersonalizationVariantInfoProvider.MoveVariantDown(variantId);
                    }

                    // Reload the variants in the current cached pageInfo
                    if ((Node != null) && (vi != null))
                    {
                        // Get the PageInfo of the current document
                        PageInfo pi = PageInfoProvider.GetPageInfo(CMSContext.CurrentSiteName, Node.NodeAliasPath, CMSContext.PreferredCultureCode, null, Node.NodeID, tree.CombineWithDefaultCulture);

                        // Reload the zone/web part variants when moving up/down
                        if ((pi != null) && (pi.UsedPageTemplateInfo != null) && (pi.UsedPageTemplateInfo.TemplateInstance != null))
                        {
                            // Reload web part, widget variants
                            if (vi.VariantInstanceGUID != Guid.Empty)
                            {
                                WebPartInstance webPartInstance = pi.UsedPageTemplateInfo.TemplateInstance.GetWebPart(vi.VariantInstanceGUID);
                                if (webPartInstance != null)
                                {
                                    webPartInstance.LoadVariants(true, VariantModeEnum.ContentPersonalization);
                                }
                            }
                            // Reload zone variants
                            else
                            {
                                WebPartZoneInstance zoneInstance = pi.UsedPageTemplateInfo.TemplateInstance.GetZone(vi.VariantZoneID);
                                if (zoneInstance != null)
                                {
                                    zoneInstance.LoadVariants(true, VariantModeEnum.ContentPersonalization);
                                }
                            }
                        }

                        RaiseOnAction(string.Empty, null);

                        // Log widget variant synchronization
                        if (vi.VariantDocumentID > 0)
                        {
                            // Log synchronization
                            DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, tree);
                        }
                    }
                }
                catch (Exception ex)
                {
                    lblError.Visible = true;
                    lblError.Text    = ex.Message;
                }
            }
            break;
            }
        }
    }