Exemplo n.º 1
0
        private static void DiffLine(HtmlStringBuilder sb, IEnumerable <StringDistance.DiffPair <string> > list)
        {
            foreach (var gr in list.GroupWhenChange(a => a.Action))
            {
                string text = gr.Select(a => a.Value).ToString("");

                if (gr.Key == StringDistance.DiffAction.Equal)
                {
                    sb.Add(HtmlTag.Encode(text));
                }
                else
                {
                    var color =
                        gr.Key == StringDistance.DiffAction.Added ? "#72F272" :
                        gr.Key == StringDistance.DiffAction.Removed ? "#FF8B8B" :
                        throw new InvalidOperationException();

                    sb.Add(new HtmlTag("span").Attr("style", "background:" + color).SetInnerText(text));
                }
            }

            sb.AddLine();
        }
Exemplo n.º 2
0
        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());
        }