public static MvcHtmlString TimePicker(this HtmlHelper helper, string name, bool formGroup, string value, string dateFormat, IDictionary <string, object> htmlProps = null) { if (dateFormat.Contains("f") || dateFormat.Contains("F")) { htmlProps["class"] += " form-control"; return(helper.TextBox(TypeContextUtilities.Compose(name, "Time"), value, htmlProps)); } var input = new HtmlTag("input") .IdName(name) .Attr("type", "text") .Class("form-control") .Attrs(htmlProps) .Attr("value", value); if (!formGroup) { return(AttachTimePiceker(input, dateFormat)); } HtmlStringBuilder sb = new HtmlStringBuilder(); using (sb.SurroundLine(AttachTimePiceker(new HtmlTag("div").Class("input-group time"), dateFormat))) { sb.Add(input); using (sb.SurroundLine(new HtmlTag("span").Class("input-group-addon"))) sb.Add(new HtmlTag("span").Class("glyphicon glyphicon-time")); } return(sb.ToHtml()); }
protected internal virtual ModifiableEntity ExtractEntity(ControllerBase controller, string prefix) { NameValueCollection form = controller.ControllerContext.HttpContext.Request.Form; var state = form[TypeContextUtilities.Compose(prefix, EntityBaseKeys.EntityState)]; if (state.HasText()) { return(Navigator.Manager.DeserializeEntity(state)); } var key = TypeContextUtilities.Compose(prefix, EntityBaseKeys.RuntimeInfo); RuntimeInfo runtimeInfo = RuntimeInfo.FromFormValue(form[key]); if (runtimeInfo == null) { throw new ArgumentNullException("{0} not found in form request".FormatWith(key)); } if (runtimeInfo.EntityType.IsEntity() && !runtimeInfo.IsNew) { return(Database.Retrieve(runtimeInfo.EntityType, runtimeInfo.IdOrNull.Value)); } else { return(new ConstructorContext(controller).ConstructUntyped(runtimeInfo.EntityType)); } }
public static MvcHtmlString RenderPopup(HtmlHelper helper, TypeContext typeContext, RenderPopupMode mode, EntityBase line, bool isTemplate = false) { TypeContext tc = TypeContextUtilities.CleanTypeContext((TypeContext)typeContext); ViewDataDictionary vdd = GetViewData(helper, line, tc); string partialViewName = line.PartialViewName ?? OnPartialViewName(tc); vdd[ViewDataKeys.PartialViewName] = partialViewName; vdd[ViewDataKeys.ViewMode] = !line.ReadOnly; vdd[ViewDataKeys.ViewMode] = ViewMode.View; vdd[ViewDataKeys.ShowOperations] = true; vdd[ViewDataKeys.RequiresSaveOperation] = EntityKindCache.RequiresSaveOperation(tc.UntypedValue.GetType()); vdd[ViewDataKeys.WriteEntityState] = !isTemplate && !(tc.UntypedValue is EmbeddedEntity) && ((ModifiableEntity)tc.UntypedValue).Modified == ModifiedState.SelfModified; switch (mode) { case RenderPopupMode.Popup: return(helper.Partial(Navigator.Manager.PopupControlView, vdd)); case RenderPopupMode.PopupInDiv: return(helper.Div(typeContext.Compose(EntityBaseKeys.Entity), helper.Partial(Navigator.Manager.PopupControlView, vdd), "", new Dictionary <string, object> { { "style", "display:none" } })); default: throw new InvalidOperationException(); } }
public static MvcHtmlString RenderContent(HtmlHelper helper, TypeContext typeContext, RenderContentMode mode, EntityBase line) { TypeContext tc = TypeContextUtilities.CleanTypeContext((TypeContext)typeContext); ViewDataDictionary vdd = GetViewData(helper, line, tc); string partialViewName = line.PartialViewName ?? OnPartialViewName(tc); switch (mode) { case RenderContentMode.Content: return(helper.Partial(partialViewName, vdd)); case RenderContentMode.ContentInVisibleDiv: return(helper.Div(typeContext.Compose(EntityBaseKeys.Entity), helper.Partial(partialViewName, vdd), "", null)); case RenderContentMode.ContentInInvisibleDiv: return(helper.Div(typeContext.Compose(EntityBaseKeys.Entity), helper.Partial(partialViewName, vdd), "", new Dictionary <string, object> { { "style", "display:none" } })); default: throw new InvalidOperationException(); } }
internal static IWidget CreateWidget(WidgetContext ctx) { var ident = ctx.Entity as Entity; if (ident == null || ident.IsNew) { return(null); } List <QuickLink> quicklinks = LinksClient.GetForEntity(ident.ToLiteFat(), ctx.PartialViewName, ctx.Prefix, null, ctx.Url); if (quicklinks == null || quicklinks.Count == 0) { return(null); } return(new Widget { Id = TypeContextUtilities.Compose(ctx.Prefix, "quicklinksWidget"), Class = "sf-quicklinks", Title = QuickLinkMessage.Quicklinks.NiceToString(), IconClass = "glyphicon glyphicon-star", Text = quicklinks.Count.ToString(), Items = quicklinks.OrderBy(a => a.Order).Cast <IMenuItem>().ToList(), Active = true, }); }
protected internal virtual PartialViewResult PartialView(ControllerBase controller, TypeContext tc, string partialViewName) { TypeContext cleanTC = TypeContextUtilities.CleanTypeContext(tc); Type cleanType = cleanTC.UntypedValue.GetType(); if (!Navigator.IsViewable(cleanType, partialViewName)) { throw new Exception(NormalControlMessage.ViewForType0IsNotAllowed.NiceToString().FormatWith(cleanType.Name)); } controller.ViewData.Model = cleanTC; if (Navigator.IsReadOnly(cleanType)) { cleanTC.ReadOnly = true; } cleanTC.ViewOverrides = Navigator.EntitySettings(cleanType).GetViewOverrides(); return(new PartialViewResult { ViewName = partialViewName ?? Navigator.OnPartialViewName((ModifiableEntity)cleanTC.UntypedValue), ViewData = controller.ViewData, TempData = controller.TempData }); }
public override MvcHtmlString Execute() { JObject jsFindOptions = FindOptions.ToJS(TypeContextUtilities.Compose("New", Prefix)); return(new HtmlTag("a") .Attr("onclick", JsModule.Finder["explore"](jsFindOptions).ToString()) .InnerHtml(TextAndIcon())); }
private static MvcHtmlString InternalEntityRepeater<T>(this HtmlHelper helper, EntityTabRepeater repeater) { if (!repeater.Visible || repeater.HideIfNull && repeater.UntypedValue == null) return MvcHtmlString.Empty; HtmlStringBuilder sb = new HtmlStringBuilder(); using (sb.SurroundLine(new HtmlTag("fieldset").Id(repeater.Prefix).Class("sf-tab-repeater-field SF-control-container SF-avoid-child-errors"))) { using (sb.SurroundLine(new HtmlTag("legend"))) using (sb.SurroundLine(new HtmlTag("div", repeater.Compose("header")))) { sb.AddLine(new HtmlTag("span").InnerHtml(repeater.LabelHtml ?? repeater.LabelText.FormatHtml()).ToHtml()); using (sb.SurroundLine(new HtmlTag("span", repeater.Compose("shownButton")).Class("pull-right"))) { sb.AddLine(EntityButtonHelper.Create(helper, repeater, btn: false)); sb.AddLine(EntityButtonHelper.Find(helper, repeater, btn: false)); } } sb.AddLine(helper.Hidden(repeater.Compose(EntityListBaseKeys.ListPresent), "")); using (sb.SurroundLine(new HtmlTag("div"))) { using (sb.SurroundLine(new HtmlTag("ul", repeater.Compose(EntityRepeaterKeys.ItemsContainer)).Class("nav nav-tabs"))) { if (repeater.UntypedValue != null) { foreach (var itemTC in TypeContextUtilities.TypeElementContext((TypeContext<MList<T>>)repeater.Parent)) sb.Add(InternalTabRepeaterHeader(helper, itemTC, repeater)); } } using (sb.SurroundLine(new HtmlTag("div", repeater.Compose(EntityRepeaterKeys.TabsContainer)).Class("tab-content"))) if (repeater.UntypedValue != null) { foreach (var itemTC in TypeContextUtilities.TypeElementContext((TypeContext<MList<T>>)repeater.Parent)) using (sb.SurroundLine(new HtmlTag("div", itemTC.Compose(EntityBaseKeys.Entity)).Class("tab-pane") .Let(h => itemTC.Index == 0 ? h.Class("active") : h))) sb.Add(EntityBaseHelper.RenderContent(helper, itemTC, RenderContentMode.Content, repeater)); } } if (repeater.ElementType.IsEmbeddedEntity() && repeater.Create) { T embedded = (T)(object)new ConstructorContext(helper.ViewContext.Controller).ConstructUntyped(typeof(T)); TypeElementContext<T> templateTC = new TypeElementContext<T>(embedded, (TypeContext)repeater.Parent, 0, null); sb.AddLine(EntityBaseHelper.EmbeddedTemplate(repeater, EntityBaseHelper.RenderContent(helper, templateTC, RenderContentMode.Content, repeater), templateTC.Value.ToString())); } sb.AddLine(repeater.ConstructorScript(JsModule.Lines, "EntityTabRepeater")); } return sb.ToHtml(); }
protected internal virtual Lite <T> ExtractLite <T>(ControllerBase controller, string prefix) where T : class, IEntity { NameValueCollection form = controller.ControllerContext.HttpContext.Request.Form; RuntimeInfo runtimeInfo = RuntimeInfo.FromFormValue(form[TypeContextUtilities.Compose(prefix, EntityBaseKeys.RuntimeInfo)]); if (!runtimeInfo.IdOrNull.HasValue) { throw new ArgumentException("Could not create a Lite without an Id"); } return((Lite <T>)runtimeInfo.ToLite()); }
public IEnumerable <MappingContext <S> > GenerateItemContexts(MappingContext <MList <S> > ctx) { PropertyRoute route = ctx.PropertyRoute.Add("Item"); var indexPrefixes = ctx.Inputs.IndexPrefixes(); foreach (var index in indexPrefixes.OrderBy(ip => (ctx.GlobalInputs.TryGetC(TypeContextUtilities.Compose(ctx.Prefix, ip, EntityListBaseKeys.Index)) ?? ip).ToInt())) { SubContext <S> itemCtx = new SubContext <S>(TypeContextUtilities.Compose(ctx.Prefix, index), null, route, ctx); yield return(itemCtx); } }
public SubContext <P> CreateSubContext(MappingContext <T> parent) { string newPrefix = TypeContextUtilities.Compose(parent.Prefix, PropertyValidator.PropertyInfo.Name); PropertyRoute route = parent.PropertyRoute.Add(this.PropertyValidator.PropertyInfo); SubContext <P> ctx = new SubContext <P>(newPrefix, PropertyValidator, route, parent); if (parent.Value != null) { ctx.Value = GetValue(parent.Value); } return(ctx); }
public bool Parse <V>(string property, out V value) { var mapping = Mapping.ForValue <V>(); if (mapping == null) { throw new InvalidOperationException("No mapping for value {0}".FormatWith(typeof(V).TypeName())); } var sc = new SubContext <V>(TypeContextUtilities.Compose(this.Prefix, property), null, null, this); value = mapping(sc); return(!sc.SupressChange); }
public static MvcHtmlString EmbeddedControl <T, S>(this HtmlHelper helper, TypeContext <T> tc, Expression <Func <T, S> > property, Action <EmbeddedControl> settingsModifier) { TypeContext context = TypeContextUtilities.CleanTypeContext(Common.WalkExpression(tc, property)); var vo = tc.ViewOverrides; if (vo != null && !vo.IsVisible(context.PropertyRoute)) { return(vo.OnSurroundLine(context.PropertyRoute, helper, tc, null)); } var ec = new EmbeddedControl(); if (settingsModifier != null) { settingsModifier(ec); } string viewName = ec.ViewName; if (viewName == null) { var es = Navigator.EntitySettings(context.Type.CleanType()); viewName = es.OnPartialViewName((ModifiableEntity)context.UntypedValue); context.ViewOverrides = es.GetViewOverrides(); } ViewDataDictionary vdd = new ViewDataDictionary(context); if (ec.ViewData != null) { vdd.AddRange(ec.ViewData); } var result = helper.Partial(viewName, vdd); if (vo == null) { return(result); } return(vo.OnSurroundLine(context.PropertyRoute, helper, tc, result)); }
public override MList <S> GetValue(MappingContext <MList <S> > ctx) { using (HeavyProfiler.LogNoStackTrace("GetValue", () => "MListDictionaryMapping<{0}>".FormatWith(typeof(S).TypeName()))) { if (ctx.Empty()) { return(ctx.None()); } MList <S> list = ctx.Value; var dic = (FilterElements == null ? list : list.Where(FilterElements)).ToDictionary(GetKey); PropertyRoute route = ctx.PropertyRoute.Add("Item").Continue(MemberList); string[] namesToAppend = MemberList.Select(MemberAccessGatherer.GetName).NotNull().ToArray(); foreach (MappingContext <S> itemCtx in GenerateItemContexts(ctx)) { var tce = new TypeContextExpression(new PropertyInfo[0], typeof(S), itemCtx.PropertyRoute, itemCtx.Value); SubContext <K> subContext = new SubContext <K>(TypeContextUtilities.Compose(itemCtx.Prefix, namesToAppend), null, route, itemCtx); subContext.Value = KeyMapping(subContext); if (!dic.ContainsKey(subContext.Value) && OnlyIfPossible) { continue; } itemCtx.Value = dic.GetOrThrow(subContext.Value); itemCtx.Value = ElementMapping(itemCtx); ctx.AddChild(itemCtx); } return(list); } }
public static MvcHtmlString DateTimePicker(this HtmlHelper helper, string name, bool formGroup, DateTime?value, string dateTimeFormat, CultureInfo culture = null, IDictionary <string, object> htmlProps = null) { var dateFormat = SplitDateTimeFormat(dateTimeFormat, culture); if (dateFormat.TimeFormat == null) { return(helper.DatePicker(name, formGroup, value?.ToString(dateFormat.DateFormat, culture), ToJsDateFormat(dateFormat.DateFormat), culture, htmlProps)); } if (dateFormat.DateFormat == null) { return(helper.TimePicker(name, formGroup, value?.ToString(dateFormat.TimeFormat, culture), dateFormat.TimeFormat, htmlProps)); } HtmlStringBuilder sb = new HtmlStringBuilder(); using (sb.SurroundLine(new HtmlTag("div", name).Class("date-time"))) { sb.Add(helper.DatePicker(TypeContextUtilities.Compose(name, "Date"), formGroup, value?.ToString(dateFormat.DateFormat, culture), ToJsDateFormat(dateFormat.DateFormat), culture, htmlProps)); sb.Add(helper.TimePicker(TypeContextUtilities.Compose(name, "Time"), formGroup, value?.ToString(dateFormat.TimeFormat, culture), dateFormat.TimeFormat, htmlProps)); } return(sb.ToHtml()); }
public void FillViewDataForViewing(ControllerBase controller, IRootEntity rootEntity, NavigateOptions options) { TypeContext tc = TypeContextUtilities.UntypedNew(rootEntity, ""); controller.ViewData.Model = tc; var entity = (ModifiableEntity)rootEntity; controller.ViewData[ViewDataKeys.PartialViewName] = options.PartialViewName ?? Navigator.OnPartialViewName(entity); tc.ViewOverrides = Navigator.EntitySettings(entity.GetType()).GetViewOverrides(); if (controller.ViewData[ViewDataKeys.TabId] == null) { controller.ViewData[ViewDataKeys.TabId] = GetOrCreateTabID(controller); } controller.ViewData[ViewDataKeys.ShowOperations] = options.ShowOperations; controller.ViewData[ViewDataKeys.WriteEntityState] = options.WriteEntityState || (bool?)controller.ViewData[ViewDataKeys.WriteEntityState] == true; AssertViewableEntitySettings(entity); tc.ReadOnly = options.ReadOnly ?? Navigator.IsReadOnly(entity); }
public JObject ToJS(string parentPrefix, string newPart) { return(ToJS(TypeContextUtilities.Compose(parentPrefix, newPart))); }
public static PartialViewResult PopupNavigate(this ControllerBase controller, IRootEntity entity, PopupNavigateOptions options = null) { var prefix = options?.Prefix ?? controller.Prefix(); return(Manager.PopupControl(controller, TypeContextUtilities.UntypedNew(entity, prefix), options ?? new PopupNavigateOptions(prefix))); }
public ToolBarButton(string prefix, string idToAppend) : this(TypeContextUtilities.Compose(prefix, idToAppend)) { }
public MenuItem(string prefix, string idToAppend) : this(TypeContextUtilities.Compose(prefix, idToAppend)) { }
private static MvcHtmlString InternalEntityList <T>(this HtmlHelper helper, EntityList entityList) { if (!entityList.Visible || entityList.HideIfNull && entityList.UntypedValue == null) { return(MvcHtmlString.Empty); } HtmlStringBuilder sb = new HtmlStringBuilder(); using (sb.SurroundLine(new HtmlTag("div", entityList.Prefix).Class("SF-entity-list SF-control-container"))) { sb.AddLine(helper.Hidden(entityList.Compose(EntityListBaseKeys.ListPresent), "")); using (sb.SurroundLine(new HtmlTag("div", entityList.Compose("hidden")).Class("hide"))) { } HtmlStringBuilder sbSelect = new HtmlStringBuilder(); var sbSelectContainer = new HtmlTag("select").Attr("size", "6").Class("form-control") .IdName(entityList.Compose(EntityListBaseKeys.List)); if (entityList.ListHtmlProps.Any()) { sbSelectContainer.Attrs(entityList.ListHtmlProps); } using (sbSelect.SurroundLine(sbSelectContainer)) { if (entityList.UntypedValue != null) { foreach (var itemTC in TypeContextUtilities.TypeElementContext((TypeContext <MList <T> >)entityList.Parent)) { sb.Add(InternalListElement(helper, sbSelect, itemTC, entityList)); } } } using (sb.SurroundLine(new HtmlTag("div", entityList.Compose("inputGroup")).Class("input-group"))) { sb.Add(sbSelect.ToHtml()); using (sb.SurroundLine(new HtmlTag("span", entityList.Compose("shownButton")).Class("input-group-btn btn-group-vertical"))) { sb.AddLine(EntityButtonHelper.Create(helper, entityList, btn: true)); sb.AddLine(EntityButtonHelper.Find(helper, entityList, btn: true)); sb.AddLine(EntityButtonHelper.View(helper, entityList, btn: true)); sb.AddLine(EntityButtonHelper.Remove(helper, entityList, btn: true)); sb.AddLine(EntityButtonHelper.MoveUp(helper, entityList, btn: true)); sb.AddLine(EntityButtonHelper.MoveDown(helper, entityList, btn: true)); } } if (entityList.ElementType.IsEmbeddedEntity() && entityList.Create) { T embedded = (T)(object)new ConstructorContext(helper.ViewContext.Controller).ConstructUntyped(typeof(T)); TypeElementContext <T> templateTC = new TypeElementContext <T>(embedded, (TypeContext)entityList.Parent, 0, null); sb.AddLine(EntityBaseHelper.EmbeddedTemplate(entityList, EntityBaseHelper.RenderPopup(helper, templateTC, RenderPopupMode.Popup, entityList, isTemplate: true), null)); } sb.AddLine(entityList.ConstructorScript(JsModule.Lines, "EntityList")); } return(helper.FormGroup(entityList, entityList.Prefix, entityList.LabelHtml ?? entityList.LabelText.FormatHtml(), sb.ToHtml())); }
public static PartialViewResult PopupView(this ControllerBase controller, ModifiableEntity entity, PopupViewOptions options = null) { var prefix = options?.Prefix ?? controller.Prefix(); return(Manager.PopupControl(controller, TypeContextUtilities.UntypedNew(entity, prefix, options?.PropertyRoute), options ?? new PopupViewOptions(prefix))); }
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 static PartialViewResult PartialView(this ControllerBase controller, IRootEntity entity, string prefix, string partialViewName) { TypeContext tc = TypeContextUtilities.UntypedNew(entity, prefix); return(Manager.PartialView(controller, tc, partialViewName)); }
private static MvcHtmlString InternalEntityListDetail <T>(this HtmlHelper helper, EntityListDetail listDetail) { if (!listDetail.Visible || listDetail.HideIfNull && listDetail.UntypedValue == null) { return(MvcHtmlString.Empty); } HtmlStringBuilder sb = new HtmlStringBuilder(); using (sb.SurroundLine(new HtmlTag("div", listDetail.Prefix).Class("SF-entity-list-detail SF-control-container"))) { sb.AddLine(helper.Hidden(listDetail.Compose(EntityListBaseKeys.ListPresent), "")); using (sb.SurroundLine(new HtmlTag("div", listDetail.Compose("hidden")).Class("hide"))) { } HtmlStringBuilder sbSelect = new HtmlStringBuilder(); var sbSelectContainer = new HtmlTag("select").Attr("size", "6").Class("form-control") .IdName(listDetail.Compose(EntityListBaseKeys.List)); if (listDetail.ListHtmlProps.Any()) { sbSelectContainer.Attrs(listDetail.ListHtmlProps); } using (sbSelect.SurroundLine(sbSelectContainer)) { if (listDetail.UntypedValue != null) { foreach (var itemTC in TypeContextUtilities.TypeElementContext((TypeContext <MList <T> >)listDetail.Parent)) { sb.Add(InternalListDetailElement(helper, sbSelect, itemTC, listDetail)); } } } using (sb.SurroundLine(new HtmlTag("div", listDetail.Compose("inputGroup")).Class("input-group"))) { sb.Add(sbSelect.ToHtml()); using (sb.SurroundLine(new HtmlTag("span", listDetail.Compose("shownButton")).Class("input-group-btn btn-group-vertical"))) { sb.AddLine(EntityButtonHelper.Create(helper, listDetail, btn: true)); sb.AddLine(EntityButtonHelper.Find(helper, listDetail, btn: true)); sb.AddLine(EntityButtonHelper.Remove(helper, listDetail, btn: true)); sb.AddLine(EntityButtonHelper.MoveUp(helper, listDetail, btn: true)); sb.AddLine(EntityButtonHelper.MoveDown(helper, listDetail, btn: true)); } } if (listDetail.ElementType.IsEmbeddedEntity() && listDetail.Create) { T embedded = (T)(object)new ConstructorContext(helper.ViewContext.Controller).ConstructUntyped(typeof(T)); TypeElementContext <T> templateTC = new TypeElementContext <T>(embedded, (TypeContext)listDetail.Parent, 0, null); sb.AddLine(EntityBaseHelper.EmbeddedTemplate(listDetail, EntityBaseHelper.RenderContent(helper, templateTC, RenderContentMode.Content, listDetail), templateTC.Value.ToString())); } sb.AddLine(listDetail.ConstructorScript(JsModule.Lines, "EntityListDetail")); } var formGroup = helper.FormGroup(listDetail, listDetail.Prefix, listDetail.LabelHtml ?? listDetail.LabelText.FormatHtml(), sb.ToHtml()); if (listDetail.DetailDiv != listDetail.Compose(EntityBaseKeys.Detail)) { return(formGroup); } HtmlStringBuilder sb2 = new HtmlStringBuilder(); sb2.Add(formGroup); using (sb2.SurroundLine(new HtmlTag("fieldset"))) sb2.AddLine(helper.Div(listDetail.DetailDiv, null, "SF-entity-list-detail-detaildiv")); return(sb2.ToHtml()); }
private static MvcHtmlString InternalEntityStrip <T>(this HtmlHelper helper, EntityStrip entityStrip) { if (!entityStrip.Visible || entityStrip.HideIfNull && entityStrip.UntypedValue == null) { return(MvcHtmlString.Empty); } HtmlStringBuilder sb = new HtmlStringBuilder(); using (sb.SurroundLine(new HtmlTag("div", entityStrip.Prefix).Class("SF-entity-strip SF-control-container"))) { sb.AddLine(helper.Hidden(entityStrip.Compose(EntityListBaseKeys.ListPresent), "")); using (sb.SurroundLine(new HtmlTag("div", entityStrip.Compose("hidden")).Class("hide"))) { } using (sb.SurroundLine(new HtmlTag("ul", entityStrip.Compose(EntityStripKeys.ItemsContainer)) .Class("sf-strip").Class(entityStrip.Vertical ? "sf-strip-vertical" : "sf-strip-horizontal"))) { if (entityStrip.UntypedValue != null) { foreach (var itemTC in TypeContextUtilities.TypeElementContext((TypeContext <MList <T> >)entityStrip.Parent)) { sb.Add(InternalStripElement(helper, itemTC, entityStrip)); } } using (sb.SurroundLine(new HtmlTag("li").Class("sf-strip-input input-group"))) { if (entityStrip.Autocomplete) { var htmlAttr = new Dictionary <string, object> { { "class", "sf-entity-autocomplete" }, { "autocomplete", "off" }, }; sb.AddLine(helper.TextBox( entityStrip.Compose(EntityBaseKeys.ToStr), null, htmlAttr)); } using (sb.SurroundLine(new HtmlTag("span", entityStrip.Compose("shownButton")))) { sb.AddLine(EntityButtonHelper.Create(helper, entityStrip, btn: false)); sb.AddLine(EntityButtonHelper.Find(helper, entityStrip, btn: false)); } } } if (entityStrip.ElementType.IsEmbeddedEntity() && entityStrip.Create) { T embeddedEntity = (T)(object)new ConstructorContext(helper.ViewContext.Controller).ConstructUntyped(typeof(T)); TypeElementContext <T> templateTC = new TypeElementContext <T>(embeddedEntity, (TypeContext)entityStrip.Parent, 0, null); sb.AddLine(EntityBaseHelper.EmbeddedTemplate(entityStrip, EntityBaseHelper.RenderPopup(helper, templateTC, RenderPopupMode.Popup, entityStrip, isTemplate: true), null)); } sb.AddLine(entityStrip.ConstructorScript(JsModule.Lines, "EntityStrip")); } return(helper.FormGroup(entityStrip, entityStrip.Prefix, entityStrip.LabelHtml ?? entityStrip.LabelText.FormatHtml(), sb.ToHtml())); }
private static MvcHtmlString InternalGridRepeater<T>(this HtmlHelper helper, GridRepeater repeater) where T : ModifiableEntity, IGridEntity { if (!repeater.Visible || repeater.HideIfNull && repeater.UntypedValue == null) return MvcHtmlString.Empty; HtmlStringBuilder sb = new HtmlStringBuilder(); using (sb.SurroundLine(new HtmlTag("fieldset", repeater.Prefix).Class("SF-grid-repeater-field SF-control-container"))) { sb.AddLine(helper.Hidden(repeater.Compose(EntityListBaseKeys.ListPresent), "")); using (sb.SurroundLine(new HtmlTag("div", repeater.Compose("hidden")).Class("hide"))) { } using (sb.SurroundLine(new HtmlTag("legend"))) using (sb.SurroundLine(new HtmlTag("div", repeater.Compose("header")))) { sb.AddLine(new HtmlTag("span").InnerHtml(repeater.LabelHtml ?? repeater.LabelText.FormatHtml()).ToHtml()); using (sb.SurroundLine(new HtmlTag("span", repeater.Compose("shownButton")).Class("pull-right"))) { sb.AddLine(EntityButtonHelper.Create(helper, repeater, btn: false)); sb.AddLine(EntityButtonHelper.Find(helper, repeater, btn: false)); } } using (sb.SurroundLine(new HtmlTag("div").Class("row rule"))) { for (int i = 0; i < 12; i++) { using (sb.SurroundLine(new HtmlTag("div").Class("col-sm-1"))) using (sb.SurroundLine(new HtmlTag("div").Class("ruleItem"))) { } } } using (sb.SurroundLine(new HtmlTag("div").Id(repeater.Compose(EntityRepeaterKeys.ItemsContainer)))) { if (repeater.UntypedValue != null) { foreach (var gr in TypeContextUtilities.TypeElementContext((TypeContext<MList<T>>)repeater.Parent).GroupBy(a => a.Value.Row).OrderBy(a => a.Key)) { using (sb.SurroundLine(new HtmlTag("div").Class("row separator-row"))) { } using (sb.SurroundLine(new HtmlTag("div").Class("row items-row"))) { var lastEnd = 0; foreach (var itemTC in gr.OrderBy(a => a.Value.StartColumn)) { helper.ViewData[LastEnd] = lastEnd; sb.Add(EntityBaseHelper.RenderContent(helper, itemTC, RenderContentMode.Content, repeater)); lastEnd = itemTC.Value.StartColumn + itemTC.Value.Columns; } } } helper.ViewData.Remove("lastEnd"); } using (sb.SurroundLine(new HtmlTag("div").Class("row separator-row"))) { } } sb.AddLine(repeater.ConstructorScript(DashboardClient.GridRepeater, "GridRepeater")); } return sb.ToHtml(); }