Пример #1
0
        public virtual XElement Element()
        {
            XNamespace ns = ContentList.DefaultNamespace;

            var element = new XElement(ns + TAG_NAME,
                new XAttribute(NAME, this.Name));

            if (!string.IsNullOrEmpty(this.ViewTemplate))
                element.Add(new XAttribute(TMPL, this.ViewTemplate));

            if (this.AllowPaging)
            {
                var pagingElement = new XElement(ns + PAGING, new XAttribute(ALLOW, this.AllowPaging));

                if (this.PageIndex > 0)
                    pagingElement.Add(new XAttribute(INDEX, this.PageIndex));

                if (this.PageSize > 0)
                    pagingElement.Add(new XAttribute(SIZE, this.PageSize));

                element.Add(pagingElement);
            }

            if (!string.IsNullOrEmpty(Roles))
                element.Add(new XAttribute(ACCESS_ROLES, Roles));

            if (this.IsDefault)
                element.Add(new XAttribute(DEFAULT, true));

            if (this.IsHierarchy)
                element.Add(new XAttribute(HIERARCHY, true));

            if (this.HideToolbar)
                element.Add(new XAttribute(HIDE_TOOLBAR, true));

            if (!string.IsNullOrEmpty(this.Filter))
                element.Add(new XAttribute(FILTER, this.Filter));

            if (!string.IsNullOrEmpty(this.Sort))
                element.Add(new XAttribute(SORT, Sort));

            //if (!string.IsNullOrEmpty(this.Style))
            //    element.Add(new XAttribute(STYLE, this.Style));

            if (this.NoPage)
                element.Add(new XElement(ns + NOPAGE, this.NoPage));

            if (!string.IsNullOrEmpty(this.Title))
                element.Add(new XElement(ns + TITLE, new XCData(this.Title)));

            if (!string.IsNullOrEmpty(this.Description))
                element.Add(new XElement(ns + DESC, new XCData(this.Title)));

            //if (!string.IsNullOrEmpty(this.RowTemplate))
            //    element.Add(new XElement(ROW_TMPL, new XCData(this.RowTemplate)));

            if (this.AllowAnonymous)
                element.Add(new XAttribute(ANONYMOUS, true));

            if (!string.IsNullOrEmpty(this.BodyTemplateXml))
            {
                var tmpl = new ContentTemplate(this.BodyTemplateXml);
                element.Add(tmpl.Element());
            }

            if (!string.IsNullOrEmpty(this.EmptyTemplateXml))
                element.Add(new XElement(ns + EMPTY_PATTERN, XElement.Parse(this.EmptyTemplateXml)));

            if (!string.IsNullOrEmpty(this.StyleSheetsXml))
            {
                var stylesEl = XElement.Parse(this.StyleSheetsXml);
                if (stylesEl != null && stylesEl.HasElements)
                {
                    var _styles = stylesEl.Elements();
                    foreach (var s in _styles)
                    {
                        var styleElement = new XElement(ns + "styleSheet");
                        if (s.HasAttributes)
                            styleElement.Add(s.Attributes());
                        if (!string.IsNullOrEmpty(s.Value))
                            styleElement.Add(new XCData(s.Value));
                        element.Add(styleElement);
                    }
                }
            }

            if (!string.IsNullOrEmpty(this.ScriptsXml))
            {
                var scriptsEl = XElement.Parse(this.ScriptsXml);
                if (scriptsEl != null && scriptsEl.HasElements)
                {
                    var _scripts = scriptsEl.Elements();
                    foreach (var s in _scripts)
                    {
                        var scriptElement = new XElement(ns + "script");
                        if (s.HasAttributes)
                            scriptElement.Add(s.Attributes());
                        if (!string.IsNullOrEmpty(s.Value))
                            scriptElement.Add(new XCData(s.Value));
                        element.Add(scriptElement);
                    }
                    //element.Add(scriptsEl.Elements());
                }
            }

            return element;
        }
