Beispiel #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(DateTime?model)
        {
            YTagBuilder tag = new YTagBuilder("div");

            FieldSetup(tag, FieldType.Anonymous);

            if (model != null && (DateTime)model > DateTime.MinValue && (DateTime)model < DateTime.MaxValue)
            {
                DateTime last    = (DateTime)model;
                TimeSpan diff    = last - DateTime.UtcNow;
                string   words   = HE(Formatting.FormatTimeSpanInWords(diff));
                string   wordsTT = Formatting.FormatLongDateTime(last);
                tag.Attributes.Add(Basics.CssTooltip, wordsTT);
                tag.SetInnerText(words);
            }
            else
            {
                string text;
                if (!TryGetSiblingProperty($"{PropertyName}_EmptyHTML", out text))
                {
                    return(Task.FromResult <string>(null));
                }
                tag.InnerHtml = text;
            }
            return(Task.FromResult(tag.ToString(YTagRenderMode.Normal)));
        }
Beispiel #2
0
        internal async Task<string> RenderPropertyListAsync(object model, bool ReadOnly) {

            HtmlBuilder hb = new HtmlBuilder();
            Type modelType = model.GetType();
            ClassData classData = ObjectSupport.GetClassData(modelType);
            RenderHeader(hb, classData);

            bool showVariables = YetaWF.Core.Localize.UserSettings.GetProperty<bool>("ShowVariables");

            // property table
            HtmlBuilder hbProps = new HtmlBuilder();
            string divId = Manager.UniqueId();
            hbProps.Append($@"
<div id='{divId}' class='yt_propertylist {(ReadOnly ? "t_display" : "t_edit")}'>
   {await RenderHiddenAsync(model)}
   {await RenderListAsync(model, null, showVariables, ReadOnly)}
</div>");

            if (!string.IsNullOrWhiteSpace(classData.Legend)) {
                YTagBuilder tagFieldSet = new YTagBuilder("fieldset");
                YTagBuilder tagLegend = new YTagBuilder("legend");
                tagLegend.SetInnerText(classData.Legend);
                tagFieldSet.InnerHtml = tagLegend.ToString(YTagRenderMode.Normal) + hbProps.ToString();
                hb.Append(tagFieldSet.ToString(YTagRenderMode.Normal));
            } else {
                hb.Append(hbProps.ToString());
            }
            RenderFooter(hb, classData);

            ControlData cd = GetControlSets(model, divId);
            Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.PropertyListComponent('{divId}', {Utility.JsonSerialize(new PropertyList.PropertyListSetup())}, {Utility.JsonSerialize(cd)});");

            return hb.ToString();
        }
Beispiel #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(Decimal?model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            YTagBuilder tag = new YTagBuilder("input");

            tag.AddCssClass("yt_decimal");
            tag.AddCssClass("t_edit");
            FieldSetup(tag, Validation ? FieldType.Validated : FieldType.Normal);
            string id = MakeId(tag);

            // handle min/max
            float          min = 0, max = 99999999.99F;
            RangeAttribute rangeAttr = PropData.TryGetAttribute <RangeAttribute>();

            if (rangeAttr != null)
            {
                min = Convert.ToSingle(rangeAttr.Minimum);
                max = Convert.ToSingle(rangeAttr.Maximum);
            }
            string format = PropData.GetAdditionalAttributeValue("Format", "0.00");

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

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

            Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.DecimalEditComponent('{id}', {{ Min: {min}, Max: {max} }});");

            return(Task.FromResult(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(DayTimeRange model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            if (model != null)
            {
                YTagBuilder tag = new YTagBuilder("div");
                tag.AddCssClass("yt_daytimerange");
                tag.AddCssClass("t_display");
                FieldSetup(tag, FieldType.Anonymous);

                string s = null;
                if (model.Start != null && model.End != null)
                {
                    if (model.Start2 != null && model.End2 != null)
                    {
                        s = __ResStr("time2", "{0} - {1}, {2} - {3} ", Formatting.FormatTime(model.GetStart()), Formatting.FormatTime(model.GetEnd()), Formatting.FormatTime(model.GetStart2()), Formatting.FormatTime(model.GetEnd2()));
                    }
                    else
                    {
                        s = __ResStr("time1", "{0} - {1}", Formatting.FormatTime(model.GetStart()), Formatting.FormatTime(model.GetEnd()));
                    }
                }
                else
                {
                    s = __ResStr("time0", "");
                }
                tag.SetInnerText(s);
                hb.Append(tag.ToString(YTagRenderMode.Normal));
            }
            return(Task.FromResult(hb.ToString()));
        }
Beispiel #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(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()));
        }
Beispiel #6
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_booleantext");
            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");
            }

            string text;

            if (TryGetSiblingProperty($"{PropertyName}_Text", out text))
            {
                return(Task.FromResult(tag.ToString(YTagRenderMode.StartTag) + HE(text)));
            }
            else
            {
                return(Task.FromResult(tag.ToString(YTagRenderMode.StartTag)));
            }
        }
