Example #1
0
        public static string GetHtmlDisplay(CmsPage page, GlossaryData[] items, GlossaryPlaceholderData placeholderData, string[] charactersWithData, string letterToDisplay)
        {
            StringBuilder html = new StringBuilder();

            html.Append("<div class=\"Glossary\">" + Environment.NewLine);
            // -- output JumpLinks

            html.Append("<div class=\"JumpLinks\">");
            string        JumpLinksSeperator = " | ";
            List <string> jumpLinks          = new List <string>();

            if (placeholderData.ViewMode == GlossaryPlaceholderData.GlossaryViewMode.PagePerLetter && letterToDisplay != "")
            {
                jumpLinks.Add("<a href=\"" + page.Url + "\" title=\"view entire glossary\">[all]</a>");
            }


            char startChar   = 'A';
            char lastChar    = 'Z'; lastChar++;
            char currentChar = startChar;

            do
            {
                string link    = "";
                bool   outputA = false;

                if (StringUtils.IndexOf(charactersWithData, currentChar.ToString(), StringComparison.CurrentCultureIgnoreCase) > -1)
                {
                    outputA = true;

                    string url = "";
                    if (placeholderData.ViewMode == GlossaryPlaceholderData.GlossaryViewMode.PagePerLetter)
                    {
                        NameValueCollection pageParams = new NameValueCollection();
                        pageParams.Add("l", currentChar.ToString());
                        url = CmsContext.getUrlByPagePath(page.Path, pageParams);
                    }
                    else if (placeholderData.ViewMode == GlossaryPlaceholderData.GlossaryViewMode.SinglePageWithJumpList)
                    {
                        url = "#letter_" + currentChar.ToString();
                    }

                    link += "<a href=\"" + url + "\">";
                }
                link += currentChar.ToString();

                if (outputA)
                {
                    link += "</a>";
                }

                jumpLinks.Add(link);
                currentChar++;
            }while (currentChar != lastChar);

            string jumpLinksHtml = String.Join(JumpLinksSeperator, jumpLinks.ToArray());

            html.Append(jumpLinksHtml);
            html.Append("</div>"); // JumpLinks

            // -- output terms
            switch (placeholderData.ViewMode)
            {
            case GlossaryPlaceholderData.GlossaryViewMode.PagePerLetter:
                if (letterToDisplay == "")
                {
                    startChar = 'A';
                    lastChar  = 'Z'; lastChar++;
                }
                else
                {
                    startChar = letterToDisplay[0];
                    lastChar  = letterToDisplay[0]; lastChar++;
                }
                break;

            case GlossaryPlaceholderData.GlossaryViewMode.SinglePageWithJumpList:
                startChar = 'A';
                lastChar  = 'Z'; lastChar++;
                break;

            default:
                throw new ArgumentException("invalid GlossaryViewMode");
            } // switch viewmode


            currentChar = startChar;
            html.Append("<table class=\"glossaryitems\">");
            do
            {
                html.Append("<tr><td class=\"LetterHeading\" colspan=\"2\">");
                html.Append("<a name=\"letter_" + currentChar.ToString() + "\"></a>");
                html.Append("<h2>" + currentChar + "</h2>");
                html.Append("</td></tr>" + Environment.NewLine);

                GlossaryData[] itemsToDisplay = new GlossaryData[0];
                if (placeholderData.ViewMode == GlossaryPlaceholderData.GlossaryViewMode.SinglePageWithJumpList || letterToDisplay == "")
                {
                    itemsToDisplay = GlossaryData.getItemsStartingWithChar(items, currentChar);
                }
                else if (placeholderData.ViewMode == GlossaryPlaceholderData.GlossaryViewMode.PagePerLetter)
                {
                    itemsToDisplay = items;
                }


                bool oddRow = true;
                foreach (GlossaryData item in itemsToDisplay)
                {
                    string cssClass = "even";
                    if (oddRow)
                    {
                        cssClass = "odd";
                    }
                    html.Append("<tr class=\"" + cssClass + "\">");
                    html.Append("<td class=\"word " + cssClass + "\">" + item.word + "</td>");
                    html.Append("<td class=\"description " + cssClass + "\">" + item.description + "</td>");
                    html.Append("</tr>" + Environment.NewLine);
                    oddRow = !oddRow;
                } // foreach glossarydata item

                currentChar++;
            } while (currentChar != lastChar);

            html.Append("</table>");
            html.Append("</div>"); // glossary

            return(html.ToString());
        }