Ejemplo n.º 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(Decimal?model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            if (model != null)
            {
                hb.Append(HE(Formatting.FormatAmount((decimal)model)));
            }
            return(Task.FromResult(hb.ToString()));
        }
Ejemplo n.º 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 Task <string> RenderAsync(Decimal?model)
        {
            HtmlBuilder hb = new HtmlBuilder();

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

            YTagBuilder tag = new YTagBuilder("input");

            FieldSetup(tag, Validation ? FieldType.Validated : FieldType.Normal);

            bool rdonly   = PropData.GetAdditionalAttributeValue <bool>("ReadOnly", false);
            bool disabled = PropData.GetAdditionalAttributeValue <bool>("Disabled", false);

            if (disabled)
            {
                tag.Attributes.Add("disabled", "disabled");
            }

            CurrencySetup setup = new CurrencySetup {
                Min      = 0,
                Max      = 999999999.99,
                ReadOnly = rdonly,
            };
            // handle min/max
            RangeAttribute rangeAttr = PropData.TryGetAttribute <RangeAttribute>();

            if (rangeAttr != null)
            {
                setup.Min = (double)rangeAttr.Minimum;
                setup.Max = (double)rangeAttr.Maximum;
            }
            if (model != null)
            {
                tag.MergeAttribute("value", Formatting.FormatAmount((decimal)model));
            }

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

            hb.Append($"</div>");
            Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.CurrencyEditComponent('{ControlId}', {Utility.JsonSerialize(setup)});");

            return(Task.FromResult(hb.ToString()));
        }