Exemple #1
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(object model)
        {
            string text;

            if (model is MultiString)
            {
                text = (MultiString)model;
            }
            else
            {
                text = (string)model;
            }

            int emHeight = PropData.GetAdditionalAttributeValue("EmHeight", 10);

            HtmlBuilder hb = new HtmlBuilder();

            YTagBuilder tag = new YTagBuilder("textarea");

            tag.AddCssClass("yt_textareasourceonly");
            tag.AddCssClass("t_edit");
            tag.AddCssClass("k-textbox"); // USE KENDO style
            FieldSetup(tag, Validation ? FieldType.Validated : FieldType.Normal);
            tag.Attributes.Add("id", ControlId);
            tag.Attributes.Add("rows", emHeight.ToString());

            // handle StringLengthAttribute as maxlength
            StringLengthAttribute lenAttr = PropData.TryGetAttribute <StringLengthAttribute>();

            if (lenAttr != null)
            {
#if DEBUG
                if (tag.Attributes.ContainsKey("maxlength"))
                {
                    throw new InternalError($"Both StringLengthAttribute and maxlength specified - {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 - {FieldName}");
            }
#endif

            tag.SetInnerText(text);
            hb.Append(tag.ToString(YTagRenderMode.Normal));

            Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.TextAreaSourceOnlyEditComponent('{ControlId}');");

            return(Task.FromResult(hb.ToString()));
        }
Exemple #2
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public async Task <string> RenderAsync(object model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            string text;

            if (model is MultiString)
            {
                text = (MultiString)model;
            }
            else
            {
                text = (string)model;
            }

            bool copy = PropData.GetAdditionalAttributeValue <bool>("Copy", true);

            if (!string.IsNullOrWhiteSpace(text))
            {
                int emHeight = PropData.GetAdditionalAttributeValue("EmHeight", 10);

                YTagBuilder tag = new YTagBuilder("textarea");
                tag.AddCssClass("yt_textareasourceonly");
                tag.AddCssClass("t_display");
                tag.AddCssClass("k-textbox"); // USE KENDO style
                //tag.AddCssClass("k-state-disabled"); // USE KENDO style
                FieldSetup(tag, FieldType.Anonymous);
                tag.Attributes.Add("id", ControlId);
                tag.Attributes.Add("rows", emHeight.ToString());
                if (copy)
                {
                    tag.Attributes.Add("readonly", "readonly");
                }
                else
                {
                    tag.Attributes.Add("disabled", "disabled");
                }
                tag.SetInnerText(text);

                hb.Append(tag.ToString(YTagRenderMode.Normal));

                if (copy)
                {
                    hb.Append(ImageHTML.BuildKnownIcon("#TextAreaSourceOnlyCopy", sprites: Info.PredefSpriteIcons, title: __ResStr("ttCopy", "Copy to Clipboard"), cssClass: "yt_textareasourceonly_copy"));
                }
            }
            if (copy)
            {
                await Manager.AddOnManager.AddAddOnNamedAsync(Package.AreaName, "clipboardjs.com.clipboard");// add clipboard support
            }

            return(hb.ToString());
        }
Exemple #3
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(DateTime?model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            if (model != null && (DateTime)model > DateTime.MinValue && (DateTime)model < DateTime.MaxValue)
            {
                YTagBuilder tag = new YTagBuilder("div");
                tag.AddCssClass("yt_time");
                tag.AddCssClass("t_display");
                FieldSetup(tag, FieldType.Anonymous);
                tag.SetInnerText(YetaWF.Core.Localize.Formatting.FormatTime(model));
                hb.Append(tag.ToString(YTagRenderMode.Normal));
            }
            return(Task.FromResult(hb.ToString()));
        }
Exemple #4
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(TimeSpan?model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            if (model != null)
            {
                YTagBuilder tag = new YTagBuilder("div");
                tag.AddCssClass("yt_timespan");
                tag.AddCssClass("t_display");
                FieldSetup(tag, FieldType.Anonymous);
                tag.SetInnerText(Formatting.FormatTimeSpan(model));
                hb.Append(tag.ToString(YTagRenderMode.Normal));
            }
            return(Task.FromResult(hb.ToString()));
        }
Exemple #5
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(bool?model)
        {
            YTagBuilder tag = new YTagBuilder("input");

            tag.AddCssClass("yt_boolean");
            tag.AddCssClass("t_display");
            FieldSetup(tag, FieldType.Anonymous);
            tag.Attributes.Add("type", "checkbox");
            tag.Attributes.Add("disabled", "disabled");
            if (model != null && (bool)model)
            {
                tag.Attributes.Add("checked", "checked");
            }
            return(Task.FromResult(tag.ToString(YTagRenderMode.StartTag)));
        }
Exemple #6
0
        internal static async Task <string> RenderMenuAsync(MenuList menu, string id = null, string cssClass = null,
                                                            ModuleAction.RenderEngineEnum RenderEngine = ModuleAction.RenderEngineEnum.KendoMenu, bool Hidden = false, YHtmlHelper HtmlHelper = null)
        {
            HtmlBuilder hb    = new HtmlBuilder();
            int         level = 0;

            if (menu.Count == 0)
            {
                return(null);
            }
            string menuContents = await RenderLIAsync(HtmlHelper, menu, null, menu.RenderMode, RenderEngine, menu.LICssClass, level);

            if (string.IsNullOrWhiteSpace(menuContents))
            {
                return(null);
            }

            // <ul class= style= >
            YTagBuilder ulTag = new YTagBuilder("ul");

            if (Hidden)
            {
                ulTag.Attributes.Add("style", "display:none");
            }
            if (!string.IsNullOrWhiteSpace(cssClass))
            {
                ulTag.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(cssClass));
            }
            ulTag.AddCssClass(string.Format("t_lvl{0}", level));
            if (RenderEngine == ModuleAction.RenderEngineEnum.BootstrapSmartMenu)
            {
                ulTag.AddCssClass("nav");
                ulTag.AddCssClass("navbar-nav");
            }
            if (!string.IsNullOrWhiteSpace(id))
            {
                ulTag.Attributes.Add("id", id);
            }
            hb.Append(ulTag.ToString(YTagRenderMode.StartTag));

            // <li>....</li>
            hb.Append(menuContents);

            // </ul>
            hb.Append(ulTag.ToString(YTagRenderMode.EndTag));

            return(hb.ToString());
        }
