コード例 #1
0
        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);
        }
コード例 #2
0
 // Explicit predicate delegate.
 private static bool FindLinkPredicate(GeneralLinkItem item, string id)
 {
     if (item.Id == id)
     {
         return true;
     }
     return false;
 }
コード例 #3
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);
        }