Beispiel #7
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)
        {
            UseSuppliedIdAsControlId();

            HtmlBuilder hb = new HtmlBuilder();

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

            Dictionary <string, object> hiddenAttributes = new Dictionary <string, object>(HtmlAttributes)
            {
                { "__NoTemplate", true }
            };

            hb.Append(await HtmlHelper.ForEditComponentAsync(Container, PropertyName, null, "Hidden", HtmlAttributes: hiddenAttributes, Validation: Validation));

            YTagBuilder tag = new YTagBuilder("input");

            FieldSetup(tag, FieldType.Anonymous);
            tag.Attributes.Add("name", "ssninput");

            if (model != null)
            {
                tag.MergeAttribute("value", model);
            }
            hb.Append(tag.ToString(YTagRenderMode.StartTag));

            hb.Append($"</div>");

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

            return(hb.ToString());
        }
Beispiel #8
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)));
        }
Beispiel #9
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());
        }
Beispiel #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 async Task <string> RenderAsync(TimeOfDay model)
        {
            // we're reusing Time component
            await Manager.AddOnManager.AddTemplateFromUIHintAsync("Time");

            HtmlBuilder hb = new HtmlBuilder();

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

            Dictionary <string, object> hiddenAttributes = new Dictionary <string, object>(HtmlAttributes)
            {
                { "__NoTemplate", true }
            };

            hb.Append(await HtmlHelper.ForEditComponentAsync(Container, PropertyName, null, "Hidden", HtmlAttributes: hiddenAttributes, Validation: Validation));

            YTagBuilder tag = new YTagBuilder("input");

            FieldSetup(tag, FieldType.Anonymous);
            tag.Attributes.Add("name", "dtpicker");

            if (model != null)
            {
                DateTime dt = model.AsDateTime();
                tag.MergeAttribute("value", Formatting.FormatTime(dt));
            }
            hb.Append(tag.ToString(YTagRenderMode.StartTag));

            hb.Append($"</div>");

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

            return(hb.ToString());
        }
Beispiel #11
0
        private void AddErrorClass(YTagBuilder tagBuilder)
        {
            string cls = GetErrorClass();

            if (!string.IsNullOrWhiteSpace(cls))
            {
                tagBuilder.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(cls));
            }
        }
        /// <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("span");

            FieldSetup(tag, FieldType.Anonymous);
            tag.InnerHtml = ImageHTML.BuildKnownIcon("#RemoveLight", title: __ResStr("altRemove", "Remove"), name: "DeleteAction");

            return(Task.FromResult(tag.ToString(YTagRenderMode.Normal)));
        }
Beispiel #13
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()));
        }
Beispiel #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 Task <string> RenderAsync(object model)
        {
            YTagBuilder tag = new YTagBuilder("input");

            FieldSetup(tag, FieldType.Normal);
            tag.MergeAttribute("name", FieldNamePrefix, true);
            tag.MergeAttribute("type", "hidden");
            tag.MergeAttribute("value", model == null ? "" : model.ToString());
            return(Task.FromResult(tag.ToString(YTagRenderMode.StartTag)));
        }
Beispiel #15
0
        /// <summary>
        /// Adds a unique ID to the specified tag.
        /// </summary>
        /// <param name="tag">The tag to which the ID is added</param>
        /// <returns>Returns the ID.</returns>
        public string MakeId(YTagBuilder tag)
        {
            string id = (from a in tag.Attributes where string.Compare(a.Key, "id", true) == 0 select a.Value).FirstOrDefault();

            if (string.IsNullOrWhiteSpace(id))
            {
                id = Manager.UniqueId();
                tag.Attributes.Add("id", id);
            }
            return(id);
        }