Exemple #7
0
        public async Task <string> RenderAsync(int model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            YTagBuilder tag = new YTagBuilder("span");

            tag.AddCssClass("yt_yetawf_identity_userid");
            tag.AddCssClass("t_display");
            FieldSetup(tag, FieldType.Anonymous);

            ModuleAction actionDisplay = null;
            ModuleAction actionLoginAs = null;

            using (UserDefinitionDataProvider dataProvider = new UserDefinitionDataProvider()) {
                UserDefinition user = await dataProvider.GetItemByUserIdAsync(model);

                string userName = "";
                if (user == null)
                {
                    if (model != 0)
                    {
                        userName = string.Format("({0})", model);
                    }
                }
                else
                {
                    userName = user.UserName;
                    Modules.UsersDisplayModule modDisp = new Modules.UsersDisplayModule();
                    actionDisplay = modDisp.GetAction_Display(null, userName);
                    Modules.LoginModule modLogin = (Modules.LoginModule) await ModuleDefinition.CreateUniqueModuleAsync(typeof(Modules.LoginModule));

                    actionLoginAs = await modLogin.GetAction_LoginAsAsync(model, userName);
                }
                tag.SetInnerText(userName);
            }

            hb.Append(tag.ToString(YTagRenderMode.Normal));
            if (actionDisplay != null)
            {
                hb.Append(await actionDisplay.RenderAsync(ModuleAction.RenderModeEnum.IconsOnly));
            }
            if (actionLoginAs != null)
            {
                hb.Append(await actionLoginAs.RenderAsync(ModuleAction.RenderModeEnum.IconsOnly));
            }

            return(hb.ToString());
        }
Exemple #8
0
        /// <summary>
        /// Renders module links.
        /// </summary>
        /// <param name="mod">The module for which the module links are rendered.</param>
        /// <param name="renderMode">The module links' rendering mode.</param>
        /// <param name="cssClass">The optional CSS classes to use for the module links.</param>
        /// <returns>Returns the module links as HTML.</returns>
        public async Task <string> RenderModuleLinksAsync(ModuleDefinition mod, ModuleAction.RenderModeEnum renderMode, string cssClass)
        {
            HtmlBuilder hb = new HtmlBuilder();

            MenuList moduleMenu = await mod.GetModuleMenuListAsync(renderMode, ModuleAction.ActionLocationEnum.ModuleLinks);

            string menuContents = (await RenderMenuAsync(moduleMenu, null, Globals.CssModuleLinks));

            if (!string.IsNullOrWhiteSpace(menuContents))
            {
                await Manager.AddOnManager.AddTemplateFromUIHintAsync("ActionIcons"); // action icons

                // <div>
                YTagBuilder div2Tag = new YTagBuilder("div");
                div2Tag.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(cssClass));
                hb.Append(div2Tag.ToString(YTagRenderMode.StartTag));

                // <ul><li> menu
                hb.Append(menuContents);

                // </div>
                hb.Append(div2Tag.ToString(YTagRenderMode.EndTag));
            }
            return(hb.ToString());
        }
