Пример #1
0
    /// <summary>
    /// Validates the form data. Checks the code name format and if the code name is unique.
    /// </summary>
    public bool ValidateData()
    {
        // Check the required fields for emptiness
        bool isValid = EditForm.ValidateData();

        if (isValid)
        {
            if ((EditForm.EditedObject == null) || (EditForm.ParentObject == null))
            {
                UIFormControl.ShowError(GetString("general.saveerror"));
                return(false);
            }

            // Create a temporary variant object in order to check the code name format rules and uniqueness
            ContentPersonalizationVariantInfo variant = new ContentPersonalizationVariantInfo();
            variant.VariantName           = VariantCodeName;
            variant.VariantID             = EditForm.EditedObject.GetIntegerValue("VariantID", 0);
            variant.VariantPageTemplateID = EditForm.ParentObject.GetIntegerValue("PageTemplateID", 0);

            // Validate the codename format
            if (!ValidationHelper.IsCodeName(VariantCodeName))
            {
                isValid = false;
                UIFormControl.ShowError(String.Format(GetString("general.codenamenotvalid"), VariantCodeName));
            }
            // Check if the code name already exists
            else if (!variant.CheckUniqueCodeName())
            {
                isValid = false;
                UIFormControl.ShowError(String.Format(GetString("general.codenamenotunique"), VariantCodeName));
            }
        }

        return(isValid);
    }
Пример #2
0
    /// <summary>
    /// Handles the OnAfterSave event of the EditForm control.
    /// </summary>
    protected void EditForm_OnAfterSave(object sender, EventArgs e)
    {
        if (UIFormControl.EditedObject != null)
        {
            // Clear cache
            CacheHelper.TouchKey("om.personalizationvariant|bytemplateid|" + (UIFormControl.EditedObject as ContentPersonalizationVariantInfo).VariantPageTemplateID);

            // Log widget variant synchronization
            ContentPersonalizationVariantInfo variantInfo = (ContentPersonalizationVariantInfo)UIFormControl.EditedObject;
            if (variantInfo.VariantDocumentID > 0)
            {
                // Log synchronization
                TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
                TreeNode     node = tree.SelectSingleDocument(variantInfo.VariantDocumentID);
                DocumentSynchronizationHelper.LogDocumentChange(node, TaskTypeEnum.UpdateDocument, tree);
            }
        }
    }
Пример #3
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();");
        }
    }
Пример #4
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;
            }
        }
    }
Пример #5
0
    /// <summary>
    /// Validates the form data. Checks the code name format and if the code name is unique.
    /// </summary>
    public bool ValidateData()
    {
        // Check the required fields for emptiness
        bool isValid = EditForm.ValidateData();

        if (isValid)
        {
            if ((EditForm.EditedObject == null) || (EditForm.ParentObject == null))
            {
                UIFormControl.ErrorLabel.Text = GetString("general.saveerror");
                return false;
            }

            string codeName = ValidationHelper.GetString(((FormEngineUserControl)UIFormControl.FieldControls["VariantName"]).Value, string.Empty);

            // Create a temporary varaint object in order to check the code name format rules and uniqueness
            ContentPersonalizationVariantInfo variant = new ContentPersonalizationVariantInfo();
            variant.VariantName = codeName;
            variant.VariantID = EditForm.EditedObject.GetIntegerValue("VariantID", 0);
            variant.VariantPageTemplateID = EditForm.ParentObject.GetIntegerValue("PageTemplateID", 0);

            // Validate the codename format
            if (!ValidationHelper.IsCodeName(codeName))
            {
                isValid = false;
                UIFormControl.ErrorLabel.Text = String.Format(GetString("general.codenamenotvalid"), codeName);
            }
            // Check if the code name already exists
            else if (!variant.CheckUniqueCodeName())
            {
                isValid = false;
                UIFormControl.ErrorLabel.Text = String.Format(GetString("general.codenamenotunique"), codeName);
            }
        }

        return isValid;
    }
Пример #6
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;
            }
        }
    }