MvcHtmlString IWidget.ToHtml(HtmlHelper helper) { if (Isolation == null) return MvcHtmlString.Empty; HtmlStringBuilder sb = new HtmlStringBuilder(); sb.Add(helper.HiddenLite(TypeContextUtilities.Compose(Prefix, "Isolation"), Isolation)); sb.Add(new HtmlTag("span").Class("sf-quicklinks badge").SetInnerText(Isolation.ToString())); //sb.Add(new MvcHtmlString("<script>" + IsolationClient.Module["addIsolationPrefilter"](Isolation.Key()) + "</script>")); return sb.ToHtml(); }
public static MvcHtmlString QueryTokenDNBuilder(this HtmlHelper helper, TypeContext<QueryTokenEntity> ctx, QueryTokenBuilderSettings settings) { if (ctx.Value.Try(qt => qt.ParseException) != null) { HtmlStringBuilder sb = new HtmlStringBuilder(); sb.Add(new HtmlTag("div").Class("ui-state-error").SetInnerText(ctx.Value.ParseException.Message).ToHtml()); sb.Add(new HtmlTag("pre").SetInnerText(ctx.Value.TokenString).ToHtml()); sb.Add(helper.QueryTokenBuilder(null, ctx, settings)); return sb.ToHtml(); } else { return helper.QueryTokenBuilder(ctx.Value.Try(ct => ct.Token), ctx, settings); } }
public static MvcHtmlString Diff(string oldStr, string newStr) { StringDistance sd = new StringDistance(); var dif = sd.DiffText(oldStr, newStr); HtmlStringBuilder sb = new HtmlStringBuilder(); foreach (var line in dif) { if (line.Action == StringDistance.DiffAction.Removed) { using (sb.Surround(new HtmlTag("span").Attr("style", "background-color:#FFD1D1"))) DiffLine(sb, line.Value); } if (line.Action == StringDistance.DiffAction.Added) { using (sb.Surround(new HtmlTag("span").Attr("style", "background-color:#CEF3CE"))) DiffLine(sb, line.Value); } else if (line.Action == StringDistance.DiffAction.Equal) { if (line.Value.Count == 1) { using (sb.Surround(new HtmlTag("span"))) DiffLine(sb, line.Value); } else { using (sb.Surround(new HtmlTag("span").Attr("style", "background-color:#FFD1D1"))) DiffLine(sb, line.Value.Where(a => a.Action == StringDistance.DiffAction.Removed || a.Action == StringDistance.DiffAction.Equal)); using (sb.Surround(new HtmlTag("span").Attr("style", "background-color:#CEF3CE"))) DiffLine(sb, line.Value.Where(a => a.Action == StringDistance.DiffAction.Added || a.Action == StringDistance.DiffAction.Equal)); } } } return(sb.ToHtml()); }
public ContentResult SelectedItemsContextMenu(string webQueryName, string implementationsKey, string prefix) { var lites = this.ParseLiteKeys<Entity>(); if (lites.IsEmpty()) return Content(""); object queryName = Finder.ResolveQueryName(webQueryName); Implementations implementations = implementationsKey == "[All]" ? Implementations.ByAll : Implementations.By(implementationsKey.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(t => Navigator.ResolveType(t)).ToArray()); var items = ContextualItemsHelper.GetContextualItemListForLites(new SelectedItemsMenuContext { Url = RouteHelper.New(), ControllerContext = this.ControllerContext, Lites = lites, QueryName = queryName, Implementations = implementations, Prefix = prefix, }); if (items.IsNullOrEmpty()) return Content(""); var sb = new HtmlStringBuilder(items.Select(mi => mi.ToHtml())); sb.Add(new MvcHtmlString(@"<script>$(function(){ $('[data-toggle=""tooltip""]').tooltip({}); });</script>")); return Content(sb.ToHtml().ToString()); }
public static Widget CreateWidget(WidgetContext ctx) { var ident = (Entity)ctx.Entity; var url = RouteHelper.New().Action((AlertController ac) => ac.AlertsCount()); var alertList = new[] { new { Count = CountAlerts(ident.ToLite(), "Attended"), Property = "Attended", AlertClass = "sf-alert-attended", Title = AlertMessage.Alerts_Attended.NiceToString() }, new { Count = CountAlerts(ident.ToLite(), "Alerted"), Property = "Alerted", AlertClass = "sf-alert-alerted", Title = AlertMessage.Alerts_NotAttended.NiceToString() }, new { Count = CountAlerts(ident.ToLite(), "Future"), Property = "Future", AlertClass = "sf-alert-future", Title = AlertMessage.Alerts_Future.NiceToString() }, }; var items = alertList.Select(a => new MenuItem(ctx.Prefix, "sfAlertExplore_" + a.Property) { OnClick = AlertClient.Module["exploreAlerts"](ctx.Prefix, GetFindOptions(ident, a.Property).ToJS(ctx.Prefix, "alerts"), url), CssClass = "sf-alert-view", Html = new HtmlTag("span").Class("sf-alert-count-label").Class(a.AlertClass).Class(a.Count > 0 ? "sf-alert-active" : null).InnerHtml((a.Title + ": ").EncodeHtml()).ToHtml().Concat( new HtmlTag("span").Class(a.AlertClass).Class(a.Count > 0 ? "sf-alert-active" : null).SetInnerText(a.Count.ToString())) }).Cast<IMenuItem>().ToList(); items.Add(new MenuItemSeparator()); items.Add(new MenuItem(ctx.Prefix, "sfAlertCreate") { CssClass = "sf-alert-create", OnClick = AlertClient.Module["createAlert"](JsFunction.Event, ctx.Prefix, AlertOperation.CreateAlertFromEntity.Symbol.Key, url), Text = AlertMessage.CreateAlert.NiceToString(), }); HtmlStringBuilder label = new HtmlStringBuilder(); int count = alertList.Length; for(int i = 0; i < count; i++) { var a = alertList[i]; label.Add(new HtmlTag("span") .Class("sf-widget-count") .Class(a.AlertClass) .Class(a.Count > 0 ? "sf-alert-active" : null) .SetInnerText(a.Count.ToString()) .Attr("title", a.Title) .ToHtml()); if (i < count - 1) { label.Add(new HtmlTag("span") .Class("sf-alerts-count-separator") .SetInnerText(" - ") .ToHtml()); } } return new Widget { Title = AlertMessage.Alerts.NiceToString(), IconClass = "glyphicon glyphicon-bell", Class = "sf-alerts-toggler", Id = TypeContextUtilities.Compose(ctx.Prefix, "alertsWidget"), Active = alertList.Any(a => a.Count > 0), Html = label.ToHtml(), Items = items, }; }
internal static MvcHtmlString InternalFileLine(this HtmlHelper helper, FileLine fileLine) { if (!fileLine.Visible) { return(MvcHtmlString.Empty); } IFile value = fileLine.GetFileValue(); HtmlStringBuilder sbg = new HtmlStringBuilder(); using (sbg.SurroundLine(new HtmlTag("div").Id(fileLine.Prefix).Class("sf-field SF-control-container"))) { sbg.AddLine(new HtmlTag("link").Attrs(new { rel = "stylesheet", type = "text/css", href = RouteHelper.New().Content("~/Files/Content/Files.css") }).ToHtmlSelf()); if (value != null) { sbg.AddLine(helper.Div(fileLine.Compose(EntityBaseKeys.Entity), null, "", new Dictionary <string, object> { { "style", "display:none" } })); } fileLine.ValueHtmlProps.AddCssClass("form-control"); bool hasEntity = value != null && value.FileName.HasText(); using (sbg.SurroundLine(new HtmlTag("div", fileLine.Compose("DivOld")).Attr("style", "display:" + (hasEntity ? "block" : "none")))) { HtmlStringBuilder sb = new HtmlStringBuilder(); using (sb.SurroundLine(new HtmlTag("div", fileLine.Compose("inputGroup")).Class("input-group"))) { if (fileLine.Download != DownloadBehaviour.None) { sb.AddLine(helper.Href(fileLine.Compose(EntityBaseKeys.Link), value?.FileName, hasEntity ? FilesClient.GetDownloadUrl(value) : null, value?.FileName, "form-control file-control", fileLine.Download == DownloadBehaviour.View ? null : new Dictionary <string, object> { { "download", value?.FileName } })); } else { sb.AddLine(helper.Span(fileLine.Compose(EntityBaseKeys.ToStr), value?.FileName ?? "", "form-control file-control", null)); } if (fileLine.Type.IsEmbeddedEntity()) { sb.AddLine(helper.Hidden(fileLine.Compose(EntityBaseKeys.EntityState), value?.Let(f => Navigator.Manager.SerializeEntity((ModifiableEntity)f)))); } using (sb.SurroundLine(new HtmlTag("span", fileLine.Compose("shownButton")).Class("input-group-btn"))) { sb.AddLine(EntityButtonHelper.Remove(helper, fileLine, btn: true)); } } sbg.AddLine(helper.FormGroup(fileLine, fileLine.Download == DownloadBehaviour.None ? fileLine.Compose(EntityBaseKeys.Link) : fileLine.Compose(EntityBaseKeys.ToStr), fileLine.LabelHtml ?? fileLine.LabelText.FormatHtml(), sb.ToHtml())); } using (sbg.SurroundLine(new HtmlTag("div", fileLine.Compose("DivNew")) .Class("sf-file-line-new") .Attr("style", "display:" + (hasEntity ? "none" : "block")))) { HtmlStringBuilder sb = new HtmlStringBuilder(); sb.AddLine(helper.HiddenRuntimeInfo(fileLine)); if (!fileLine.ReadOnly) { sb.AddLine(MvcHtmlString.Create("<input type='file' id='{0}' name='{0}' class='form-control'/>".FormatWith(fileLine.Compose(FileLineKeys.File)))); sb.AddLine(MvcHtmlString.Create("<img src='{0}' id='{1}_loading' alt='loading' style='display:none'/>".FormatWith(RouteHelper.New().Content("~/Files/Images/loading.gif"), fileLine.Prefix))); } sbg.AddLine(helper.FormGroup(fileLine, fileLine.Compose(FileLineKeys.File), fileLine.LabelHtml ?? fileLine.LabelText.FormatHtml(), sb.ToHtml())); } if (!fileLine.ReadOnly) { sbg.AddLine(fileLine.ConstructorScript(FilesClient.Module, "FileLine")); } } return(sbg.ToHtml()); }
public static Widget CreateWidget(WidgetContext ctx) { var ident = (Entity)ctx.Entity; var url = RouteHelper.New().Action((AlertController ac) => ac.AlertsCount()); var alertList = new[] { new { Count = CountAlerts(ident.ToLite(), "Attended"), Property = "Attended", AlertClass = "sf-alert-attended", Title = AlertMessage.Alerts_Attended.NiceToString() }, new { Count = CountAlerts(ident.ToLite(), "Alerted"), Property = "Alerted", AlertClass = "sf-alert-alerted", Title = AlertMessage.Alerts_NotAttended.NiceToString() }, new { Count = CountAlerts(ident.ToLite(), "Future"), Property = "Future", AlertClass = "sf-alert-future", Title = AlertMessage.Alerts_Future.NiceToString() }, }; var items = alertList.Select(a => new MenuItem(ctx.Prefix, "sfAlertExplore_" + a.Property) { OnClick = AlertClient.Module["exploreAlerts"](ctx.Prefix, GetFindOptions(ident, a.Property).ToJS(ctx.Prefix, "alerts"), url), CssClass = "sf-alert-view", Html = new HtmlTag("span").Class("sf-alert-count-label").Class(a.AlertClass).Class(a.Count > 0 ? "sf-alert-active" : null).InnerHtml((a.Title + ": ").EncodeHtml()).ToHtml().Concat( new HtmlTag("span").Class(a.AlertClass).Class(a.Count > 0 ? "sf-alert-active" : null).SetInnerText(a.Count.ToString())) }).Cast <IMenuItem>().ToList(); items.Add(new MenuItemSeparator()); items.Add(new MenuItem(ctx.Prefix, "sfAlertCreate") { CssClass = "sf-alert-create", OnClick = AlertClient.Module["createAlert"](JsFunction.Event, ctx.Prefix, AlertOperation.CreateAlertFromEntity.Symbol.Key, url), Text = AlertMessage.CreateAlert.NiceToString(), }); HtmlStringBuilder label = new HtmlStringBuilder(); int count = alertList.Length; for (int i = 0; i < count; i++) { var a = alertList[i]; label.Add(new HtmlTag("span") .Class("sf-widget-count") .Class(a.AlertClass) .Class(a.Count > 0 ? "sf-alert-active" : null) .SetInnerText(a.Count.ToString()) .Attr("title", a.Title) .ToHtml()); if (i < count - 1) { label.Add(new HtmlTag("span") .Class("sf-alerts-count-separator") .SetInnerText(" - ") .ToHtml()); } } return(new Widget { Title = AlertMessage.Alerts.NiceToString(), IconClass = "glyphicon glyphicon-bell", Class = "sf-alerts-toggler", Id = TypeContextUtilities.Compose(ctx.Prefix, "alertsWidget"), Active = alertList.Any(a => a.Count > 0), Html = label.ToHtml(), Items = items, }); }