Exemple #9
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(string model)
        {
            HtmlBuilder sb = new HtmlBuilder();

            YTagBuilder tagLabel = new YTagBuilder("label");

            FieldSetup(tagLabel, FieldType.Anonymous);
            if (string.IsNullOrEmpty(model)) // we're distinguishing between "" and " "
            {
                tagLabel.InnerHtml = "&nbsp;";
            }
            else
            {
                tagLabel.SetInnerText(model);
            }
            sb.Append(tagLabel.ToString(YTagRenderMode.Normal));

            string helpLink;

            if (TryGetSiblingProperty <string>($"{PropertyName}_HelpLink", out helpLink) && !string.IsNullOrWhiteSpace(helpLink))
            {
                YTagBuilder tagA = new YTagBuilder("a");
                tagA.Attributes.Add("href", Utility.UrlEncodePath(helpLink));
                tagA.Attributes.Add("target", "_blank");
                tagA.MergeAttribute("rel", "noopener noreferrer");
                tagA.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule("yt_extlabel_img"));
                tagA.InnerHtml = ImageHTML.BuildKnownIcon("#Help");
                sb.Append(tagA.ToString(YTagRenderMode.Normal));
            }

            return(Task.FromResult(sb.ToString()));
        }
Exemple #10
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(bool?model)
        {
            YTagBuilder tag = new YTagBuilder("input");

            tag.AddCssClass("yt_boolean");
            tag.AddCssClass("t_edit");
            FieldSetup(tag, Validation ? FieldType.Validated : FieldType.Anonymous);
            tag.Attributes.Add("id", ControlId);
            tag.Attributes.Add("type", "checkbox");
            tag.Attributes.Add("value", "true");
            if (model != null && (bool)model)
            {
                tag.Attributes.Add("checked", "checked");
            }

            // add a hidden field so we always get "something" for check boxes (that means we have to deal with duplicates names)
            YTagBuilder tagHidden = new YTagBuilder("input");

            FieldSetup(tagHidden, FieldType.Normal);
            tagHidden.Attributes.Add("type", "hidden");
            tagHidden.Attributes.Add("value", "false");
            tagHidden.AddCssClass("yform-novalidate");

            //Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.BooleanEditComponent('{ControlId}');");

            return(Task.FromResult(tag.ToString(YTagRenderMode.StartTag) + tagHidden.ToString(YTagRenderMode.StartTag)));
        }
Exemple #11
0
        private void AddErrorClass(YTagBuilder tagBuilder)
        {
            string cls = GetErrorClass();

            if (!string.IsNullOrWhiteSpace(cls))
            {
                tagBuilder.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(cls));
            }
        }
Exemple #12
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(Decimal?model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            if (model != null && (Decimal)model > Decimal.MinValue && (Decimal)model < Decimal.MaxValue)
            {
                YTagBuilder tag = new YTagBuilder("div");
                tag.AddCssClass("yt_decimal");
                tag.AddCssClass("t_display");
                FieldSetup(tag, FieldType.Anonymous);
                string format = PropData.GetAdditionalAttributeValue("Format", "0.00");
                if (model != null)
                {
                    tag.SetInnerText(((decimal)model).ToString(format));
                }
                hb.Append(tag.ToString(YTagRenderMode.Normal));
            }
            return(Task.FromResult(hb.ToString()));
        }
Exemple #13
0
        /// <summary>
        /// Renders an image &lt;img&gt; tag with specified attributes and returns HTML.
        /// </summary>
        /// <param name="imageType">The image type which must match a registered image handler. The YetaWF.Core.Image.ImageSupport.AddHandler method is used to register an image handler.</param>
        /// <param name="width">The width of the image. Both <paramref name="width"/> and <paramref name="height"/> may be 0, in which case no size attributes are rendered.</param>
        /// <param name="height">The height of the image. Both <paramref name="width"/> and <paramref name="height"/> may be 0, in which case no size attributes are rendered.</param>
        /// <param name="model">The model representing the image.</param>
        /// <param name="CacheBuster">A value that becomes part of the image URL, which can be used to defeat client-side caching. May be null.</param>
        /// <param name="Alt">The text that is rendered as part of the &lt;img&gt; tag's Alt attribute. May be null in which case the text "Image" is used.</param>
        /// <param name="ExternalUrl">Defines whether a full URL including domain is rendered (true) or whether just the path is used (false).</param>
        /// <param name="SecurityType">The security type of the rendered image URL.</param>
        /// <returns></returns>
        public static string RenderImage(string imageType, int width, int height, string model,
                                         string CacheBuster = null, string Alt = null, bool ExternalUrl = false, PageDefinition.PageSecurityType SecurityType = PageDefinition.PageSecurityType.Any)
        {
            string      url = ImageHTML.FormatUrl(imageType, null, model, width, height, CacheBuster: CacheBuster, ExternalUrl: ExternalUrl, SecurityType: SecurityType);
            YTagBuilder img = new YTagBuilder("img");

            img.AddCssClass("t_preview");
            img.Attributes.Add("src", url);
            img.Attributes.Add("alt", Alt ?? __ResStr("altImg", "Image"));
            return(img.ToString(YTagRenderMode.StartTag));
        }
