Esempio n. 1
0
        public void Process(FilterArgs args)
        {
            //get master database
            Database database = Database.GetDatabase("master");
            if (database == null || args.ContentItem.IsNull())
            {
                args.HideCommand = false;
                return;
            }

            MultiVariantProcessor processor = new MultiVariantProcessor();
            TemplateItem templateItem = processor.GetTemplate(args.ContentItem.TemplateID.ToString(), database);

            args.HideCommand = (templateItem == null);
        }
Esempio n. 2
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);
            }
        }
        protected override void OnOK(object sender, EventArgs args)
        {
            string mediaUrl;
            string displayName;
            Assert.ArgumentNotNull(sender, "sender");
            Assert.ArgumentNotNull(args, "args");
            string linkedId = string.Empty;
            string goalId = string.Empty;

            //verify goal has been selected
            Item goalItem = rootItemDataContext.GetFolder();
            if (goalItem == null || goalItem.ID.ToString() == AnalyticsReference.System_MarketingCenter_Goals.Guid)
            {
                //reset to null to avoid setting the goal item to the goal folder
                goalItem = null;
            }

            if (this.Tabs.Active == 0)
            {
                Item selectionItem = this.InternalLinkTreeview.GetSelectionItem();
                if (selectionItem == null)
                {
                    SheerResponse.Alert("Select an item.", new string[0]);
                    return;
                }

                //use variant mapping functionality
                MultiVariantProcessor processor = new MultiVariantProcessor();
                if (processor.IsVariantTemplate(selectionItem.TemplateID.ToString()))
                {
                    SheerResponse.Alert("Select an non variant item.", new string[0]);
                    return;
                }

                displayName = selectionItem.DisplayName;
                if (selectionItem.Paths.IsMediaItem)
                {
                    mediaUrl = GetMediaUrl(selectionItem);
                }
                else
                {
                    if (!selectionItem.Paths.IsContentItem)
                    {
                        SheerResponse.Alert("Select either a content item or a media item.", new string[0]);
                        return;
                    }
                    LinkUrlOptions options = new LinkUrlOptions();
                    mediaUrl = LinkManager.GetDynamicUrl(selectionItem, options);
                    linkedId = selectionItem.ID.ToString();
                }
            }
            else
            {
                MediaItem item2 = this.MediaTreeview.GetSelectionItem();
                if (item2 == null)
                {
                    SheerResponse.Alert("Select a media item.", new string[0]);
                    return;
                }

                //use variant mapping functionality
                MultiVariantProcessor processor = new MultiVariantProcessor();
                if (processor.IsVariantTemplate(item2.InnerItem.TemplateID.ToString()))
                {
                    SheerResponse.Alert("Select an non variant item.", new string[0]);
                    return;
                }

                displayName = item2.DisplayName;
                mediaUrl = GetMediaUrl((Item)item2);
                linkedId = item2.ID.ToString();
            }
            if (this.Mode == "webedit")
            {
                SheerResponse.SetDialogValue(StringUtil.EscapeJavascriptString(mediaUrl));
                base.OnOK(sender, args);
            }
            else
            {
                string url = StringUtil.EscapeJavascriptString(mediaUrl);

                if (goalItem.IsNotNull())
                {
                    goalId = goalItem.ID.ToString();
                }

                //put querystring on for only content items, media items will be picked up within a javascript event.
                if (this.Tabs.Active == 0)
                {
                    //set default parameter key
                    string parameterKey = "sc_trk";

                    //check configuration file for parameter key
                    if (!string.IsNullOrEmpty(Sitecore.Configuration.Settings.GetSetting("Analytics.EventQueryStringKey")))
                    {
                        parameterKey = Sitecore.Configuration.Settings.GetSetting("Analytics.EventQueryStringKey");
                    }

                    //if there is a goal, assign a querystring parameter
                    //no check for existing parameters, this is because it will come across as link.aspx?_id=3D98F330EBA94EAA97C63F0D0FE1D5D8?sc_trk=SomeGoal
                    //and when the field renderer processes this it will convert it as /research?sc_trk=SomeGoal
                    string goalName = string.Empty;
                    if (goalItem.IsNotNull() && !string.IsNullOrEmpty(goalItem["Name"]))
                    {
                        goalName = string.Format("?{1}={0}", goalItem["Name"], parameterKey);
                    }

                    url = StringUtil.EscapeJavascriptString(string.Format("{0}{1}", mediaUrl, goalName));
                }

                SheerResponse.Eval("scClose(" + url + "," + StringUtil.EscapeJavascriptString(displayName) + ",'" + linkedId + "','" + goalId + "')");
            }
        }
        protected void SetContent(ClientPipelineArgs args)
        {
            Predicate<VariableValueItemStub> match = null;
            Predicate<VariableValueItemStub> predicate2 = null;
            ID id;
            string str = args.Parameters["variationid"];
            if (string.IsNullOrEmpty(str))
            {
                SheerResponse.Alert("Item not found.", new string[0]);
            }
            else
            {
                id = ShortID.DecodeID(str);
                if (args.IsPostBack)
                {
                    if (args.HasResult)
                    {
                        List<VariableValueItemStub> variableValues = VariableValues;
                        if (match == null)
                        {
                            match = v => v.Id == id;
                        }
                        VariableValueItemStub stub = variableValues.Find(match);
                        if (stub != null)
                        {
                            stub.Datasource = args.Result;
                            var output = new HtmlTextWriter(new StringWriter());
                            RenderContentControls(output, stub);
                            SheerResponse.SetOuterHtml(str + "_content", output.InnerWriter.ToString());
                            VariableValues = variableValues;
                        }
                    }
                }
                else
                {
                    if (predicate2 == null)
                    {
                        predicate2 = v => v.Id == id;
                    }
                    VariableValueItemStub stub2 = VariableValues.Find(predicate2);
                    if ((stub2 != null) && ((Rendering != null) && !string.IsNullOrEmpty(Rendering.ItemID)))
                    {
                        Item renderingItem = Client.ContentDatabase.GetItem(Rendering.ItemID);
                        if (renderingItem == null)
                        {
                            SheerResponse.Alert("Item not found.", new string[0]);
                        }
                        else
                        {
                            //get current content item
                            Item variantSourceItem = (ContextItemUri == null) ? null : Client.ContentDatabase.GetItem(ContextItemUri.ToDataUri());

                            if (variantSourceItem.IsNotNull())
                            {
                                //use variant mapping functionality to find proper source
                                MultiVariantProcessor processor = new MultiVariantProcessor();
                                IMultiVariantMapping mapping = processor.GetMapping(variantSourceItem.TemplateID.ToString(), Client.ContentDatabase);
                                if(mapping != null)
                                {
                                    //set mapping
                                    variantSourceItem = mapping.VariantSource(variantSourceItem);
                                }
                            }

                            var args3 = new GetRenderingDatasourceArgs(renderingItem);
                            args3.FallbackDatasourceRoots = new List<Item> {variantSourceItem};
                            args3.ContentLanguage = ((variantSourceItem != null) ? variantSourceItem.Language : null);
                            args3.ContextItemPath = (variantSourceItem != null) ? variantSourceItem.Paths.FullPath : string.Empty;
                            args3.ShowDialogIfDatasourceSetOnRenderingItem = true;
                            args3.CurrentDatasource = (string.IsNullOrEmpty(stub2.Datasource) ? Rendering.Datasource : stub2.Datasource);
                            GetRenderingDatasourceArgs args2 = args3;
                            CorePipeline.Run("getRenderingDatasource", args2);
                            if (string.IsNullOrEmpty(args2.DialogUrl))
                            {
                                SheerResponse.Alert("An error ocurred.", new string[0]);
                            }
                            else
                            {
                                SheerResponse.ShowModalDialog(args2.DialogUrl, "460px", "460px", string.Empty, true);
                                args.WaitForPostBack();
                            }
                        }
                    }
                }
            }
        }