protected string RenderInternal(SortableListItemWrapper list) { var htmlString = String.Empty; if (list.BadgeTag.Attributes.ContainsKey("class")) { list.BadgeTag.Attributes["class"] += " label"; } else { list.BadgeTag.Attributes.Add("class", "label"); } if (list.ItemTag.Attributes.ContainsKey("class")) { list.ItemTag.Attributes["class"] += " bs-sortable-item"; } else { list.ItemTag.Attributes.Add("class", "bs-sortable-item"); } #region Nested elements if (list.RootTag.Attributes.ContainsKey("class")) { list.RootTag.Attributes["class"] += " bs-sortable"; } else { list.RootTag.Attributes.Add("class", "bs-sortable"); } if (list.Children != null && list.Children.Any()) { foreach (var child in list.Children) { list.RootTag.InnerHtml += RenderInternal(child); } } #endregion list.ItemTag.InnerHtml += list.BadgeTag.ToString() + list.LabelTag.ToString() + list.RootTag.ToString(); htmlString = list.ItemTag.ToString(); return(htmlString); }
private SortableListItemWrapper Build(IEnumerable <TModel> modelList, Expression <Func <TModel, BsSortableListConfiguration <TModel> > > config, Expression <Func <TModel, HtmlProperties> > globalProperties, Expression <Func <TModel, HtmlProperties> > itemProperties, Expression <Func <TModel, HtmlProperties> > labelProperties, Expression <Func <TModel, HtmlProperties> > badgeProperties) { var sortableListItemWrapper = new SortableListItemWrapper(); if (modelList != null && modelList.Any()) { sortableListItemWrapper.Children = new List <SortableListItemWrapper>(); _permitedConnections = GetPermitedConnections(_reducedTree, config); foreach (var item in modelList) { sortableListItemWrapper.Children.Add(Build(item, config, globalProperties, itemProperties, labelProperties, badgeProperties)); } } return(sortableListItemWrapper); }
public string RenderInternal(SortableListItemWrapper list) { var htmlString = String.Empty; list.RootTag = new TagBuilder("ul"); if (list.ItemTag.Attributes.ContainsKey("class")) { list.ItemTag.Attributes["class"] += " bs-sortable-item active"; } else { list.ItemTag.Attributes.Add("class", "bs-sortable-item active"); } #region Nested elements if (list.RootTag.Attributes.ContainsKey("class")) { list.RootTag.Attributes["class"] += " bs-sortable nav nav-pills nav-stacked"; } else { list.RootTag.Attributes.Add("class", "bs-sortable nav nav-pills nav-stacked"); } if (list.RootTag.Attributes.ContainsKey("style")) { list.RootTag.Attributes["style"] += "margin-left: 40px; margin-top: 4px;"; } else { list.RootTag.Attributes.Add("style", "margin-left: 40px; margin-top: 4px;"); } if (list.Children != null && list.Children.Any()) { foreach (var child in list.Children) { list.RootTag.InnerHtml += RenderInternal(child); } } #endregion var anchor = new TagBuilder("a"); anchor.Attributes.Add("href", "#"); anchor.SetInnerText(list.LabelTag.InnerHtml); var span = new TagBuilder("span"); span.Attributes.Add("class", "badge pull-right"); span.InnerHtml = list.BadgeTag.InnerHtml; anchor.InnerHtml = span.ToString() + anchor.InnerHtml; list.ItemTag.InnerHtml = anchor.ToString() + list.RootTag.ToString(); // list.ItemTag.InnerHtml += spanTag.ToString() + list.RootTag.ToString(); // htmlString = list.ItemTag.ToString() + list.RootTag.ToString(); htmlString = list.ItemTag.ToString(); return(htmlString); }
private SortableListItemWrapper Build(TModel model, Expression <Func <TModel, BsSortableListConfiguration <TModel> > > config, Expression <Func <TModel, HtmlProperties> > globalProperties, Expression <Func <TModel, HtmlProperties> > itemProperties, Expression <Func <TModel, HtmlProperties> > labelProperties, Expression <Func <TModel, HtmlProperties> > badgeProperties) { var sortableListItemWrapper = new SortableListItemWrapper(); #region Apply attributes var itemProps = itemProperties != null?itemProperties.Compile().Invoke(model) : new HtmlProperties(null, null, null); var labelProps = labelProperties != null?labelProperties.Compile().Invoke(model) : new HtmlProperties(null, null, null); var badgeProps = badgeProperties != null?badgeProperties.Compile().Invoke(model) : new HtmlProperties(null, null, null); var globalProps = globalProperties != null?globalProperties.Compile().Invoke(model) : new HtmlProperties(null, null, null); var configProps = config != null?config.Compile().Invoke(model) : null; var htmlAttributes = new RouteValueDictionary(); var dataAttributes = new RouteValueDictionary(); #region Root sortableListItemWrapper.RootTag.MergeAttributes(DictionaryFromAttributes(globalProps.HtmlAttributes)); sortableListItemWrapper.RootTag.MergeAttributes(DictionaryFromAttributes(globalProps.DataAttributes, "data-")); #endregion #region Item if (configProps != null) { var connectionString = String.Join(" ", _permitedConnections[configProps.Id].OrderBy(x => x)); dataAttributes = DictionaryFromAttributes(itemProps.DataAttributes, "data-"); dataAttributes.Add("data-id", configProps.Id); dataAttributes.Add("data-order", configProps.Order); dataAttributes.Add("data-appends-to", connectionString); } sortableListItemWrapper.ItemTag.MergeAttributes(DictionaryFromAttributes(itemProps.HtmlAttributes)); sortableListItemWrapper.ItemTag.MergeAttributes(dataAttributes); #endregion #region Label htmlAttributes = DictionaryFromAttributes(labelProps.HtmlAttributes); sortableListItemWrapper.LabelTag.MergeAttributes(htmlAttributes); sortableListItemWrapper.LabelTag.MergeAttributes(DictionaryFromAttributes(labelProps.DataAttributes, "data-")); sortableListItemWrapper.LabelTag.InnerHtml = " " + (configProps != null ? configProps.Text : String.Empty); #endregion #region Badge sortableListItemWrapper.BadgeTag.MergeAttributes(DictionaryFromAttributes(badgeProps.HtmlAttributes)); sortableListItemWrapper.BadgeTag.MergeAttributes(DictionaryFromAttributes(badgeProps.DataAttributes, "data-")); sortableListItemWrapper.BadgeTag.InnerHtml += badgeProps.Text; #endregion #endregion #region Build nested list var properties = model.GetType().GetProperties(); PropertyInfo nestedValuesProperty = null; // Find the first property in @model's properties // decorated with a BsControlAttribute matching BsControlType.SortableList foreach (PropertyInfo prop in properties) { if (nestedValuesProperty != null) { break; } var attributes = prop.GetCustomAttributes(true); foreach (var attr in attributes) { var bsControl = attr as BsControlAttribute; if (bsControl != null && bsControl.ControlType == BsControlType.SortableList) { nestedValuesProperty = prop; break; } } } if (nestedValuesProperty != null) { var value = nestedValuesProperty.GetValue(model, null); sortableListItemWrapper.Children = new List <SortableListItemWrapper>(); if (value != null && (value as IEnumerable <TModel>) != null) { foreach (var item in (value as IEnumerable <TModel>)) { sortableListItemWrapper.Children.Add(Build(item, config, globalProperties, itemProperties, labelProperties, badgeProperties)); } } } #endregion return(sortableListItemWrapper); }