Exemple #14
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public async Task <string> RenderAsync(string model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            bool copy   = PropData.GetAdditionalAttributeValue <bool>("Copy", true);
            bool rdonly = PropData.GetAdditionalAttributeValue <bool>("ReadOnly", false);

            YTagBuilder tag = new YTagBuilder("input");

            tag.AddCssClass(TemplateClass);
            // 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_display");
            tag.AddCssClass("k-state-disabled"); // USE KENDO style
            FieldSetup(tag, FieldType.Anonymous);

            tag.MergeAttribute("type", "text");
            tag.MergeAttribute("value", model ?? "");
            if (copy || rdonly)
            {
                tag.MergeAttribute("readonly", "readonly");
            }
            else
            {
                tag.MergeAttribute("disabled", "disabled");
            }

            hb.Append(tag.ToString(YTagRenderMode.StartTag));

            if (copy)
            {
                await Manager.AddOnManager.AddAddOnNamedAsync(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"));
            }

            //Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.TextDisplayComponent('{ControlId}');");

            return(hb.ToString());
        }
Exemple #15
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(string model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            int tileSize = PropData.GetAdditionalAttributeValue("TileSize", 24);

            YTagBuilder tag = new YTagBuilder("div");

            tag.AddCssClass("yt_colorpicker");
            tag.AddCssClass("t_display");
            FieldSetup(tag, FieldType.Anonymous);
            string style = $"width:{tileSize}px;height:{tileSize}px";

            if (model != null)
            {
                style += $";background-color:{model}";
            }
            tag.MergeAttribute("style", style);
            hb.Append(tag.ToString(YTagRenderMode.Normal));

            return(Task.FromResult(hb.ToString()));
        }
Exemple #16
0
        internal static async Task <string> RenderMenuAsync(YHtmlHelper htmlHelper, List <ModuleAction> subMenu, Guid?subGuid, string cssClass, ModuleAction.RenderModeEnum renderMode, ModuleAction.RenderEngineEnum renderEngine, int level)
        {
            HtmlBuilder hb = new HtmlBuilder();

            string menuContents = await RenderLIAsync(htmlHelper, subMenu, subGuid, renderMode, renderEngine, null, level);

            if (string.IsNullOrWhiteSpace(menuContents))
            {
                return(null);
            }

            // <ul>
            YTagBuilder ulTag = new YTagBuilder("ul");

            ulTag.AddCssClass(string.Format("t_lvl{0}", level));
            if (renderEngine == ModuleAction.RenderEngineEnum.BootstrapSmartMenu)
            {
                ulTag.AddCssClass("dropdown-menu");
            }
            if (subGuid != null)
            {
                ulTag.AddCssClass("t_megamenu_content");
                ulTag.AddCssClass("mega-menu"); // used by smartmenus
            }
            if (!string.IsNullOrWhiteSpace(cssClass))
            {
                ulTag.AddCssClass(cssClass);
            }
            hb.Append(ulTag.ToString(YTagRenderMode.StartTag));

            // <li>....</li>
            hb.Append(menuContents);

            // </ul>
            hb.Append(ulTag.ToString(YTagRenderMode.EndTag));

            return(hb.ToString());
        }
Exemple #17
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(int?model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            YTagBuilder tag = new YTagBuilder("input");
            string      id  = MakeId(tag);

            tag.AddCssClass(TemplateClass);
            tag.AddCssClass("t_edit");
            tag.AddCssClass("yt_intvalue_base");
            FieldSetup(tag, Validation ? FieldType.Validated : FieldType.Normal);

            tag.MergeAttribute("maxlength", "20");

            if (model != null)
            {
                tag.MergeAttribute("value", ((int)model).ToString());
            }

            // handle min/max
            int            min = 0, max = 999999999;
            RangeAttribute rangeAttr = PropData.TryGetAttribute <RangeAttribute>();

            if (rangeAttr != null)
            {
                min = (int)rangeAttr.Minimum;
                max = (int)rangeAttr.Maximum;
            }
            string noEntry = PropData.GetAdditionalAttributeValue <string>("NoEntry", null);
            int    step    = PropData.GetAdditionalAttributeValue <int>("Step", 1);

            hb.Append($@"
{tag.ToString(YTagRenderMode.StartTag)}");

            Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.IntValueEditComponent('{id}', {{ Min: {min}, Max: {max}, Step: {step}, NoEntryText: '{JE(noEntry??"")}' }});");

            return(Task.FromResult(hb.ToString()));
        }
Exemple #18
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(string model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            int    tileSize = PropData.GetAdditionalAttributeValue("TileSize", 16);
            string palette  = PropData.GetAdditionalAttributeValue("Palette", "basic");
            int    columns  = PropData.GetAdditionalAttributeValue("Columns", 6);
            bool   preview  = PropData.GetAdditionalAttributeValue("Preview", true);

            YTagBuilder tag = new YTagBuilder("input");

            tag.AddCssClass("yt_colorpicker");
            tag.AddCssClass("t_edit");
            FieldSetup(tag, Validation ? FieldType.Validated : FieldType.Normal);
            tag.MergeAttribute("id", ControlId);
            if (model != null)
            {
                tag.MergeAttribute("value", model);
            }
            hb.Append(tag.ToString(YTagRenderMode.StartTag));

            ScriptBuilder sb = new ScriptBuilder();

            sb.Append($@"(new YetaWF_ComponentsHTML.ColorPickerEditComponent('{ControlId}', {{
                palette: '{JE(palette)}',
                tileSize: {tileSize},
                preview: {JE(preview)},
                messages: {{
                    previewInput: '{JE(__ResStr("editColor", "Edit the color using hex values or names"))}',
                    cancel: '{JE(__ResStr("cancel", "Cancel"))}',
                    apply: '{JE(__ResStr("apply", "Apply"))}'
                }}
            }}));");

            Manager.ScriptManager.AddLast(sb.ToString());

            return(Task.FromResult(hb.ToString()));
        }