Пример #2
0
        public virtual XElement Element()
        {
            XNamespace ns = ContentList.DefaultNamespace;

            var element = new XElement(ns + TAG_NAME,
                                       new XAttribute(NAME, this.Name));

            if (!string.IsNullOrEmpty(this.ViewTemplate))
            {
                element.Add(new XAttribute(TMPL, this.ViewTemplate));
            }

            if (this.AllowPaging)
            {
                var pagingElement = new XElement(ns + PAGING, new XAttribute(ALLOW, this.AllowPaging));

                if (this.PageIndex > 0)
                {
                    pagingElement.Add(new XAttribute(INDEX, this.PageIndex));
                }

                if (this.PageSize > 0)
                {
                    pagingElement.Add(new XAttribute(SIZE, this.PageSize));
                }

                element.Add(pagingElement);
            }

            if (!string.IsNullOrEmpty(Roles))
            {
                element.Add(new XAttribute(ACCESS_ROLES, Roles));
            }

            if (this.IsDefault)
            {
                element.Add(new XAttribute(DEFAULT, true));
            }

            if (this.IsHierarchy)
            {
                element.Add(new XAttribute(HIERARCHY, true));
            }

            if (this.HideToolbar)
            {
                element.Add(new XAttribute(HIDE_TOOLBAR, true));
            }

            if (!string.IsNullOrEmpty(this.Filter))
            {
                element.Add(new XAttribute(FILTER, this.Filter));
            }

            if (!string.IsNullOrEmpty(this.Sort))
            {
                element.Add(new XAttribute(SORT, Sort));
            }

            //if (!string.IsNullOrEmpty(this.Style))
            //    element.Add(new XAttribute(STYLE, this.Style));

            if (this.NoPage)
            {
                element.Add(new XElement(ns + NOPAGE, this.NoPage));
            }

            if (!string.IsNullOrEmpty(this.Title))
            {
                element.Add(new XElement(ns + TITLE, new XCData(this.Title)));
            }

            if (!string.IsNullOrEmpty(this.Description))
            {
                element.Add(new XElement(ns + DESC, new XCData(this.Title)));
            }

            //if (!string.IsNullOrEmpty(this.RowTemplate))
            //    element.Add(new XElement(ROW_TMPL, new XCData(this.RowTemplate)));

            if (this.AllowAnonymous)
            {
                element.Add(new XAttribute(ANONYMOUS, true));
            }

            if (!string.IsNullOrEmpty(this.BodyTemplateXml))
            {
                var tmpl = new ContentTemplate(this.BodyTemplateXml);
                element.Add(tmpl.Element());
            }

            if (!string.IsNullOrEmpty(this.EmptyTemplateXml))
            {
                element.Add(new XElement(ns + EMPTY_PATTERN, XElement.Parse(this.EmptyTemplateXml)));
            }

            if (!string.IsNullOrEmpty(this.StyleSheetsXml))
            {
                var stylesEl = XElement.Parse(this.StyleSheetsXml);
                if (stylesEl != null && stylesEl.HasElements)
                {
                    var _styles = stylesEl.Elements();
                    foreach (var s in _styles)
                    {
                        var styleElement = new XElement(ns + "styleSheet");
                        if (s.HasAttributes)
                        {
                            styleElement.Add(s.Attributes());
                        }
                        if (!string.IsNullOrEmpty(s.Value))
                        {
                            styleElement.Add(new XCData(s.Value));
                        }
                        element.Add(styleElement);
                    }
                }
            }

            if (!string.IsNullOrEmpty(this.ScriptsXml))
            {
                var scriptsEl = XElement.Parse(this.ScriptsXml);
                if (scriptsEl != null && scriptsEl.HasElements)
                {
                    var _scripts = scriptsEl.Elements();
                    foreach (var s in _scripts)
                    {
                        var scriptElement = new XElement(ns + "script");
                        if (s.HasAttributes)
                        {
                            scriptElement.Add(s.Attributes());
                        }
                        if (!string.IsNullOrEmpty(s.Value))
                        {
                            scriptElement.Add(new XCData(s.Value));
                        }
                        element.Add(scriptElement);
                    }
                    //element.Add(scriptsEl.Elements());
                }
            }

            return(element);
        }