private string GetItemName(string itemName)
 {
     if (ItemUtil.GetItemNameError(itemName).Length > 0)
     {
         return(ItemUtil.ProposeValidItemName(itemName));
     }
     return(itemName);
 }
예제 #2
0
        /// <summary>
        /// Validate Sitecore item name
        /// </summary>
        /// <returns>
        /// true if item name is valid otherwise - false
        /// </returns>
        public bool Validate()
        {
            string errorMessage = ItemUtil.GetItemNameError(this.SitecoreField);

            if (!string.IsNullOrEmpty(errorMessage))
            {
                this.validationMark.ToolTip = Translate.Text(errorMessage);
                this.validationMark.Visible = true;
                return(false);
            }
            else
            {
                this.validationMark.Visible = false;
                return(true);
            }
        }
예제 #3
0
        /// <summary>
        /// Archives current poll to the pollItem.
        /// </summary>
        /// <param name="pollItem">The poll item.</param>
        public void ArchiveTo(Item pollItem)
        {
            //copy archive folder if exists
            foreach (Item item in InnerItem.Children)
            {
                if (item.TemplateID == PollConstants.PollArchiveTemplateID)
                {
                    item.CopyTo(pollItem, item.Name);
                    item.Delete();
                }
            }
            //or create archive folder
            if (pollItem.Children[PollConstants.PollArchiveFolderName] == null)
            {
                TemplateItem pollArhiveTemplate = PollConstants.DatabaseContext.Templates[PollConstants.PollArchiveTemplateID];
                Assert.IsNotNull(pollArhiveTemplate, "Poll archive template");

                pollItem.Add(PollConstants.PollArchiveFolderName, pollArhiveTemplate);
            }
            string itemName    = string.Format("{0} {1}", InnerItem.Name, DateTime.Today.ToShortDateString().Replace('.', ' '));
            string displayName = itemName;

            if (ItemUtil.GetItemNameError(itemName).Length > 0)
            {
                itemName = ItemUtil.ProposeValidItemName(itemName);
            }

            Item currentPollCopy = InnerItem.CopyTo(pollItem.Children[PollConstants.PollArchiveFolderName], itemName, Data.ID.NewID, false);

            if (displayName != itemName)
            {
                PollItem archivedPoll = new PollItem(currentPollCopy)
                {
                    DisplayName = displayName
                };
            }

            //copy all poll options
            foreach (Item item in InnerItem.Children)
            {
                item.CopyTo(currentPollCopy, item.Name);
                item.Delete();
            }
            InnerItem.Delete();
        }
예제 #4
0
        public void RunInsertPipeline(ClientPipelineArgs args)
        {
            if (!args.IsPostBack)
            {
                Sitecore.Context.ClientPage.ClientResponse.Input("Enter a name for the new variant: ", string.Empty);
                args.WaitForPostBack();
            }
            else
            {
                if (!args.HasResult || args.Result == null)
                {
                    return;
                }

                //verify valid name
                string nameError = ItemUtil.GetItemNameError(args.Result);
                if (!string.IsNullOrEmpty(nameError))
                {
                    SheerResponse.Alert(nameError, new string[0]);
                    return;
                }

                string newItemName   = args.Result;
                string currentItemId = args.Parameters["currentid"];

                Item currentItem = Sitecore.Context.ContentDatabase.GetItem(currentItemId);
                if (currentItem.IsNull())
                {
                    return;
                }

                MultiVariantProcessor processor           = new MultiVariantProcessor();
                IMultiVariantMapping  multiVariantMapping = processor.GetMapping(currentItem.TemplateID.ToString(), Sitecore.Context.ContentDatabase);
                if (multiVariantMapping == null)
                {
                    return;
                }

                //create a new item to be used as variant
                multiVariantMapping.CreateVariantItem(currentItem, newItemName);
            }
        }