internal static Task <string> RenderStringTTAsync(YetaWFComponent component, StringTT model, string cssClass) { HtmlBuilder hb = new HtmlBuilder(); YTagBuilder tag = new YTagBuilder("span"); if (!string.IsNullOrWhiteSpace(cssClass)) { tag.AddCssClass(cssClass); tag.AddCssClass("t_display"); } component.FieldSetup(tag, FieldType.Anonymous); if (!string.IsNullOrWhiteSpace(model.Tooltip)) { tag.Attributes.Add(Basics.CssTooltipSpan, model.Tooltip); } if (!string.IsNullOrWhiteSpace(model.Text)) { tag.SetInnerText(model.Text); } return(Task.FromResult(tag.ToString(YTagRenderMode.Normal))); }
/// <summary> /// Renders a DropDownList component as HTML. /// </summary> /// <param name="component">The component to render.</param> /// <param name="model">The model rendered by the component.</param> /// <param name="list">A collection of items to render.</param> /// <param name="cssClass">A CSS class to add to the <select> tag. May be null.</param> /// <returns></returns> public static async Task <string> RenderDropDownListAsync(YetaWFComponent component, TYPE model, List <SelectionItem <TYPE> > list, string cssClass) { await IncludeExplicitAsync(); HtmlBuilder hb = new HtmlBuilder(); bool useKendo = true; bool adjustWidth = false; YTagBuilder tag = new YTagBuilder("select"); if (!string.IsNullOrWhiteSpace(cssClass)) { tag.AddCssClass(cssClass); } tag.AddCssClass("t_edit"); tag.AddCssClass("yt_dropdownlist_base"); bool disabled = false; if (list.Count <= 1) { if (component.PropData.GetAdditionalAttributeValue("Disable1OrLess", true)) { disabled = true; } } if (disabled) { //$$$$$$ THIS DOESN'T WORK WITH TEMPLATES component.FieldSetup(tag, FieldType.Normal); tag.Attributes.Remove("disabled"); tag.Attributes.Add("disabled", "disabled"); if (list.Count > 0) { tag.AddCssClass("disabled-submit");// submit disabled field } } else { component.FieldSetup(tag, component.Validation ? FieldType.Validated : FieldType.Normal); } string id = null; if (useKendo) { id = component.MakeId(tag); tag.Attributes.Add("data-charavgw", Manager.CharWidthAvg.ToString()); tag.AddCssClass("t_kendo"); adjustWidth = component.PropData.GetAdditionalAttributeValue("AdjustWidth", true); } else { tag.AddCssClass("t_native"); } HtmlBuilder tagHtml = new HtmlBuilder(); ScriptBuilder sb = new ScriptBuilder(); bool haveDesc = false; int empty = 0;// count empty tooltips so we don't generate them (and just drop if all are trailing entries) foreach (var item in list) { YTagBuilder tagOpt = new YTagBuilder("option"); tagOpt.SetInnerText(item.Text.ToString()); if (item.Value != null) { tagOpt.Attributes["value"] = item.Value.ToString(); } else { tagOpt.Attributes["value"] = ""; } if (Equals(item.Value, model)) { tagOpt.Attributes["selected"] = "selected"; } string desc = (item.Tooltip != null) ? item.Tooltip.ToString() : null; if (!useKendo) { if (!string.IsNullOrWhiteSpace(desc)) { tagOpt.Attributes["title"] = desc; } } else { if (string.IsNullOrWhiteSpace(desc)) { desc = ""; empty++; } else { while (empty-- > 0) { sb.Append("\"\","); } empty = 0; haveDesc = true; sb.Append("{0},", Utility.JsonSerialize(desc)); } } tagHtml.Append(tagOpt.ToString(YTagRenderMode.Normal)); } if (useKendo) { if (!haveDesc) // if we don't have any descriptions, clear the tooltip array { sb = new ScriptBuilder(); } ScriptBuilder newSb = new ScriptBuilder(); newSb.Append($@"new YetaWF_ComponentsHTML.DropDownListEditComponent('{id}', {{ ToolTips: [{sb.ToString()}], AdjustWidth: {JE(adjustWidth)} }});"); sb = newSb; } tag.InnerHtml = tagHtml.ToString(); hb.Append($@" {tag.ToString(YTagRenderMode.Normal)}"); if (sb.Length > 0) { Manager.ScriptManager.AddLast(sb.ToString()); } return(hb.ToString()); }
/// <summary> /// Renders a text input control. /// </summary> /// <param name="component">The current component being rendered.</param> /// <param name="model">The model.</param> /// <param name="templateCssClass">The CSS class to add to the template (starting with yt_).</param> /// <returns>The component rendered as HTML.</returns> public static async Task <string> RenderTextAsync(YetaWFComponent component, string model, string templateCssClass) { await IncludeExplicitAsync(); HtmlBuilder hb = new HtmlBuilder(); component.UseSuppliedIdAsControlId(); YTagBuilder tag = new YTagBuilder("input"); if (!string.IsNullOrWhiteSpace(templateCssClass)) { tag.AddCssClass(templateCssClass); } tag.AddCssClass("yt_text_base"); // adding k-textbox to the control makes it look like a kendo maskedtext box without the overhead of actually calling kendoMaskedTextBox tag.AddCssClass("k-textbox"); tag.AddCssClass("t_edit"); component.FieldSetup(tag, component.Validation ? FieldType.Validated : FieldType.Normal); tag.Attributes.Add("id", component.ControlId); //string id = null; //if (!string.IsNullOrWhiteSpace(mask)) { // id = component.MakeId(tag); //} if (Manager.CurrentModule != null && Manager.CurrentModule.FormAutoComplete) { tag.MergeAttribute("autocomplete", "on", replaceExisting: false); } else { tag.MergeAttribute("autocomplete", "new-password", replaceExisting: false); } bool copy = component.PropData.GetAdditionalAttributeValue <bool>("Copy", false); //string mask = component.PropData.GetAdditionalAttributeValue<string>("Mask", null); // handle StringLengthAttribute as maxlength StringLengthAttribute lenAttr = component.PropData.TryGetAttribute <StringLengthAttribute>(); if (lenAttr != null) { #if DEBUG if (tag.Attributes.ContainsKey("maxlength")) { throw new InternalError("Both StringLengthAttribute and maxlength specified - {0}", component.FieldName); } #endif int maxLength = lenAttr.MaximumLength; if (maxLength > 0 && maxLength <= 8000) { tag.MergeAttribute("maxlength", maxLength.ToString()); } } #if DEBUG if (lenAttr == null && !tag.Attributes.ContainsKey("maxlength")) { throw new InternalError("No max string length given using StringLengthAttribute or maxlength - {0}", component.FieldName); } #endif // text tag.MergeAttribute("type", "text"); tag.MergeAttribute("value", model ?? ""); hb.Append($@"{tag.ToString(YTagRenderMode.StartTag)}"); if (copy) { await Manager.AddOnManager.AddAddOnNamedAsync(component.Package.AreaName, "clipboardjs.com.clipboard");// add clipboard support hb.Append(ImageHTML.BuildKnownIcon("#TextCopy", sprites: Info.PredefSpriteIcons, title: __ResStr("ttCopy", "Copy to Clipboard"), cssClass: "yt_text_copy")); } //if (!string.IsNullOrWhiteSpace(mask)) { // // if there is a Mask we need to use the KendoMaskedTextBox // await KendoUICore.AddFileAsync("kendo.maskedtextbox.min.js"); // ScriptBuilder sb = new ScriptBuilder(); // sb.Append("$('#{0}').kendoMaskedTextBox({{ mask: '{1}' }});\n", id, Utility.JserEncode(mask)); // Manager.ScriptManager.AddLastDocumentReady(sb); //} //Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.TextEditComponent('{component.ControlId}');"); return(hb.ToString()); }