Beispiel #16
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));
        }
        /// <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(Guid?model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            // dropdown
            List <SelectionItem <string> > list;

            list = (
                from p in await PageDefinition.GetDesignedPagesAsync() orderby p.Url select
                new SelectionItem <string> {
                Text = p.Url,
                Value = p.PageGuid.ToString(),
            }).ToList <SelectionItem <string> >();
            list.Insert(0, new SelectionItem <string> {
                Text = __ResStr("select", "(select)"), Value = null
            });

            string ddList = await DropDownListComponent.RenderDropDownListAsync(this, (model ?? Guid.Empty).ToString(), list, null);

            // link
            YTagBuilder tag = new YTagBuilder("a");

            PageDefinition page = null;

            if (model != null)
            {
                page = await PageDefinition.LoadAsync((Guid)model);
            }

            tag.MergeAttribute("href", (page != null ? page.EvaluatedCanonicalUrl : ""));
            tag.MergeAttribute("target", "_blank");
            tag.MergeAttribute("rel", "nofollow noopener noreferrer");
            tag.Attributes.Add(Basics.CssTooltip, __ResStr("linkTT", "Click to preview the page in a new window - not all pages can be displayed correctly and may require additional parameters"));

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

            hb.Append($@"
<div id='{DivId}' class='yt_pageselection t_edit'>
    <div class='t_select'>
        {ddList.ToString()}
    </div>
    <div class='t_link'>
        {linkTag}
    </div>
    <div class='t_description'>
    </div>
</div>");

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

            return(hb.ToString());
        }
Beispiel #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 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());
        }
Beispiel #19
0
        /// <summary>
        /// Render a StringTT display component given a HtmlHelper instance.
        /// </summary>
        /// <param name="htmlHelper">The HtmlHelper instance.</param>
        /// <param name="text">The text displayed.</param>
        /// <param name="tooltip">The tooltip.</param>
        /// <returns></returns>
        public static string ForStringTTDisplay(this YHtmlHelper htmlHelper, string text, string tooltip)
        {
            YTagBuilder tag = new YTagBuilder("span");

            if (!string.IsNullOrWhiteSpace(tooltip))
            {
                tag.Attributes.Add(Basics.CssTooltipSpan, tooltip);
            }
            if (!string.IsNullOrWhiteSpace(text))
            {
                tag.SetInnerText(text);
            }
            return(tag.ToString(YTagRenderMode.Normal));
        }
Beispiel #20
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(DateTime?model)
        {
            UseSuppliedIdAsControlId();

            HtmlBuilder hb = new HtmlBuilder();

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

            Dictionary <string, object> hiddenAttributes = new Dictionary <string, object>(HtmlAttributes)
            {
                { "__NoTemplate", true }
            };

            hb.Append(await HtmlHelper.ForEditComponentAsync(Container, PropertyName, null, "Hidden", HtmlAttributes: hiddenAttributes, Validation: Validation));

            YTagBuilder tag = new YTagBuilder("input");

            FieldSetup(tag, FieldType.Anonymous);
            tag.Attributes.Add("name", "dtpicker");

            // handle min/max date
            DateTimeSetup setup = new DateTimeSetup {
                Min = new DateTime(1900, 1, 1),
                Max = new DateTime(2199, 12, 31),
            };
            MinimumDateAttribute minAttr = PropData.TryGetAttribute <MinimumDateAttribute>();

            if (minAttr != null)
            {
                setup.Min = minAttr.MinDate;
            }
            MaximumDateAttribute maxAttr = PropData.TryGetAttribute <MaximumDateAttribute>();

            if (maxAttr != null)
            {
                setup.Max = maxAttr.MaxDate;
            }

            if (model != null)
            {
                tag.MergeAttribute("value", Formatting.FormatDateTime((DateTime)model));// shows date using user's timezone
            }
            hb.Append(tag.ToString(YTagRenderMode.StartTag));

            hb.Append($"</div>");

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

            return(hb.ToString());
        }
Beispiel #21
0
        public Task <string> RenderAsync(int model)
        {
            YTagBuilder tag = new YTagBuilder("span");

            FieldSetup(tag, FieldType.Anonymous);

            using (RoleDefinitionDataProvider dataProvider = new RoleDefinitionDataProvider()) {
                RoleDefinition role = dataProvider.GetRoleById(model);
                tag.SetInnerText(role.Name);
                tag.Attributes.Add(Basics.CssTooltipSpan, role.Description);
            }

            return(Task.FromResult(tag.ToString(YTagRenderMode.Normal)));
        }
