private static IEnumerable <Vertical> OrdinarySlideToVerticals(string courseId, Slide slide, string slideUrl, string solutionsUrl, Dictionary <string, string> videoGuids, string ltiId) { var componentIndex = 0; var components = new List <Component>(); while (componentIndex < slide.Blocks.Length) { var blocks = slide.Blocks.Skip(componentIndex).TakeWhile(x => !(x is YoutubeBlock) && !(x is ExerciseBlock)).ToList(); if (blocks.Count != 0) { var innerComponents = new List <Component>(); foreach (var block in blocks) { var component = block.ToEdxComponent("", slide, componentIndex); innerComponents.Add(component); componentIndex++; } var displayName = componentIndex == blocks.Count ? slide.Title : ""; var header = displayName == "" ? "" : "<h2>" + displayName + "</h2>"; var slideComponent = new HtmlComponent { DisplayName = displayName, UrlName = slide.Guid + componentIndex, Filename = slide.Guid + componentIndex, Source = header + string.Join("", innerComponents.Select(x => x.AsHtmlString())), Subcomponents = innerComponents.ToArray() }; components.Add(slideComponent); } if (componentIndex >= slide.Blocks.Length) { break; } var exerciseBlock = slide.Blocks[componentIndex] as ExerciseBlock; var otherComponent = exerciseBlock != null ? exerciseBlock.GetExerciseComponent(componentIndex == 0?slide.Title : "”пражнение", slide, componentIndex, string.Format(slideUrl, courseId, slide.Index), ltiId) : ((YoutubeBlock)slide.Blocks[componentIndex]).GetVideoComponent(componentIndex == 0 ? slide.Title : "", slide, componentIndex, videoGuids); components.Add(otherComponent); componentIndex++; } var solutionComponents = new List <Component>(); foreach (var result in slide.Blocks.OfType <ExerciseBlock>()) { var comp = result.GetSolutionsComponent("–ешени¤", slide, componentIndex, string.Format(solutionsUrl, courseId, slide.Index), ltiId); solutionComponents.Add(comp); componentIndex++; } yield return(new Vertical(slide.Guid, slide.Title, components.ToArray())); if (solutionComponents.Count != 0) { yield return(new Vertical(slide.Guid + "0", "–ешени¤", solutionComponents.ToArray())); } }
/// <summary> /// Creates a Bootstrap icon /// </summary> /// <param name="icon">Icon to be created</param> /// <param name="htmlAttributes">[Optional] Any extra HTML attributes</param> /// <returns>A Bootstrap icon</returns> public static IHtmlComponent CreateIcon(EBootstrapIcon icon, object htmlAttributes = null) { NameValueCollection htmlAttribs = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes); List <string> cssClasses = new List <string>(); if (htmlAttribs.ContainsKey("class")) { cssClasses.AddRange(htmlAttribs["class"].Split(' ')); htmlAttribs.Remove("class"); } switch (WebExtrasSettings.BootstrapVersion) { case EBootstrapVersion.V2: cssClasses.Add("icon-" + icon.ToString().ToLowerInvariant().Replace("_", "-")); break; case EBootstrapVersion.V3: cssClasses.Add("glyphicon glyphicon-" + icon.ToString().ToLowerInvariant().Replace("_", "-")); break; default: throw new BootstrapVersionException(); } HtmlComponent i = new HtmlComponent(EHtmlTag.I); i.CssClasses.AddRange(cssClasses); return(i); }
/// <summary> /// Create special buttons /// </summary> /// <typeparam name="T">Generic type to be used. This type must implement IExtendedHtmlString</typeparam> /// <param name="html">Current HTML element</param> /// <param name="type">Gumby button type</param> /// <param name="sizeOrstyle">Gumby button size/style</param> /// <returns>A Gumby button styled hyperlink</returns> /// <exception cref="GumbyThemeException">Thrown when a valid Gumby framework /// theme is not selected</exception> public static IExtendedHtmlString AsButton <T>(this T html, EGumbyButton type, params EGumbyButtonStyle[] sizeOrstyle) where T : IExtendedHtmlString { if (WebExtrasSettings.GumbyTheme == EGumbyTheme.None) { throw new GumbyThemeException(); } if (!WebExtrasMvcUtil.CanDisplayAsButton(html)) { throw new InvalidUsageException("The AsButton decorator can only be used with Button and Hyperlink extensions"); } List <string> classes = new List <string> { "btn", type.ToString().ToLowerInvariant() }; // if a style was specified then don't add the theme class EGumbyButtonStyle[] styles = { EGumbyButtonStyle.Oval, EGumbyButtonStyle.Rounded, EGumbyButtonStyle.Squared, EGumbyButtonStyle.Pill_Left, EGumbyButtonStyle.Pill_Right }; int styleCnt = sizeOrstyle.Where(styles.Contains).Count(); if (styleCnt == 0) { classes.Add(WebExtrasSettings.GumbyTheme.ToString().ToLowerInvariant()); } // if no size was specified set as medium EGumbyButtonStyle[] sizes = { EGumbyButtonStyle.XLarge, EGumbyButtonStyle.Large, EGumbyButtonStyle.Medium, EGumbyButtonStyle.Small }; int sizeCnt = sizeOrstyle.Where(sizes.Contains).Count(); if (sizeCnt == 0) { classes.Add("medium"); } HtmlComponent div = new HtmlComponent(EHtmlTag.Div); div.Attributes["class"] = string.Join(" ", classes .Concat(sizeOrstyle.Select(s => s.ToString().ToLowerInvariant().Replace('_', '-')))); div.AppendTags.Add(html.Component); return(new ExtendedHtmlString(div)); }
public ActionResult AddOrEdit(HtmlComponentViewModel comp) { using (var db = new GenerateHtmlDbContext()) { if (comp.Id == 0) { var obj = new HtmlComponent { Name = comp.Name }; db.HtmlComponents.Add(obj); db.SaveChanges(); return(Json(new { success = true, message = "Saved successfully!!!" }, JsonRequestBehavior.AllowGet)); } else { var obj = new HtmlComponent { Name = comp.Name }; db.Entry(obj).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Updated successfully!!!" }, JsonRequestBehavior.AllowGet)); } } }
public HtmlComponent addElement() { var comp = new HtmlComponent(); elements.Add(comp); return(comp); }
/// <summary> /// Create a label with the required field asterix /// </summary> /// <typeparam name="TModel">Type to be scanned</typeparam> /// <typeparam name="TValue">Property to be scanned</typeparam> /// <param name="html">Htmlhelper extension</param> /// <param name="expression">The property lamba expression</param> /// <param name="labelText">Label text to be shown</param> /// <param name="htmlAttributes">[Optional] Extra html attributes</param> /// <returns>A label with the required field asterix</returns> public static IExtendedHtmlString RequiredFieldLabelFor <TModel, TValue>(this HtmlHelpers <TModel> html, Expression <Func <TModel, TValue> > expression, string labelText, object htmlAttributes = null) { if (expression == null) { throw new ArgumentNullException("expression"); } MemberExpression exp = expression.Body as MemberExpression; if (exp == null) { throw new ArgumentException("Unable to parse property lambda expression", "expression"); } HtmlComponent label = new HtmlComponent(EHtmlTag.Label, htmlAttributes); label.Attributes["id"] = WebExtrasUtil.GetFieldIdFromExpression(exp); label.Attributes["name"] = WebExtrasUtil.GetFieldNameFromExpression(exp); label.InnerHtml = labelText; if (exp.Member.GetCustomAttributes(typeof(RequiredAttribute), true).Any()) { HtmlComponent span = new HtmlComponent(EHtmlTag.Span); span.CssClasses.Add("required"); span.InnerHtml = " *"; label.AppendTags.Add(span); } return(new ExtendedHtmlString(label)); }
/// <summary> /// Create bootstrap 3 tags /// </summary> /// <param name="htmlAttributes">Extra HTML attributes</param> private void CreateBootstrap3Tags(object htmlAttributes) { var defaultAttribs = new Dictionary <string, string> { { "type", "text" }, { "id", WebExtrasUtil.GetFieldIdFromExpression(m_propertyExpression) }, { "name", WebExtrasUtil.GetFieldNameFromExpression(m_propertyExpression) } }; DataTypeAttribute[] customAttribs = (DataTypeAttribute[])m_propertyExpression.Member.GetCustomAttributes(typeof(DataTypeAttribute), false); if (customAttribs.Length > 0) { switch (customAttribs[0].DataType) { case DataType.EmailAddress: defaultAttribs["type"] = "email"; break; case DataType.Password: defaultAttribs["type"] = "password"; break; case DataType.MultilineText: defaultAttribs["type"] = "textarea"; break; } } Dictionary <string, string> attribs = WebExtrasUtil .AnonymousObjectToHtmlAttributes(htmlAttributes) .ToDictionary() .Merge(defaultAttribs) .ToDictionary(k => k.Key, v => v.Value); HtmlComponent input; if (m_selectListItems != null) { input = new HtmlSelect(m_selectListItems, attribs); } else if (m_textAreaDimensions != null || attribs.ContainsValue("textarea")) { attribs.Remove("type"); input = new HtmlComponent(EHtmlTag.TextArea, attribs); } else { input = new HtmlComponent(EHtmlTag.Input, attribs); } input.CssClasses.Add("form-control"); Input = input; InputGroup = new HtmlComponent(EHtmlTag.Div); InputGroup.CssClasses.Add("input-group"); InputGroup.AppendTags.Add(input); }
/// <summary> /// Creates an alert /// </summary> /// <param name="type">Type of alert</param> /// <param name="message">Alert message</param> /// <param name="title">Title/Heading of the alert</param> /// <param name="icon">Icon to be rendered with title/heading</param> private void CreateAlert(EMessage type, string message, string title, IHtmlComponent icon) { CssClasses.Add(type.GetStringValue()); HtmlComponent bc = new HtmlComponent(EHtmlTag.B) { InnerHtml = title ?? string.Empty }; if (icon != null) { bc.PrependTags.Add(icon); } if (WebExtrasSettings.CssFramework != ECssFramework.JQueryUI) { CssClasses.Add("alert"); Button closeBtn = new Button(EButton.Regular, "×", string.Empty); closeBtn.CssClasses.Add("close"); closeBtn.Attributes["data-dismiss"] = "alert"; PrependTags.Add(closeBtn); PrependTags.Add(bc); InnerHtml = (!string.IsNullOrWhiteSpace(title) || icon != null) ? WebExtrasSettings.HTMLSpace + message : message; } else { HtmlComponent div = new HtmlComponent(EHtmlTag.Div); switch (type) { case EMessage.Error: div.CssClasses.Add("ui-state-error"); break; case EMessage.Information: case EMessage.Warning: div.CssClasses.Add("ui-state-highlight"); break; case EMessage.Success: div.CssClasses.Add("ui-state-success"); break; } div.CssClasses.Add("ui-corner-all"); div.PrependTags.Add(bc); div.InnerHtml = (!string.IsNullOrWhiteSpace(title) || icon != null) ? WebExtrasSettings.HTMLSpace + message : message; PrependTags.Add(div); } Type = type; }
IRegionDefinition IRegionDefinition.Html(string textAssetName, string defaultHtml) { var htmlComponent = new HtmlComponent(_componentDependenciesFactory); htmlComponent.Html(textAssetName, defaultHtml); _region.Content = htmlComponent; return(this); }
ILayoutDefinition ILayoutDefinition.Html(string zoneName, string textAssetName, string defaultHtml) { var htmlComponent = new HtmlComponent(_componentDependenciesFactory); htmlComponent.Html(textAssetName, defaultHtml); _regionComponents[zoneName] = htmlComponent; return(this); }
/// <summary> /// Renders a JQuery UI icon /// </summary> /// <param name="html">Current Html helper object</param> /// <param name="icon">JQuery UI icon</param> /// <param name="type">JQUery UI icon type</param> /// <param name="htmlAttributes">[Optional] Extra HTML attributes</param> /// <returns>A JQuery UI icon</returns> public static IExtendedHtmlString Icon(this HtmlHelper html, EJQueryUIIcon icon, EJQueryUIIconType type, object htmlAttributes = null) { HtmlComponent span = new HtmlComponent(EHtmlTag.Span, htmlAttributes); span.CssClasses.Add("ui-icon"); span.CssClasses.Add(string.Format("ui-icon-{0}", icon.ToString().ToLowerInvariant().Replace("_", "-"))); span.CssClasses.Add(type.GetStringValue()); return(new ExtendedHtmlString(span)); }
/// <summary> /// Add an icon /// </summary> /// <typeparam name="T">Generic type to be used. This type must implement IExtendedHtmlString</typeparam> /// <param name="html">Current html element</param> /// <param name="icon">Icon to be rendered</param> /// <param name="htmlAttributes">[Optional] Extra html attributes</param> /// <returns>Html element with icon added</returns> public static T AddIcon <T>(this T html, EJQueryUIIcon icon, object htmlAttributes = null) where T : IExtendedHtmlString { HtmlComponent span = new HtmlComponent(EHtmlTag.Span, htmlAttributes); span.CssClasses.Add("ui-icon"); span.CssClasses.Add(string.Format("ui-icon-{0}", icon.ToString().ToLowerInvariant().Replace("_", "-"))); html.Component.PrependTags.Add(span); return(html); }
/// <summary> /// Creates a HTML hyperlink from given text and URL /// </summary> /// <param name="html">Current html helper object</param> /// <param name="linkText">Link text</param> /// <param name="url">Link URL</param> /// <param name="htmlAttributes">[Optional] Extra HTML attributes</param> /// <returns>HTML hyperlink</returns> public static IExtendedHtmlString Hyperlink( this HtmlHelpers html, string linkText, string url, object htmlAttributes = null) { HtmlComponent a = new HtmlComponent(EHtmlTag.A, htmlAttributes); a.Attributes["href"] = url; a.InnerHtml = linkText; return(new ExtendedHtmlString(a)); }
/// <summary> /// Creates a button /// </summary> /// <param name="html">Current HTML helpers</param> /// <param name="type">Button type</param> /// <param name="text">Button text</param> /// <param name="htmlAttributes">[Optional] Any extra html attributes</param> /// <returns>A HTML button element</returns> public static IExtendedHtmlString Button(this HtmlHelpers html, EButton type, string text, object htmlAttributes = null) { HtmlComponent component = new HtmlComponent(EHtmlTag.Button, htmlAttributes); component.Attributes["type"] = type.GetStringValue(); component.InnerHtml = text; if (type == EButton.Cancel) { component.Attributes["onclick"] = "javascript:window.history.back()"; } return(new ExtendedHtmlString(component)); }
IPageDefinition IPageDefinition.RegionHtml(string regionName, string textAssetName, string defaultHtml) { if (string.IsNullOrEmpty(regionName)) { throw new PageBuilderException("You must provide a region name when configuring page regions"); } var component = new HtmlComponent(_componentDependenciesFactory); component.Html(textAssetName, defaultHtml); _page.PopulateRegion(regionName, component); return(this); }
/// <summary> /// Creates an HTML image /// </summary> /// <param name="html">Current HTML helper object</param> /// <param name="src">Image location</param> /// <param name="altText">Image alt text</param> /// <param name="title">Image title</param> /// <param name="htmlAttributes">[Optional] Extra HTML attributes</param> /// <returns>An HTML image</returns> public static IExtendedHtmlString Image( this HtmlHelpers html, string src, string altText, string title, object htmlAttributes = null) { HtmlComponent img = new HtmlComponent(EHtmlTag.Img, htmlAttributes); img.Attributes["src"] = src; img.Attributes["title"] = title; img.Attributes["alt"] = altText; return(new ExtendedHtmlString(img)); }
/// <summary> /// Creates an icon /// </summary> /// <param name="icon">Icon to be created</param> /// <param name="htmlAttributes">[Optional] Any extras HTML attributes</param> /// <returns>A Gumby icon</returns> public static IHtmlComponent CreateIcon(EGumbyIcon icon, object htmlAttributes = null) { NameValueCollection attrsDictionary = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes); HtmlComponent i = new HtmlComponent(EHtmlTag.I); i.CssClasses.Add("icon-" + icon.ToString().ToLowerInvariant().Replace('_', '-')); foreach (string key in attrsDictionary.Keys) { i.Attributes[key] = attrsDictionary[key]; } return(i); }
/// <summary> /// Add an icon /// </summary> /// <typeparam name="T">Generic type to be used. This type must implement IExtendedHtmlString</typeparam> /// <param name="html">Current HTML element</param> /// <param name="icon">Gumby icon to be added</param> /// <param name="iconLeft">[Optional] Flag indicating whether to place icon on left. Defaults to true</param> /// <returns>HTML element with icon added</returns> public static T AddIcon <T>(this T html, EGumbyIcon icon, bool iconLeft = true) where T : IExtendedHtmlString { HtmlComponent ic = new HtmlComponent(EHtmlTag.I); ic.CssClasses.Add(icon.GetStringValue()); if (iconLeft) { html.Component.PrependTags.Add(ic); } else { html.Component.AppendTags.Add(ic); } return(html); }
/// <summary> /// Creates a Bootstrap Font-Awesome icon /// </summary> /// <param name="icon">Icon to be rendered</param> /// <param name="size">Icon size</param> /// <param name="htmlAttributes">Extra HTML attributes</param> /// <returns>A Bootstrap icon</returns> /// <exception cref="FontAwesomeVersionException">Thrown when a valid FontAwesome /// icon library version is not selected</exception> public static IHtmlComponent CreateIcon(EFontAwesomeIcon icon, EFontAwesomeIconSize size = EFontAwesomeIconSize.Normal, object htmlAttributes = null) { NameValueCollection attrsDictionary = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes); List <string> cssClasses = new List <string>(); if (attrsDictionary.ContainsKey("class")) { cssClasses.AddRange(attrsDictionary["class"].Split(' ')); attrsDictionary.Remove("class"); } string prefix; switch (WebExtrasSettings.FontAwesomeVersion) { case EFontAwesomeVersion.V3: prefix = "icon-"; break; case EFontAwesomeVersion.V4: prefix = "fa fa-"; break; default: throw new FontAwesomeVersionException(); } cssClasses.Add(prefix + icon.ToString().ToLowerInvariant().Replace("_", "-")); if (size != EFontAwesomeIconSize.Normal) { cssClasses.Add(prefix + size.GetStringValue()); } HtmlComponent i = new HtmlComponent(EHtmlTag.I); i.CssClasses.AddRange(cssClasses); foreach (string key in attrsDictionary.Keys) { i.Attributes[key] = attrsDictionary[key]; } return(i); }
/// <summary> /// Create a HTML hyperlink with an image /// </summary> /// <param name="html">Current HTML helper object</param> /// <param name="src">Image location</param> /// <param name="altText">Image alt text</param> /// <param name="title">Image title</param> /// <param name="url">Link URL</param> /// <param name="htmlAttributes"> /// [Optional] Extra html attributes for the image link. By default /// these attributes will be applied to the A tag only. /// </param> /// <returns>HTML image hyperlink</returns> public static IExtendedHtmlString Imagelink( this HtmlHelpers html, string src, string altText, string title, string url, object htmlAttributes = null) { object linkAttributes = null, imgAttributes = null; if (htmlAttributes != null) { // try to get the html attributes for the link and img IDictionary <string, object> attr = htmlAttributes .GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Select(p => new KeyValuePair <string, object>(p.Name, p.GetValue(htmlAttributes, null))) .ToDictionary(k => k.Key, v => v.Value); if (attr.ContainsKey("a")) { linkAttributes = attr["a"]; } if (attr.ContainsKey("img")) { imgAttributes = attr["img"]; } } // create <img> tag HtmlComponent img = new HtmlComponent(EHtmlTag.Img, imgAttributes); img.Attributes["src"] = src; img.Attributes["alt"] = altText; img.Attributes["title"] = title; // create <a> tag HtmlComponent link = new HtmlComponent(EHtmlTag.A, linkAttributes); link.Attributes["href"] = url; link.AppendTags.Add(img); return(new ExtendedHtmlString(link)); }
/// <summary> /// Convert the current hyperlink to a label /// </summary> /// <returns>The converted label</returns> public IExtendedHtmlString ToLabel() { HtmlComponent label = new HtmlComponent(EHtmlTag.Label) { InnerHtml = InnerHtml }; label.AppendTags.AddRange(AppendTags); label.PrependTags.AddRange(PrependTags); foreach (string key in Attributes.Keys) { label.Attributes.Add(key, Attributes[key]); } label.Attributes.Remove("href"); label.CssClasses.AddRange(CssClasses); return(new ExtendedHtmlString(label)); }
/// <summary> /// Creates a jQuery UI icon /// </summary> /// <param name="icon">Icon to be created</param> /// <param name="htmlAttributes">[Optional] Any extra HTML attributes</param> /// <returns>A jQuery UI icon</returns> public static IHtmlComponent CreateIcon(EJQueryUIIcon icon, object htmlAttributes = null) { NameValueCollection rvd = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes); List <string> cssClasses = new List <string>(); if (rvd.ContainsKey("class")) { cssClasses.AddRange(rvd["class"].Split(' ')); rvd.Remove("class"); } cssClasses.Add("ui-icon"); cssClasses.Add("ui-icon-" + icon.ToString().ToLowerInvariant().Replace("_", "-")); HtmlComponent i = new HtmlComponent(EHtmlTag.I); i.CssClasses.AddRange(cssClasses); return(i); }
/// <summary> /// Create the Gumby navigation bar /// </summary> /// <param name="list">Navigation bar items</param> private void CreateNavBar(HtmlList list) { this["class"] = "row navbar metro"; Component.AppendTags.Add(list); // append the logo/brand is it was supplied if (Logo == null) { return; } HtmlComponent logoDiv = new HtmlComponent(EHtmlTag.Div); logoDiv.CssClasses.AddRange(Logo.CssClasses); Logo.CssClasses.Clear(); logoDiv.AppendTags.Add(Logo.Component); Component.PrependTags.Add(logoDiv); }
/// <summary> /// Constructor /// </summary> /// <param name="type">Progress bar type</param> /// <param name="percent">Percentage of completion for the progress bar</param> /// <param name="srText">[Optional] Custom text to be displayed in progress bar. Defaults to percentage complete</param> /// <param name="htmlAttributes">[Optional] Extra HTML attributes</param> public BootstrapProgressBar(EBootstrapProgressBar type, int percent, string srText = null, object htmlAttributes = null) : base(EHtmlTag.Div, htmlAttributes) { Percent = percent; this["class"] += "progress"; HtmlComponent inner = new HtmlComponent(EHtmlTag.Div); switch (WebExtrasSettings.BootstrapVersion) { case EBootstrapVersion.None: throw new BootstrapVersionException(); case EBootstrapVersion.V2: inner.Attributes["class"] = string.Format("bar bar-{0}", type.ToString().ToLowerInvariant()); break; case EBootstrapVersion.V3: inner.Attributes["class"] = string.Format("progress-bar progress-bar-{0}", type.ToString().ToLowerInvariant()); inner.Attributes["role"] = "progressbar"; inner.Attributes["aria-valuenow"] = percent.ToString(CultureInfo.InvariantCulture); inner.Attributes["aria-valuemin"] = "0"; inner.Attributes["aria-valuemax"] = "100"; HtmlComponent spanInner = new HtmlComponent(EHtmlTag.Span); spanInner.InnerHtml = string.IsNullOrWhiteSpace(srText) ? percent + "% Complete" : srText; spanInner.Attributes["class"] = "sr-only"; inner.AppendTags.Add(spanInner); break; } Component.AppendTags.Add(inner); //this.m_tag.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); }
/// <summary> /// Add an icon /// </summary> /// <typeparam name="T">Generic type to be used. This type must implement IExtendedHtmlString</typeparam> /// <param name="html">Current html element</param> /// <param name="cssClasses">Css classes to be added</param> /// <param name="htmlAttributes">[Optional] Extra html attributes</param> /// <returns>Html element with icon added</returns> private static T AddIcon <T>(T html, IEnumerable <string> cssClasses, object htmlAttributes = null) where T : IExtendedHtmlString { IDictionary <string, object> rvd = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); List <string> finalClasses = new List <string>(cssClasses) { "wb-ext-addicon" }; if (rvd.ContainsKey("class")) { finalClasses.AddRange(rvd["class"].ToString().Split(' ')); rvd.Remove("class"); } HtmlComponent i = new HtmlComponent(EHtmlTag.I); i.CssClasses.AddRange(finalClasses); foreach (string key in rvd.Keys) { i.Attributes[key] = rvd[key].ToString(); } html.Component.PrependTags.Add(i); if (html.Component.Attributes.ContainsKey("style")) { html.Component.Attributes["style"] += ";text-decoration:none"; } else { html.Component.Attributes["style"] = "text-decoration:none"; } return(html); }
/// <summary> /// Creates the add on /// </summary> /// <param name="data">The html to be added in the addon</param> /// <param name="append">Whether we are appending the addon or prepending the addon</param> /// <returns>The updated form control</returns> private IFormComponent <TModel, TValue> CreateAddOn(string data, bool append = true) { HtmlComponent e = new HtmlComponent(WebExtrasSettings.DefaultTagForTextEncapsulation); e.CssClasses.Add("input-group-addon"); e.InnerHtml = data; if (append) { InputGroup.AppendTags.Add(e); } else { InputGroup.PrependTags.Add(e); } HtmlComponent lbl = new HtmlComponent(EHtmlTag.Label); lbl.Attributes["for"] = Input.Attributes["name"]; string html = Label != null ? Label.InnerHtml : string.Empty; if (append) { html += data; } else { html = data + html; } lbl.InnerHtml = html; Label = lbl; return(this); }
/// <summary> /// Creates a Bootstrap navigation bar from the given /// list of items /// </summary> /// <param name="list">Navigation bar items</param> private void CreateNavBar(HtmlList list) { list.Attributes["class"] = "nav navbar-nav"; Attributes["class"] = Type.GetStringValue(); switch (WebExtrasSettings.BootstrapVersion) { case EBootstrapVersion.V2: HtmlComponent innerNav = new HtmlComponent(EHtmlTag.Div); innerNav.Attributes["class"] = "navbar-inner"; if (Brand != null) { innerNav.PrependTags.Add(Brand.Component); } innerNav.AppendTags.Add(list); AppendTags.Add(innerNav); break; case EBootstrapVersion.V3: if (Brand != null) { Brand.Attributes["class"] = "navbar-brand"; PrependTags.Add(Brand.Component); } AppendTags.Add(list); break; default: throw new BootstrapVersionException(); } }
/// <summary> /// Add an icon /// </summary> /// <typeparam name="T">Generic type to be used. This type must implement IExtendedHtmlString</typeparam> /// <param name="html">Current html element</param> /// <param name="cssClasses">Css classes to be added</param> /// <param name="htmlAttributes">[Optional] Extra html attributes</param> /// <returns>HTML element with icon added</returns> private static T AddIcon <T>(T html, IEnumerable <string> cssClasses, object htmlAttributes = null) where T : IExtendedHtmlString { NameValueCollection rvd = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes); List <string> finalClasses = new List <string>(cssClasses); if (rvd.ContainsKey("class")) { finalClasses.AddRange(rvd["class"].Split(' ')); rvd.Remove("class"); } HtmlComponent i = new HtmlComponent(EHtmlTag.I); i.CssClasses.AddRange(finalClasses); foreach (string key in rvd.Keys) { i.Attributes[key] = rvd[key]; } // TODO: remove unnecessary conversion html.Component.PrependTags.Add(i); if (html.Component.Attributes.ContainsKey("style")) { html.Component.Attributes["style"] += ";text-decoration:none"; } else { html.Component.Attributes["style"] = "text-decoration:none"; } return(html); }
/// <summary> /// Creates a Bootstrap date time picker control /// </summary> /// <typeparam name="TModel">Type to be scanned</typeparam> /// <typeparam name="TValue">Property to be scanned</typeparam> /// <param name="html">HtmlHelper extension</param> /// <param name="expression">The property lamba expression</param> /// <param name="options">Date time picker options</param> /// <param name="htmlAttributes">Extra HTML attributes to be applied to the text box</param> /// <returns>A Bootstrap date time picker control</returns> public static IExtendedHtmlStringLegacy DateTimeTextBoxFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, PickerOptions options, object htmlAttributes = (IDictionary <string, object>) null) { MemberExpression exp = expression.Body as MemberExpression; PickerOptions pickerOptions = options.GetHashCode() == BootstrapSettings.DateTimePickerOptions.GetHashCode() ? options.DeepClone() : options; pickerOptions = pickerOptions.TryFontAwesomeIcons(); var model = ((DateTime?)ModelMetadata.FromLambdaExpression(expression, html.ViewData).Model); if (model.HasValue && model.Value > DateTime.MinValue) { pickerOptions.defaultDate = model; } string fieldId = WebExtrasUtil.GetFieldIdFromExpression(exp); string fieldName = WebExtrasUtil.GetFieldNameFromExpression(exp); // create the text box HtmlComponent input = new HtmlComponent(EHtmlTag.Input); var attribs = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes) .ToDictionary(k => k.Key, v => v.Value.ToString()); input.Attributes.Add(attribs); input.Attributes["type"] = "text"; input.Attributes["name"] = fieldName; if (input.Attributes.ContainsKey("class")) { input.Attributes["class"] += " form-control"; } else { input.Attributes["class"] = "form-control"; } // create icon HtmlComponent icon = new HtmlComponent(EHtmlTag.I); if (WebExtrasSettings.FontAwesomeVersion == EFontAwesomeVersion.V4) { icon.CssClasses.Add("fa fa-calendar"); } else if (WebExtrasSettings.FontAwesomeVersion == EFontAwesomeVersion.V3) { icon.CssClasses.Add("icon-calendar"); } else { icon.CssClasses.Add("glyphicon glyphicon-calendar"); } // create addon HtmlComponent addOn = new HtmlComponent(EHtmlTag.Span); addOn.CssClasses.Add("input-group-addon"); addOn.AppendTags.Add(icon); // create JSON dictionary of the picker options string op = pickerOptions.ToJson(new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); HtmlComponent script = new HtmlComponent(EHtmlTag.Script); script.Attributes["type"] = "text/javascript"; script.InnerHtml = "$(function(){ $('#" + fieldId + "').datetimepicker(" + op + "); });"; // create the final component IHtmlComponent control; if (pickerOptions.useAddonField.Equals(false)) { NullWrapperComponent wrapper = new NullWrapperComponent(); input.Attributes["id"] = fieldId; wrapper.Components.Add(input); wrapper.Components.Add(script); control = wrapper; } else { control = new HtmlComponent(EHtmlTag.Div); control.Attributes["id"] = fieldId; control.Attributes["class"] = "input-group date"; control.AppendTags.Add(input); control.AppendTags.Add(addOn); control.AppendTags.Add(script); } return(new HtmlElement(control)); }
public ActionResult AddOrEdit(HtmlComponentViewModel comp, HttpPostedFileBase styleSheetFile, HttpPostedFileBase scriptFile, HttpPostedFileBase imageFile, List <HttpPostedFileBase> mediaFiles) { try { using (var db = new GenerateHtmlDbContext()) { ViewBag.Category = db.HtmlComponentCategories.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }).ToList(); if (!ModelState.IsValid) { return(PartialView("~/Areas/Admin/Views/Home/_form.cshtml", comp)); } if (comp.Id == 0) { var obj = new HtmlComponent { Name = comp.Name, HtmlBody = comp.HtmlBody, ScriptPath = comp.ScriptPath, CssPath = comp.CssPath, ImageName = comp.ImageName, CategoryId = comp.CategoryId }; db.HtmlComponents.Add(obj); db.SaveChanges(); if (imageFile != null) { var imageFilePath = HandleUploadFile(obj.Id, imageFile, Utils.ImagePath); obj.ImageName = imageFilePath; } if (styleSheetFile != null && Path.GetExtension(styleSheetFile.FileName) == ".css") { var cssFilePath = HandleUploadFile(obj.Id, styleSheetFile, Utils.CssPath); obj.CssPath = cssFilePath; } if (scriptFile != null && Path.GetExtension(scriptFile.FileName) == ".js") { var scriptFilePath = HandleUploadFile(obj.Id, scriptFile, Utils.ScriptsPath); obj.ScriptPath = scriptFilePath; } if (mediaFiles.Any()) { HandleMediaImages(obj.Id, mediaFiles); } db.Entry(obj).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Lưu thành công." }, JsonRequestBehavior.AllowGet)); } else { var item = db.HtmlComponents.FirstOrDefault(x => x.Id == comp.Id); if (item != null) { item.Name = comp.Name; item.HtmlBody = comp.HtmlBody; item.CategoryId = comp.CategoryId; if (imageFile != null) { HandleDeleteFile(comp.ImageName, Utils.ImagePath); var imageFilePath = HandleUploadFile(item.Id, imageFile, Utils.ImagePath); item.ImageName = imageFilePath; } if (styleSheetFile != null && Path.GetExtension(styleSheetFile.FileName) == ".css") { HandleDeleteFile(comp.CssPath, Utils.CssPath); var cssFilePath = HandleUploadFile(item.Id, styleSheetFile, Utils.CssPath); item.CssPath = cssFilePath; } if (scriptFile != null && Path.GetExtension(scriptFile.FileName) == ".js") { HandleDeleteFile(comp.ScriptPath, Utils.ScriptsPath); var scriptFilePath = HandleUploadFile(item.Id, scriptFile, Utils.ScriptsPath); item.ScriptPath = scriptFilePath; } if (mediaFiles.Any()) { HandleMediaImages(item.Id, mediaFiles); } db.Entry(item).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Sửa thành công." }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, message = "Sửa thất bại" }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { return(Json(new { success = false, message = "Sửa thất bại" }, JsonRequestBehavior.AllowGet)); } }