/// <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) { int variantId = ValidationHelper.GetInteger(actionArgument, 0); if (variantId > 0) { switch (actionName.ToLower()) { case "edit": this.SelectedItemID = variantId; this.RaiseOnEdit(); break; case "delete": if (CheckPermissions("CMS.ABTest", CMSAdminControl.PERMISSION_MANAGE)) { // Delete the object ABVariantInfoProvider.DeleteABVariantInfo(variantId); this.RaiseOnDelete(); // Reload data gridElem.ReloadData(); } break; } } }
/// <summary> // Processes the form - saves the data. /// </summary> private void Process() { // Check manage permissions if (!CheckPermissions("CMS.ABTest", PERMISSION_MANAGE)) { return; } // Validate the form if (Validate()) { // Ensure the info object if (VariantObj == null) { VariantObj = new ABVariantInfo(); VariantObj.ABVariantTestID = TestID; VariantObj.ABVariantSiteID = CMSContext.CurrentSiteID; } // Initialize object VariantObj.ABVariantDisplayName = txtABVariantDisplayName.Text.Trim(); VariantObj.ABVariantName = txtABVariantName.Text.Trim(); VariantObj.ABVariantPath = ucPath.Value.ToString().Trim(); // Save object data to database ABVariantInfoProvider.SetABVariantInfo(VariantObj); ItemID = VariantObj.ABVariantID; RaiseOnSaved(); // Set the info message ShowChangesSaved(); } }
/// <summary> // Processes the form - saves the data. /// </summary> private void Process() { // Check manage permissions if (!CheckPermissions("CMS.ABTest", CMSAdminControl.PERMISSION_MANAGE)) { return; } // Validate the form if (Validate()) { // Ensure the info object if (this.VariantObj == null) { this.VariantObj = new ABVariantInfo(); this.VariantObj.ABVariantTestID = TestID; this.VariantObj.ABVariantSiteID = CMSContext.CurrentSiteID; } // Initialize object this.VariantObj.ABVariantDisplayName = this.txtABVariantDisplayName.Text.Trim(); this.VariantObj.ABVariantName = this.txtABVariantName.Text.Trim(); this.VariantObj.ABVariantPath = this.ucPath.Value.ToString().Trim(); // Save object data to database ABVariantInfoProvider.SetABVariantInfo(this.VariantObj); this.ItemID = this.VariantObj.ABVariantID; this.RaiseOnSaved(); // Set the info message this.lblInfo.Text = GetString("general.changessaved"); } }
/// <summary> /// Creates new AB variant if AB test filled in. /// </summary> /// <param name="newDocument">Newly created document</param> /// <returns>True if new variant is successfully created or if AB test is not defined.</returns> private bool CreateABVariant(TreeNode newDocument) { // If ABTest selected - create new variant int abTestID = ValidationHelper.GetInteger(ucABTestSelector.Value, 0); if (abTestID <= 0) { return(true); } // If no test found, handle it as no test was specified ABTestInfo abTest = ABTestInfoProvider.GetABTestInfo(abTestID); if (abTest == null) { return(true); } string defaultCodeName = TextHelper.LimitLength(ValidationHelper.GetCodeName(newDocument.NodeAlias), 45, String.Empty); string codeName = defaultCodeName; ABVariantInfo info = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, SiteContext.CurrentSiteName); // Find non existing variant code name int index = 0; while (info != null) { index++; codeName = defaultCodeName + "-" + index; info = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, SiteContext.CurrentSiteName); } // Save AB Variant ABVariantInfo variantInfo = new ABVariantInfo(); variantInfo.ABVariantTestID = abTestID; variantInfo.ABVariantPath = newDocument.NodeAliasPath; variantInfo.ABVariantName = codeName; variantInfo.ABVariantDisplayName = newDocument.NodeAlias; variantInfo.ABVariantSiteID = SiteContext.CurrentSiteID; try { ABVariantInfoProvider.SetABVariantInfo(variantInfo); } catch (InfoObjectException ex) { newDocument.Delete(true, true); ShowError(ex.Message); return(false); } return(true); }
/// <summary> /// Creates a new AB variant that should be created by default to given AB test /// </summary> private void CreateDefaultVariant(ABTestInfo info) { // Create instance of AB variant ABVariantInfo variant = new ABVariantInfo(); // Set properties variant.ABVariantPath = info.ABTestOriginalPage; variant.ABVariantTestID = info.ABTestID; variant.ABVariantDisplayName = GetString("abtesting.originalvariantdisplayname"); variant.ABVariantName = "Original"; variant.ABVariantSiteID = info.ABTestSiteID; // Save to the storage ABVariantInfoProvider.SetABVariantInfo(variant); }
/// <summary> /// Validates the form. If validation succeeds returns true, otherwise returns false. /// </summary> private bool Validate() { // Validate required fields string errorMessage = new Validator() .NotEmpty(txtABVariantDisplayName.Text.Trim(), rfvABVariantDisplayName.ErrorMessage) .NotEmpty(txtABVariantName.Text.Trim(), rfvABVariantName.ErrorMessage) .IsCodeName(txtABVariantName.Text.Trim(), GetString("general.invalidcodename")).Result; string abTestName = string.Empty; string siteName = CMSContext.CurrentSiteName; // Get AB test info object ABTestInfo abti = ABTestInfoProvider.GetABTestInfo(TestID); if (abti != null) { abTestName = abti.ABTestName; } // Test unique codename ABVariantInfo info = ABVariantInfoProvider.GetABVariantInfo(txtABVariantName.Text.Trim(), abTestName, siteName); if ((info != null) && ((VariantObj == null) || (info.ABVariantID != VariantObj.ABVariantID))) { errorMessage = GetString("general.codenameexists"); } if (String.IsNullOrEmpty(ucPath.Value.ToString())) { errorMessage = GetString("abtesting.entertestpage"); } // Set the error message if (!String.IsNullOrEmpty(errorMessage)) { ShowError(errorMessage); return(false); } return(true); }
/// <summary> /// Checks if page is not already assigned. /// </summary> /// <param name="filledVariantPath">Variant path filled in form</param> private void CheckDoublePageAssignment(string filledVariantPath) { string originalVariantPath = ValidationHelper.GetString(ABVariant.GetOriginalValue("ABVariantPath"), ""); //Check if variantPath is changed if (originalVariantPath != filledVariantPath) { var condition = new WhereCondition() .WhereEquals("ABVariantTestID", ABTest.ABTestID) .WhereEquals("ABVariantPath", filledVariantPath); if (ABVariant.ABVariantID > 0) { condition.Where("ABVariantID", QueryOperator.NotEquals, ABVariant.ABVariantID); } var variants = ABVariantInfoProvider.GetVariants().Where(condition).TopN(1); if (variants.Any()) { ShowError(GetString("abtesting.variantpath.alreadyassigned")); form.StopProcessing = true; } } }
/// <summary> /// Handles Unigrid's OnAction event. /// </summary> /// <param name="actionName">Name of the action</param> /// <param name="actionArgument">Action argument</param> protected void gridElem_OnAction(string actionName, object actionArgument) { switch (actionName) { case "delete": int variantID = ValidationHelper.GetInteger(actionArgument, 0); if (variantID > 0) { var variant = ABVariantInfoProvider.GetABVariantInfo(variantID); if (variant != null) { if (variant.ABVariantPath != ABTest.ABTestOriginalPage) { ABVariantInfoProvider.DeleteABVariantInfo(variantID); } else { ShowError(GetString("abtesting.deleteoriginalvariant")); } } } break; } }
/// <summary> /// Creates document. /// </summary> /// <param name="createAnother">If false user will be redirected to created document</param> public int Save(bool createAnother) { // Validate input data string message = new Validator().NotEmpty(txtDocumentName.Text.Trim(), GetString("om.enterdocumentname")).Result; if (message == String.Empty) { if (node != null) { // Select parent node TreeNode parent = tree.SelectSingleNode(CMSContext.CurrentSiteName, ucPath.Value.ToString(), TreeProvider.ALL_CULTURES, false, null, false); if (parent != null) { // Check security if (!CMSContext.CurrentUser.IsAuthorizedToCreateNewDocument(parent.NodeID, node.NodeClassName)) { RedirectToAccessDenied(GetString("cmsdesk.notauthorizedtocreatedocument")); return(0); } TreeNode newNode = ProcessAction(node, parent, "copynode", false, true, true); if (newNode != null) { newNode.SetValue("DocumentMenuItemHideInNavigation", !chkShowInNavigation.Checked); newNode.SetValue("DocumentShowInSiteMap", chkShowInSiteMap.Checked); newNode.SetValue("DocumentSearchExcluded", chkExcludeFromSearch.Checked); // Limit length to 100 characters string nodeAlias = TextHelper.LimitLength(txtDocumentName.Text.Trim(), 100, String.Empty); newNode.NodeAlias = nodeAlias; newNode.DocumentName = nodeAlias; // Update menu item name newNode.SetDocumentNameSource(nodeAlias); newNode.Update(); // If ABTest selected - create new variant int abTestID = ValidationHelper.GetInteger(ucABTestSelector.Value, 0); if (abTestID != 0) { ABTestInfo abTest = ABTestInfoProvider.GetABTestInfo(abTestID); if (abTest != null) { string defaultCodeName = TextHelper.LimitLength(ValidationHelper.GetCodeName(newNode.GetDocumentName()), 45, String.Empty); string codeName = defaultCodeName; ABVariantInfo info = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, CMSContext.CurrentSiteName); // Find non existing variant code name int index = 0; while (info != null) { index++; codeName = defaultCodeName + "-" + index; info = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, CMSContext.CurrentSiteName); } // Save AB Variant ABVariantInfo variantInfo = new ABVariantInfo(); variantInfo.ABVariantTestID = abTestID; variantInfo.ABVariantPath = newNode.NodeAliasPath; variantInfo.ABVariantName = codeName; variantInfo.ABVariantDisplayName = newNode.GetDocumentName(); variantInfo.ABVariantSiteID = CMSContext.CurrentSiteID; ABVariantInfoProvider.SetABVariantInfo(variantInfo); } } // Get the page mode if (CMSContext.ViewMode != ViewModeEnum.EditLive) { CMSContext.ViewMode = ViewModeEnum.EditForm; } txtDocumentName.Text = String.Empty; return(newNode.NodeID); } } else { message = GetString("om.pathdoesnotexists"); } } } if (message != String.Empty) { lblError.Visible = true; lblError.Text = message; } return(0); }
/// <summary> // Processes the form - saves the data. /// </summary> private void Process() { // Check manage permissions if (!CheckPermissions("CMS.ABTest", CMSAdminControl.PERMISSION_MANAGE)) { return; } // Validate the form if (Validate()) { bool isNew = false; // Ensure the info object if (this.AbTestObj == null) { this.AbTestObj = new ABTestInfo(); if (AliasPath != String.Empty) { this.AbTestObj.ABTestOriginalPage = AliasPath; } isNew = true; } // Initialize object String newName = this.txtABTestName.Text.Trim(); this.AbTestObj.ABTestDisplayName = this.txtABTestDisplayName.Text.Trim(); this.AbTestObj.ABTestDescription = this.txtABTestDescription.Text.Trim(); this.AbTestObj.ABTestMaxConversions = ValidationHelper.GetInteger(this.txtABTestMaxConversions.Text.Trim(), 0); this.AbTestObj.ABTestOpenFrom = this.dtpABTestOpenFrom.SelectedDateTime; this.AbTestObj.ABTestOpenTo = this.dtpABTestOpenTo.SelectedDateTime; this.AbTestObj.ABTestCulture = this.ucCultureSelector.Value.ToString(); this.AbTestObj.ABTestEnabled = this.chkABTestEnabled.Checked; this.AbTestObj.ABTestSiteID = CMSContext.CurrentSiteID; // Name has changed. Change analytics statistics data for existing object if ((this.AbTestObj.ABTestID != 0) && (this.AbTestObj.ABTestName != newName)) { ABTestInfoProvider.RenameABTestStatistics(this.AbTestObj.ABTestName, newName, CMSContext.CurrentSiteID); } this.AbTestObj.ABTestName = newName; // Store conversion type TargetConversionType conversionType = TargetConversionType.Total; if (radAnyVariant.Checked) { conversionType = TargetConversionType.AnyVariant; } this.AbTestObj.ABTestTargetConversionType = conversionType; if (ShowAliasPath) { this.AbTestObj.ABTestOriginalPage = this.ucPath.Value.ToString().Trim(); } // Save object data to database ABTestInfoProvider.SetABTestInfo(this.AbTestObj); this.ItemID = this.AbTestObj.ABTestID; // For new A/B test create default variant if (isNew) { // Create instance of ab variant ABVariantInfo variant = new ABVariantInfo(); // Set properties variant.ABVariantPath = this.AbTestObj.ABTestOriginalPage; variant.ABVariantTestID = this.AbTestObj.ABTestID; variant.ABVariantDisplayName = this.AbTestObj.ABTestDisplayName + " " + GetString("om.variant"); variant.ABVariantName = this.AbTestObj.ABTestName; variant.ABVariantSiteID = this.AbTestObj.ABTestSiteID; // Save to the storage ABVariantInfoProvider.SetABVariantInfo(variant); } this.RaiseOnSaved(); // Set the info message this.lblInfo.Text = GetString("general.changessaved"); } }