Exemple #19
0
        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)));
        }
Exemple #20
0
        /// <summary>
        /// Renders a view.
        /// </summary>
        /// <param name="htmlHelper">The HtmlHelper instance.</param>
        /// <param name="module">The module being rendered in the view.</param>
        /// <param name="viewHtml">The current view contents to be wrapped in the view.</param>
        /// <param name="UsePartialFormCss">Defines whether the partial form CSS should be used.</param>
        /// <returns>Returns the complete view as HTML.</returns>
        public Task <string> RenderViewAsync(YHtmlHelper htmlHelper, ModuleDefinition module, string viewHtml, bool UsePartialFormCss)
        {
            HtmlBuilder hb = new HtmlBuilder();

            YTagBuilder tag = new YTagBuilder("div");

            tag.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(Forms.CssFormPartial));
            string divId = null;

            if (Manager.IsPostRequest)
            {
                divId = Manager.UniqueId();
                tag.Attributes.Add("id", divId);
            }
            else
            {
                if (UsePartialFormCss && !Manager.IsInPopup && Manager.ActiveDevice != YetaWFManager.DeviceSelected.Mobile &&
                    !string.IsNullOrWhiteSpace(Manager.SkinInfo.PartialFormCss) && module.UsePartialFormCss)
                {
                    tag.AddCssClass(Manager.SkinInfo.PartialFormCss);
                }
            }
            hb.Append(tag.ToString(YTagRenderMode.StartTag));
            hb.Append(htmlHelper.AntiForgeryToken());
            hb.Append($@"<input name='{Basics.ModuleGuid}' type='hidden' value='{module.ModuleGuid}' />");

            hb.Append(viewHtml);

            hb.Append(tag.ToString(YTagRenderMode.EndTag));

            if (divId != null)
            {
                Manager.ScriptManager.AddLast($"$YetaWF.Forms.initPartialForm('{divId}');");
            }

            return(Task.FromResult(hb.ToString()));
        }
