Example #1
0
        public string Render()
        {
            interfaceScripts.Sort(RankedObject.SortByRank);
            JavaScriptCollection jsc = new JavaScriptCollection();
            int scrnum = 0;

            foreach (RankedString str in interfaceScripts)
            {
                jsc.Add("sprocket-admin-script-" + scrnum++, str.Render());
            }
            headSections.Add(new RankedString(jsc.CreateScriptTags(), 1000));

            menuLinks.Sort(RankedObject.SortByRank);
            footerLinks.Sort(RankedObject.SortByRank);
            contentSections.Sort(RankedObject.SortByRank);
            headSections.Sort(RankedObject.SortByRank);
            bodyOnLoadScripts.Sort(RankedObject.SortByRank);

            StringBuilder menu = new StringBuilder();

            foreach (AdminMenuLink link in menuLinks)
            {
                menu.AppendFormat("<div id=\"main-menu\">{0}</div>", link.Render());
            }

            menuSections.Add(new RankedString(menu.ToString(), 0));
            menuSections.Sort(RankedObject.SortByRank);

            StringBuilder footer = new StringBuilder();

            foreach (AdminMenuLink link in footerLinks)
            {
                if (footer.Length > 0)
                {
                    footer.Append(" | ");
                }
                footer.Append(link.Render());
            }

            StringBuilder content = new StringBuilder();

            foreach (RankedString section in contentSections)
            {
                content.Append(section.Render());
            }

            StringBuilder head = new StringBuilder();

            foreach (RankedString section in headSections)
            {
                head.Append(section.Render());
            }

            StringBuilder left = new StringBuilder();

            foreach (RankedString section in menuSections)
            {
                left.Append(section.Render());
            }

            StringBuilder onLoad = new StringBuilder();

            foreach (RankedString script in bodyOnLoadScripts)
            {
                string scr = script.Render();
                if (!scr.Trim().EndsWith(";"))
                {
                    scr += ";";
                }
                onLoad.Append(scr);
            }

            string html = WebUtility.CacheTextFile("resources/admin/admin.htm");

            html = html.Replace("{website-name}", websiteName);
            html = html.Replace("{head}", head.ToString());
            html = html.Replace("//{onload}", onLoad.ToString());
            html = html.Replace("{main-menu}", left.ToString());
            html = html.Replace("{main-content}", content.ToString());
            html = html.Replace("{section-heading}", contentHeading);
            html = html.Replace("{footer}", footer.ToString());
            html = html.Replace("{basepath}", WebUtility.BasePath);
            return(html);
        }
Example #2
0
        public KeyValuePair <string, object>[] GetScriptVariables()
        {
            interfaceScripts.Sort(RankedObject.SortByRank);
            JavaScriptCollection jsc = new JavaScriptCollection();
            int scrnum = 0;

            foreach (AdminSection str in interfaceScripts)
            {
                jsc.Add("sprocket-admin-script-" + scrnum++, str.Render());
            }
            headSections.Add(new AdminSection(jsc.CreateScriptTags(), ObjectRank.Last));

            menuLinks.Sort(RankedObject.SortByRank);
            footerLinks.Sort(RankedObject.SortByRank);
            preContentSections.Sort(RankedObject.SortByRank);
            subContentSections.Sort(RankedObject.SortByRank);
            headSections.Sort(RankedObject.SortByRank);
            bodyOnLoadScripts.Sort(RankedObject.SortByRank);

            StringBuilder menu = new StringBuilder();

            foreach (AdminMenuLink link in menuLinks)
            {
                menu.AppendFormat("<div class=\"main-menu-link\">{0}</div>", link.Render());
            }

            menuSections.Add(new AdminSection(menu.ToString(), ObjectRank.Late));
            menuSections.Sort(RankedObject.SortByRank);

            StringBuilder footer = new StringBuilder();

            foreach (AdminMenuLink link in footerLinks)
            {
                if (footer.Length > 0)
                {
                    footer.Append(" | ");
                }
                footer.Append(link.Render());
            }

            StringBuilder preContent = new StringBuilder();

            foreach (AdminSection section in preContentSections)
            {
                preContent.Append(section.Render());
            }

            StringBuilder subContent = new StringBuilder();

            foreach (AdminSection section in subContentSections)
            {
                subContent.Append(section.Render());
            }

            StringBuilder head = new StringBuilder();

            foreach (AdminSection section in headSections)
            {
                head.Append(section.Render());
            }

            StringBuilder left = new StringBuilder();

            foreach (AdminSection section in menuSections)
            {
                left.Append(section.Render());
            }

            StringBuilder onLoad = new StringBuilder();

            foreach (AdminSection script in bodyOnLoadScripts)
            {
                string scr = script.Render();
                if (!scr.Trim().EndsWith(";"))
                {
                    scr += ";";
                }
                onLoad.Append(scr);
            }

            KeyValuePair <string, object>[] vars = new KeyValuePair <string, object> [7];
            vars[0] = new KeyValuePair <string, object>("_admin_head", head.ToString());
            vars[1] = new KeyValuePair <string, object>("_admin_mainmenu", left.ToString());
            vars[2] = new KeyValuePair <string, object>("_admin_precontent", preContent.ToString());
            vars[3] = new KeyValuePair <string, object>("_admin_subcontent", subContent.ToString());
            vars[4] = new KeyValuePair <string, object>("_admin_footer", footer.ToString());
            vars[5] = new KeyValuePair <string, object>("_admin_websitename", websiteName);
            vars[6] = new KeyValuePair <string, object>("_admin_bodyonload", onLoad.ToString());
            return(vars);
        }