// Explicit predicate delegate.
 private static bool FindLinkPredicate(GeneralLinkItem item, string id)
 {
     if (item.Id == id)
     {
         return(true);
     }
     return(false);
 }
        /// <summary>
        /// Pipeline for setting the link text
        /// </summary>
        /// <param name="args"></param>
        protected void SetLinkTextPipeline(ClientPipelineArgs args)
        {
            if (!args.IsPostBack)
            {
                Sitecore.Context.ClientPage.ClientResponse.Input("Enter a name: ", string.Empty);
                args.WaitForPostBack();
            }
            else
            {
                if (!args.HasResult || args.Result == null)
                {
                    return;
                }

                GeneralLinkItem selectedLink = XmlUtil.XmlDeserializeFromString <GeneralLinkItem>(args.Parameters["link"]);
                if (selectedLink == null)
                {
                    return;
                }

                int i = 0;
                while (i <= LinkItems.Count)
                {
                    GeneralLinkItem linkItem = LinkItems[i];
                    if (linkItem.LinkId == selectedLink.LinkId)
                    {
                        linkItem.LinkText = args.Result;
                        LinkItems[i]      = linkItem;

                        //update new field value
                        Value = string.Format("<links>{0}</links>", LinkItems.Aggregate(string.Empty, (current, link) => current + XmlUtil.XmlSerializeToString(link)));
                        SetModified();
                        break;
                    }
                    i++;
                }

                //set new value
                Sitecore.Context.ClientPage.ClientResponse.SetAttribute(ID + "_Value", "value", Value);

                //set new display
                Sitecore.Context.ClientPage.ClientResponse.SetInnerHtml(ID + "_SelectedItems", RenderItems(LinkItems));

                SheerResponse.Eval("scContent.startValidators()");
            }
        }
        protected string RenderItem(GeneralLinkItem linkItem)
        {
            GeneralLinksListItem listItem = new GeneralLinksListItem();
            bool useFieldGutter           = false;

            listItem.ShowAddRemoveButton = true;
            listItem.ButtonClick         = string.Format("FieldSuite.Fields.GeneralLinks.RemoveItem(this, '{0}');", this.ID);
            listItem.ItemClick           = "FieldSuite.Fields.SelectItem(this);";
            listItem.SelectedClass       = "velirFieldSelected";
            listItem.ReadOnly            = this.ReadOnly;
            listItem.Text = linkItem.LinkText;

            listItem.HoverText = linkItem.Url;
            if (!string.IsNullOrEmpty(linkItem.Id) && Sitecore.Data.ID.IsID(linkItem.Id))
            {
                Database db = Sitecore.Data.Database.GetDatabase("master");
                if (db != null)
                {
                    Item item = db.GetItem(linkItem.Id);
                    if (item.IsNotNull())
                    {
                        listItem.HoverText = item.Paths.FullPath;
                        useFieldGutter     = true;

                        //for performance reason limit field gutter
                        IFieldGutterProcessor fieldGutterProcessor = FieldGutterProcessorFactory.GetProcessor();
                        if (fieldGutterProcessor != null)
                        {
                            Int32 maxCount = fieldGutterProcessor.MaxCount;
                            if (maxCount != 0 && RenderItemCount <= maxCount)
                            {
                                RenderItemCount++;
                            }
                        }
                    }
                }
            }

            return(listItem.RenderGeneralLink(linkItem, this.ID, useFieldGutter));
        }