Exemple #21
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(string model)
        {
            YTagBuilder tag = new YTagBuilder("div");

            tag.AddCssClass("yt_timezone");
            tag.AddCssClass("t_display");

            if (!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
            {
                try {
                    model = TZConvert.WindowsToIana(model);
                } catch (Exception) { }
            }
            TimeZoneInfo tzi = null;

            try {
                tzi = TimeZoneInfo.FindSystemTimeZoneById(model);
            } catch (Exception) { }
            if (tzi == null)
            {
                tag.SetInnerText(__ResStr("unknown", "(unknown)"));
            }
            else
            {
                if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
                {
                    tag.SetInnerText(tzi.DisplayName);
                }
                else
                {
                    tag.SetInnerText(tzi.Id);
                }
                tag.Attributes.Add("title", tzi.IsDaylightSavingTime(DateTime.Now /*need local time*/) ? tzi.DaylightName : tzi.StandardName);
            }
            return(Task.FromResult(tag.ToString(YTagRenderMode.Normal)));
        }
Exemple #22
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(object model)
        {
            bool showValues = UserSettings.GetProperty <bool>("ShowEnumValue");

            showValues = showValues && PropData.GetAdditionalAttributeValue("ShowEnumValue", true);

            string desc;
            string caption = ObjectSupport.GetEnumDisplayInfo(model, out desc, ShowValue: showValues);

            if (HtmlAttributes.Count > 0 || !string.IsNullOrWhiteSpace(desc))
            {
                YTagBuilder tag = new YTagBuilder("span");
                tag.AddCssClass("yt_enum");
                tag.AddCssClass("t_display");
                FieldSetup(tag, FieldType.Anonymous);
                tag.Attributes.Add(Basics.CssTooltipSpan, desc);
                tag.SetInnerText(caption);
                return(Task.FromResult(tag.ToString(YTagRenderMode.Normal)));
            }
            else
            {
                return(Task.FromResult(caption));
            }
        }
Exemple #23
0
        /// <summary>
        /// Renders a complete module menu.
        /// </summary>
        /// <param name="mod">The module for which the module menu is rendered.</param>
        /// <returns>Returns the complete module menu as HTML.</returns>
        public async Task <string> RenderModuleMenuAsync(ModuleDefinition mod)
        {
            HtmlBuilder hb = new HtmlBuilder();

            MenuList moduleMenu = await mod.GetModuleMenuListAsync(ModuleAction.RenderModeEnum.NormalMenu, ModuleAction.ActionLocationEnum.ModuleMenu);

            string menuContents = (await RenderMenuAsync(moduleMenu, null, Globals.CssModuleMenu));

            if (!string.IsNullOrWhiteSpace(menuContents))
            {
                //await Manager.ScriptManager.AddKendoUICoreJsFile("kendo.popup.min.js"); // is now a prereq of kendo.window (2017.2.621)
                await KendoUICore.AddFileAsync("kendo.menu.min.js");

                await Manager.AddOnManager.AddAddOnNamedAsync(Package.AreaName, "ModuleMenu");   // module menu support

                await Manager.AddOnManager.AddAddOnNamedAsync(Package.AreaName, "Modules");      // various module support

                await Manager.AddOnManager.AddAddOnNamedAsync(Package.AreaName, "jquery-color"); // for color change when entering module edit menu

                // <div class= >
                YTagBuilder divTag = new YTagBuilder("div");
                divTag.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(Globals.CssModuleMenuEditIcon));
                divTag.Attributes.Add("style", "display:none");
                hb.Append(divTag.ToString(YTagRenderMode.StartTag));

                hb.Append(ImageHTML.BuildKnownIcon("#ModuleMenuEdit", sprites: Info.PredefSpriteIcons, title: null /*no tooltip here as it's useless */));

                // <div>
                YTagBuilder div2Tag = new YTagBuilder("div");
                div2Tag.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(Globals.CssModuleMenuContainer));
                hb.Append(div2Tag.ToString(YTagRenderMode.StartTag));

                // <ul><li> menu
                hb.Append(menuContents);

                // </div>
                hb.Append(div2Tag.ToString(YTagRenderMode.EndTag));

                // </div>
                hb.Append(divTag.ToString(YTagRenderMode.EndTag));
            }
            return(hb.ToString());
        }
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(string model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            YTagBuilder tag = new YTagBuilder("span");

            tag.AddCssClass("t_display");
            FieldSetup(tag, FieldType.Anonymous);

            string toolTip = GetSiblingProperty <string>($"{PropertyName}_ToolTip");

            if (!string.IsNullOrWhiteSpace(toolTip))
            {
                tag.Attributes.Add(Basics.CssTooltipSpan, toolTip);
            }
            if (!string.IsNullOrWhiteSpace(model))
            {
                tag.SetInnerText(model);
            }
            return(Task.FromResult(tag.ToString(YTagRenderMode.Normal)));
        }
Exemple #25
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(object model)
        {
            YTagBuilder tag = new YTagBuilder("input");

            FieldSetup(tag, FieldType.Normal);
            tag.MergeAttribute("type", "hidden");
            if (HtmlAttributes.ContainsKey("--NoTemplate"))
            {
                HtmlAttributes.Remove("--NoTemplate");
            }
            else if (HtmlAttributes.ContainsKey("__NoTemplate"))
            {
                HtmlAttributes.Remove("__NoTemplate");
            }
            else
            {
                tag.AddCssClass("yt_hidden");
            }
            if (model != null && model.GetType().IsEnum)
            {
                model = (int)model;
            }
            tag.MergeAttribute("value", model == null ? "" : model.ToString());

            StringLengthAttribute lenAttr = PropData.TryGetAttribute <StringLengthAttribute>();

#if NOTYET
            if (lenAttr == null)
            {
                throw new InternalError($"No max string length given using StringLengthAttribute - {FieldName}");
            }
#endif
            if (lenAttr != null && lenAttr.MaximumLength > 0 && lenAttr.MaximumLength <= 8000)
            {
                tag.MergeAttribute("maxlength", lenAttr.MaximumLength.ToString());
            }

            return(Task.FromResult(tag.ToString(YTagRenderMode.StartTag)));
        }
        /// <summary>
        /// Returns the client-side validation message for a component with the specified field name.
        /// </summary>
        /// <param name="fieldName">The HTML field name.</param>
        /// <param name="htmlHelper">An instance of a YHtmlHelper.</param>
        /// <returns>Returns the client-side validation message for the component with the specified field name.</returns>
        public static string BuildValidationMessage(this YHtmlHelper htmlHelper, string fieldName)
        {
            var    modelState = htmlHelper.ModelState[fieldName];
            string error      = null;
            bool   hasError   = false;

            if (modelState == null)
            {
                // no errors
            }
            else
            {
                IEnumerable <string> errors = (from e in modelState.Errors select e.ErrorMessage);
                hasError = errors.Any();
                if (hasError)
                {
                    error = errors.First();
                }
            }

            YTagBuilder tagBuilder = new YTagBuilder("span");

            tagBuilder.MergeAttribute("data-v-for", fieldName);
            tagBuilder.AddCssClass(hasError ? "v-error" : "v-valid");

            if (hasError)
            {
                // we're building the same client side in validation.ts, make sure to keep in sync
                // <img src="${$YetaWF.htmlAttrEscape(YConfigs.Forms.CssWarningIconUrl)}" name=${name} class="${YConfigs.Forms.CssWarningIcon}" ${YConfigs.Basics.CssTooltip}="${$YetaWF.htmlAttrEscape(val.M)}"/>
                YTagBuilder tagImg = new YTagBuilder("img");
                tagImg.Attributes.Add("src", Forms.CssWarningIconUrl);
                tagImg.Attributes.Add("name", fieldName);
                tagImg.AddCssClass(Forms.CssWarningIcon);
                tagImg.Attributes.Add(Basics.CssTooltip, error);
                tagBuilder.InnerHtml = tagImg.ToString();
            }
            return(tagBuilder.ToString(YTagRenderMode.Normal));
        }
