private static MvcHtmlString DropDownList(HtmlHelper helper, EntityCombo entityCombo) { List <SelectListItem> items = new List <SelectListItem>(); items.Add(new SelectListItem() { Text = "-", Value = "" }); List <Lite <IEntity> > data = entityCombo.Data != null?entityCombo.Data.ToList() : AutocompleteUtils.FindAllLite(entityCombo.Implementations.Value).Cast <Lite <IEntity> >().ToList(); if (entityCombo.SortElements) { data = data.OrderBy(a => a.ToString()).ToList(); } var current = entityCombo.UntypedValue is IEntity ? ((IEntity)entityCombo.UntypedValue)?.ToLite() : entityCombo.UntypedValue as Lite <IEntity>; if (current != null && !data.Contains(current)) { data.Add(current); } items.AddRange( data.Select(lite => new SelectListItem() { Text = lite.ToString(), Value = lite.Key(), Selected = lite.Is(current) })); entityCombo.ComboHtmlProperties.AddCssClass("form-control"); if (entityCombo.ComboHtmlProperties.ContainsKey("onchange")) { throw new InvalidOperationException("EntityCombo cannot have onchange html property, use onEntityChanged instead"); } entityCombo.ComboHtmlProperties.Add("onchange", entityCombo.SFControlThen("combo_selected()")); if (entityCombo.Size > 0) { entityCombo.ComboHtmlProperties.AddCssClass("sf-entity-list"); entityCombo.ComboHtmlProperties.Add("size", Math.Min(entityCombo.Size, items.Count - 1)); } if (entityCombo.PlaceholderLabels && !entityCombo.ComboHtmlProperties.ContainsKey("placeholder")) { entityCombo.ComboHtmlProperties.Add("placeholder", entityCombo.LabelText); } return(helper.SafeDropDownList( entityCombo.Compose(EntityComboKeys.Combo), items, entityCombo.ComboHtmlProperties)); }
private static MvcHtmlString InternalEntityListCheckbox <T>(this HtmlHelper helper, EntityListCheckbox entityListCheckBox) { if (!entityListCheckBox.Visible || entityListCheckBox.HideIfNull && entityListCheckBox.UntypedValue == null) { return(MvcHtmlString.Empty); } var elementType = entityListCheckBox.Type.ElementType(); if (!elementType.IsIEntity() && !elementType.IsLite()) { throw new InvalidOperationException("EntityCombo can only be done for an identifiable or a lite, not for {0}".FormatWith(elementType.CleanType())); } HtmlStringBuilder sb = new HtmlStringBuilder(); using (sb.SurroundLine(new HtmlTag("fieldset", entityListCheckBox.Prefix).Class("SF-repeater-field SF-control-container SF-avoid-child-errors"))) { sb.AddLine(helper.Hidden(entityListCheckBox.Compose(EntityListBaseKeys.ListPresent), "")); using (sb.SurroundLine(new HtmlTag("div", entityListCheckBox.Compose("hidden")).Class("hide"))) { } using (sb.SurroundLine(new HtmlTag("legend"))) using (sb.SurroundLine(new HtmlTag("div", entityListCheckBox.Compose("header")))) { sb.AddLine(new HtmlTag("span").InnerHtml(entityListCheckBox.LabelHtml ?? entityListCheckBox.LabelText.FormatHtml()).ToHtml()); using (sb.SurroundLine(new HtmlTag("span", entityListCheckBox.Compose("shownButton")).Class("pull-right"))) { sb.AddLine(EntityButtonHelper.Create(helper, entityListCheckBox, btn: false)); sb.AddLine(EntityButtonHelper.Find(helper, entityListCheckBox, btn: false)); } } using (sb.SurroundLine(new HtmlTag("div").Id(entityListCheckBox.Compose(EntityRepeaterKeys.ItemsContainer)).Attr("style", GetStyle(entityListCheckBox)))) { IEnumerable <Lite <IEntity> > data = entityListCheckBox.Data ?? AutocompleteUtils.FindAllLite(entityListCheckBox.Implementations.Value).OrderBy(a => a.ToString()); if (entityListCheckBox.UntypedValue != null) { var already = TypeContextUtilities.TypeElementContext((TypeContext <MList <T> >)entityListCheckBox.Parent).ToDictionary(a => AsLite(a.Value), "repeated elements"); List <Lite <IEntity> > liteList = data.Except(already.Keys).ToList(); List <T> typedList = typeof(Lite <IEntity>).IsAssignableFrom(typeof(T)) ? liteList.Cast <T>().ToList(): Database.RetrieveFromListOfLite(liteList).Cast <T>().ToList(); var extra = typedList.Select((e, i) => new TypeElementContext <T>(e, (TypeContext)entityListCheckBox.Parent, i + already.Count, null)).ToDictionary(a => AsLite(a.Value), "repeated elements"); foreach (var lite in data) { sb.Add(InternalRepeaterElement(helper, already.TryGetC(lite) ?? extra.GetOrThrow(lite), entityListCheckBox, already.ContainsKey(lite), lite)); } } } if (entityListCheckBox.ElementType.IsEmbeddedEntity() && entityListCheckBox.Create) { T embedded = (T)(object)new ConstructorContext(helper.ViewContext.Controller).ConstructUntyped(typeof(T)); TypeElementContext <T> templateTC = new TypeElementContext <T>(embedded, (TypeContext)entityListCheckBox.Parent, 0, null); sb.AddLine(EntityBaseHelper.EmbeddedTemplate(entityListCheckBox, EntityBaseHelper.RenderContent(helper, templateTC, RenderContentMode.Content, entityListCheckBox), null)); } sb.AddLine(entityListCheckBox.ConstructorScript(JsModule.Lines, "EntityListCheckbox")); } return(sb.ToHtml()); }
public virtual List <Lite <Entity> > FindAllLite(Implementations implementations) { return(Return(MethodInfo.GetCurrentMethod(), implementations.ToString(), () => AutocompleteUtils.FindAllLite(implementations))); }
public List <Lite <Entity> > FetchAllLites([FromUri] string types) { Implementations implementations = ParseImplementations(types); return(AutocompleteUtils.FindAllLite(implementations)); }