示例#4
0
        /// <summary>
        /// Renders the list item as Html
        /// </summary>
        /// <param name="linkItem"></param>
        /// <param name="fieldId"></param>
        /// <param name="useFieldGutter"></param>
        /// <returns></returns>
        public virtual string RenderGeneralLink(GeneralLinkItem linkItem, string fieldId, bool useFieldGutter)
        {
            //disable items if the form is read only)
            if (ReadOnly)
            {
                ItemClick   = string.Empty;
                ButtonClick = string.Empty;
            }

            string templateName = string.Empty;
            string icon         = string.Empty;
            Item   item         = null;

            if (!string.IsNullOrEmpty(linkItem.Id) && ID.IsID(linkItem.Id))
            {
                Database db = Database.GetDatabase("master");
                if (db != null)
                {
                    item = db.GetItem(linkItem.Id);
                    if (item.IsNotNull())
                    {
                        icon = item.Appearance.Icon;

                        TemplateItem template = item.Template;
                        if (!string.IsNullOrEmpty(template.Name))
                        {
                            templateName = template.Name;
                        }
                    }
                }
            }

            //external link
            if (linkItem.LinkType == GeneralLinkItem.ExternalLinkType)
            {
                templateName = GeneralLinkItem.ExternalLinkType;
                icon         = GeneralLinkItem.ExternalLinkIcon;
            }

            //javascript link
            if (linkItem.LinkType == GeneralLinkItem.JavascriptLinkType)
            {
                templateName = GeneralLinkItem.JavascriptLinkType;
                icon         = GeneralLinkItem.JavascriptLinkIcon;
            }

            //mail link
            if (linkItem.LinkType == GeneralLinkItem.MailLinkType)
            {
                templateName = GeneralLinkItem.MailLinkType;
                icon         = GeneralLinkItem.MailLinkIcon;
            }

            //anchor link
            if (linkItem.LinkType == GeneralLinkItem.AnchorLinkType)
            {
                templateName = GeneralLinkItem.AnchorLinkType;
                icon         = GeneralLinkItem.AnchorLinkIcon;
            }

            string sitecoreId = string.Empty;

            if (linkItem.LinkType == GeneralLinkItem.InternalLinkType || linkItem.LinkType == GeneralLinkItem.MediaLinkType)
            {
                sitecoreId = linkItem.Id;
            }

            string fieldGutterHtml = string.Format("<div class=\"fieldGutter\">{0}</div>", Images.GetSpacer(16, 16));

            if (useFieldGutter)
            {
                if (item.IsNotNull())
                {
                    IFieldGutterProcessor fieldGutterProcessor = FieldGutterProcessorFactory.GetProcessor();
                    if (fieldGutterProcessor != null)
                    {
                        string html = fieldGutterProcessor.Process(new FieldGutterArgs(item, fieldId));
                        if (!string.IsNullOrEmpty(html))
                        {
                            fieldGutterHtml = html;
                        }
                    }
                }
            }

            return(string.Format(HtmlTemplate,
                                 linkItem.LinkId,
                                 fieldGutterHtml,
                                 fieldId,
                                 AddRemoveHtml(ButtonClick, Images.GetSpacer(16, 16)),
                                 templateName,
                                 Images.GetImage(icon, 0x10, 0x10, "absmiddle", "0px 4px 0px 0px", templateName),
                                 Text,
                                 HoverText,
                                 ItemClick,
                                 SelectedClass,
                                 sitecoreId));
        }
        protected void InsertLink(ClientPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            if (args.IsPostBack)
            {
                if (!string.IsNullOrEmpty(args.Result) && (args.Result != "undefined"))
                {
                    GeneralLinkItem selectedLink = null;
                    if (args.Parameters["link"] != null)
                    {
                        selectedLink = XmlUtil.XmlDeserializeFromString <GeneralLinkItem>(args.Parameters["link"]);
                    }

                    GeneralLinkItem returnedLink = XmlUtil.XmlDeserializeFromString <GeneralLinkItem>(args.Result);
                    string          rawValue     = LinkItems.Aggregate(string.Empty, (current, link) => current + XmlUtil.XmlSerializeToString(link));

                    if (selectedLink == null)
                    {
                        //item doesn't exist, add to values
                        if (string.IsNullOrEmpty(returnedLink.LinkId))
                        {
                            returnedLink.LinkId = Guid.NewGuid().ToString();
                        }
                        rawValue += XmlUtil.XmlSerializeToString(returnedLink);
                        LinkItems.Add(returnedLink);
                    }
                    else
                    {
                        //item exists, set in values
                        int i = 0;
                        while (i <= LinkItems.Count)
                        {
                            GeneralLinkItem linkItem = LinkItems[i];
                            if (linkItem.LinkId == selectedLink.LinkId)
                            {
                                returnedLink.LinkId = selectedLink.LinkId;
                                LinkItems[i]        = returnedLink;
                                rawValue            = LinkItems.Aggregate(string.Empty, (current, link) => current + XmlUtil.XmlSerializeToString(link));
                                break;
                            }
                            i++;
                        }
                    }

                    Value = string.Format("<links>{0}</links>", rawValue);

                    SetModified();

                    //set new value
                    Sitecore.Context.ClientPage.ClientResponse.SetAttribute(ID + "_Value", "value", Value);

                    //set new display
                    Sitecore.Context.ClientPage.ClientResponse.SetInnerHtml(ID + "_SelectedItems", RenderItems(LinkItems));

                    SheerResponse.Eval("scContent.startValidators()");
                }
            }
            else
            {
                var str = new UrlString(args.Parameters["url"]);

                if (args.Parameters["link"] != null && !string.IsNullOrEmpty(args.Parameters["link"]))
                {
                    str.Append("va", args.Parameters["link"]);
                }

                str.Append("ro", Source);
                if ((UIUtil.IsIE() && (GetIEEngineBasedVersion() == 9)) && (args.Parameters["umwn"] == "1"))
                {
                    ShowIEModelessDialog(str.ToString(), 500, 600);
                }
                else
                {
                    Sitecore.Context.ClientPage.ClientResponse.ShowModalDialog(str.ToString(), true);
                }
                args.WaitForPostBack();
            }
        }