Exemple #27
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public async Task <string> RenderAsync(IEnumerable model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            string uiHint = PropData.GetAdditionalAttributeValue <string>("Template");

            if (uiHint == null)
            {
                throw new InternalError("No UIHint available for scroller");
            }


            hb.Append($@"
<div id='{DivId}' class='yt_scroller t_display'>
    <a class='t_left' href='javascript:void(0)'></a>
    <div class='t_scrollarea'>
        <div class='t_items'>");

            foreach (var item in model)
            {
                YTagBuilder tag = new YTagBuilder("div");
                tag.AddCssClass("t_item");
                tag.InnerHtml = await HtmlHelper.ForDisplayContainerAsync(item, uiHint);

                hb.Append(tag.ToString(YTagRenderMode.Normal));
            }

            hb.Append($@"
        </div>
    </div>
    <a class='t_right' href='javascript:void(0)'></a>
</div>");

            Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.ScrollerComponent('{DivId}');");

            return(hb.ToString());
        }
Exemple #28
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(string model)
        {
            if (string.IsNullOrWhiteSpace(model))
            {
                return(Task.FromResult <string>(null));
            }

            HtmlBuilder hb = new HtmlBuilder();

            hb.Append("<div class='yt_url t_display'>");

            string hrefUrl;

            if (!TryGetSiblingProperty($"{PropertyName}_Url", out hrefUrl))
            {
                hrefUrl = model;
            }

            if (string.IsNullOrWhiteSpace(hrefUrl))
            {
                // no link
                YTagBuilder tag = new YTagBuilder("span");
                FieldSetup(tag, FieldType.Anonymous);

                string cssClass = PropData.GetAdditionalAttributeValue("CssClass", "");
                if (!string.IsNullOrWhiteSpace(cssClass))
                {
                    tag.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(cssClass));
                }

                tag.SetInnerText(model);
                hb.Append(tag.ToString(YTagRenderMode.Normal));
            }
            else
            {
                // link
                YTagBuilder tag = new YTagBuilder("a");
                FieldSetup(tag, FieldType.Anonymous);

                string cssClass = PropData.GetAdditionalAttributeValue("CssClass", "");
                if (!string.IsNullOrWhiteSpace(cssClass))
                {
                    tag.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(cssClass));
                }

                tag.MergeAttribute("href", hrefUrl);
                tag.MergeAttribute("target", "_blank");
                tag.MergeAttribute("rel", "nofollow noopener noreferrer");
                string text;
                if (!TryGetSiblingProperty($"{PropertyName}_Text", out text))
                {
                    text = model;
                }
                tag.SetInnerText(text);
                string tooltip = null;
                TryGetSiblingProperty($"{PropertyName}_ToolTip", out tooltip);
                if (!string.IsNullOrWhiteSpace(tooltip))
                {
                    tag.MergeAttribute(Basics.CssTooltip, tooltip);
                }

                // image
                if (PropData.GetAdditionalAttributeValue("ShowImage", true))
                {
                    tag.InnerHtml = tag.InnerHtml + ImageHTML.BuildKnownIcon("#UrlRemote", sprites: Info.PredefSpriteIcons);
                }
                hb.Append(tag.ToString(YTagRenderMode.Normal));
            }
            hb.Append("</div>");
            return(Task.FromResult(hb.ToString()));
        }