Beispiel #22
0
        private void AddValidation(YTagBuilder tagBuilder)
        {
            //$$$ // add some default validations
            //if (!PropData.ReadOnly) {
            //    if (PropData.PropInfo.PropertyType == typeof(DateTime) || PropData.PropInfo.PropertyType == typeof(DateTime?)) {
            //        tagBuilder.Attributes["data-val-date"] = __ResStr("valDate", "Please enter a valid value for field '{0}'", PropData.GetCaption(Container));
            //        tagBuilder.MergeAttribute("data-val", "true");
            //    } else if (PropData.PropInfo.PropertyType == typeof(int) || PropData.PropInfo.PropertyType == typeof(int?) ||
            //            PropData.PropInfo.PropertyType == typeof(long) || PropData.PropInfo.PropertyType == typeof(long?)) {
            //        tagBuilder.Attributes["data-val-number"] = __ResStr("valNumber", "Please enter a valid number for field '{0}'", PropData.GetCaption(Container));
            //        tagBuilder.MergeAttribute("data-val", "true");
            //    }
            //}
            // Build validation attribute
            List <object> objs = new List <object>();

            foreach (YIClientValidation val in PropData.ClientValidationAttributes)
            {
                // TODO: GetCaption can fail for redirects (ModuleDefinition) so we can't call it when there are no validation attributes
                // GridAllowedRole and GridAllowedUser use a ResourceRedirectList with a property OUTSIDE of the model. This only works in grids (where it is used)
                // but breaks when used elsewhere (like here) so we only call GetCaption if there is a validation attribute (FOR NOW).
                // That whole resource  redirect business needs to be fixed (old and ugly, and fragile).
                string         caption = PropData.GetCaption(Container);
                ValidationBase valBase = val.AddValidation(Container, PropData, caption, tagBuilder);
                if (valBase != null)
                {
                    string method = valBase.Method;
                    if (string.IsNullOrWhiteSpace(method))
                    {
                        throw new InternalError($"No method given ({nameof(ValidationBase)}.{nameof(ValidationBase.Method)})");
                    }
                    if (string.IsNullOrWhiteSpace(valBase.Message))
                    {
                        throw new InternalError($"No message given ({nameof(ValidationBase)}.{nameof(ValidationBase.Message)})");
                    }
                    objs.Add(valBase);
                    method         = method.TrimEnd("Attribute");  // remove ending ..Attribute
                    method         = method.TrimEnd("Validation"); // remove ending ..Validation
                    valBase.Method = method.ToLower();
                    if (string.IsNullOrWhiteSpace(method))
                    {
                        throw new InternalError($"No method name found after removing Attribute and Validation suffixes");
                    }
                }
            }
            if (objs.Count > 0)
            {
                tagBuilder.Attributes.Add("data-v", Utility.JsonSerialize(objs));
            }
        }
Beispiel #23
0
        public async Task <string> RenderAsync(string model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            YTagBuilder tag = new YTagBuilder("span");

            FieldSetup(tag, FieldType.Anonymous);

            ModuleAction actionDisplay = null;
            ModuleAction actionLoginAs = null;

            using (UserDefinitionDataProvider userDefDP = new UserDefinitionDataProvider()) {
                UserDefinition user     = null;
                string         userName = "";
                if (!string.IsNullOrWhiteSpace(model))
                {
                    user = await userDefDP.GetItemByEmailAsync(model);

                    if (user == null)
                    {
                        userName = model;
                    }
                    else
                    {
                        userName = user.Email;
                        UsersDisplayModule modDisp = new UsersDisplayModule();
                        actionDisplay = modDisp.GetAction_Display(null, user.UserName);
                        LoginModule modLogin = (LoginModule)await ModuleDefinition.CreateUniqueModuleAsync(typeof(LoginModule));

                        actionLoginAs = await modLogin.GetAction_LoginAsAsync(user.UserId, user.UserName);
                    }
                }
                else
                {
                    userName = __ResStr("noEmail", "(not specified)");
                }
                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());
        }
Beispiel #24
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)));
        }
Beispiel #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(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()));
        }
Beispiel #26
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()));
        }
Beispiel #27
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());
        }
Beispiel #28
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());
        }
Beispiel #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 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()));
        }
Beispiel #30
0
        internal string GetModuleLink(Guid?model, bool force = false)
        {
            if (!force)
            {
                if (model == null || model == Guid.Empty)
                {
                    return("");
                }
            }
            YTagBuilder tag = new YTagBuilder("a");

            tag.MergeAttribute("href", ModuleDefinition.GetModulePermanentUrl(model ?? Guid.Empty));
            tag.MergeAttribute("target", "_blank");
            tag.MergeAttribute("rel", "nofollow noopener noreferrer");
            tag.Attributes.Add(Basics.CssTooltip, __ResStr("linkTT", "Click to preview the module in a new window - not all modules can be displayed correctly and may require additional parameters"));

            tag.InnerHtml = tag.InnerHtml + ImageHTML.BuildKnownIcon("#ModulePreview", sprites: Info.PredefSpriteIcons);
            return(tag.ToString(YTagRenderMode.Normal));
        }