Exemple #29
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public async Task <string> RenderAsync(string model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            UrlTypeEnum type = PropData.GetAdditionalAttributeValue("UrlType", UrlTypeEnum.Remote);

            UrlUI ui = new UrlUI {
                UrlType = type,
                _Local  = model,
                _Remote = model,
            };

            hb.Append($@"
<div id='{ControlId}' class='yt_url t_edit'>");

            YTagBuilder tag = new YTagBuilder("input");

            tag.AddCssClass("t_hidden");
            tag.Attributes["type"] = "hidden";
            FieldSetup(tag, FieldType.Validated);
            tag.MergeAttribute("value", model);
            hb.Append(tag.ToString(YTagRenderMode.StartTag));

            using (Manager.StartNestedComponent(FieldName)) {
                hb.Append($@"
    {await HtmlHelper.ForEditAsync(ui, nameof(ui.UrlType), Validation: false)}
");

                if ((type & UrlTypeEnum.Local) != 0)
                {
                    hb.Append($@"
    <div class='t_local'>
        {await HtmlHelper.ForEditAsync(ui, nameof(ui._Local), Validation: false)}
    </div>");
                }
                if ((type & UrlTypeEnum.Remote) != 0)
                {
                    hb.Append($@"
    <div class='t_remote'>
        {await HtmlHelper.ForEditAsync(ui, nameof(ui._Remote), Validation: false)}
    </div>");
                }
            }

            // link
            tag = new YTagBuilder("a");
            tag.MergeAttribute("href", Utility.UrlEncodePath(model));
            tag.MergeAttribute("target", "_blank");
            tag.MergeAttribute("rel", "nofollow noopener noreferrer");

            tag.InnerHtml = tag.InnerHtml + ImageHTML.BuildKnownIcon("#UrlRemote", sprites: Info.PredefSpriteIcons);
            string link = tag.ToString(YTagRenderMode.Normal);

            UrlEditSetup setup = new UrlEditSetup {
                Type = type,
                Url  = model,
            };

            hb.Append($@"
    <div class='t_link'>
        {link}
    </div>
</div>");

            Manager.ScriptManager.AddLast($"new YetaWF_ComponentsHTML.UrlEditComponent('{ControlId}', {Utility.JsonSerialize(setup)});");

            return(hb.ToString());
        }
Exemple #30
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public async Task <string> RenderAsync(object model)
        {
            string text;

            if (model is MultiString)
            {
                text = (MultiString)model;
            }
            else
            {
                text = (string)model;
            }

            bool sourceOnly = PropData.GetAdditionalAttributeValue("SourceOnly", false);
            bool full       = PropData.GetAdditionalAttributeValue("Full", false);

            HtmlBuilder hb = new HtmlBuilder();

            if (full || sourceOnly)
            {
                await Manager.AddOnManager.AddAddOnNamedAsync(Package.AreaName, "ckeditor");

                int emHeight  = PropData.GetAdditionalAttributeValue("EmHeight", 10);
                int pixHeight = Manager.CharHeight * emHeight;

                string addonUrl = Manager.AddOnManager.GetAddOnNamedUrl(Package.AreaName, "ckeditor") + "__CUSTOM_FILES/";
                string url      = addonUrl + "full_ro_config.js";
                if (sourceOnly)
                {
                    url = addonUrl + "sourceonly_ro_config.js";
                }

                YTagBuilder tag = new YTagBuilder("textarea");
                tag.AddCssClass("yt_textarea");
                tag.AddCssClass("t_edit");
                tag.AddCssClass("t_readonly");
                FieldSetup(tag, FieldType.Anonymous);
                tag.Attributes.Add("id", ControlId);
                tag.Attributes.Add("data-height", pixHeight.ToString());
                tag.SetInnerText(text);

                hb.Append(tag.ToString(YTagRenderMode.Normal));

                Manager.ScriptManager.AddLast($@"
CKEDITOR.replace('{ControlId}', {{
    customConfig: '{Utility.JserEncode(Manager.GetCDNUrl(url))}',
    height: '{pixHeight}px'
}});");
            }
            else
            {
                if (string.IsNullOrWhiteSpace(text))
                {
                    return(null);
                }

                hb.Append(Globals.LazyHTMLOptimization);

                YTagBuilder tag = new YTagBuilder("div");
                tag.AddCssClass("yt_textarea");
                tag.AddCssClass("t_display");
                FieldSetup(tag, FieldType.Anonymous);

                bool encode = PropData.GetAdditionalAttributeValue("Encode", true);
                if (encode)
                {
                    tag.SetInnerText(text);
                    text = tag.InnerHtml;
                    text = text.Replace("\r\n", "<br/>");
                    text = text.Replace("\n", "<br/>");
                }
                tag.InnerHtml = text;

                hb.Append(tag.ToString(YTagRenderMode.Normal));
                hb.Append(Globals.LazyHTMLOptimizationEnd);
            }
            return(hb.ToString());
        }