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(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()));
        }
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(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)));
        }
Ejemplo n.º 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(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()));
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 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(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()));
        }
Ejemplo n.º 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 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());
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
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)));
        }
Ejemplo n.º 9
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());
        }
Ejemplo n.º 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(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()));
        }
Ejemplo n.º 11
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()));
        }
Ejemplo n.º 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(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)));
        }
Ejemplo n.º 13
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());
        }
Ejemplo n.º 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(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()));
        }
Ejemplo n.º 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();

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

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

            ModuleDefinition mod = null;

            if (model != null && model != Guid.Empty)
            {
                mod = await ModuleDefinition.LoadAsync((Guid)model, AllowNone : true);
            }

            string modName;

            if (mod == null)
            {
                if (model != null && model == Guid.Empty)
                {
                    modName = __ResStr("noLinkNone", "(none)");
                }
                else
                {
                    modName = __ResStr("noLink", "(not found - {0})", ((Guid)model).ToString());
                }
            }
            else
            {
                Package package = Package.GetPackageFromType(mod.GetType());
                modName = __ResStr("name", "{0} - {1}", package.Name, mod.Name);
            }

            YTagBuilder tag = new YTagBuilder("div");

            tag.AddCssClass("t_select");
            tag.SetInnerText(modName);
            hb.Append(tag.ToString(YTagRenderMode.Normal));

            if (mod != null)
            {
                tag = new YTagBuilder("div");
                tag.AddCssClass("t_link");
                tag.InnerHtml = GetModuleLink(model);
                hb.Append(tag.ToString(YTagRenderMode.Normal));
            }

            tag = new YTagBuilder("div");
            tag.AddCssClass("t_description");
            if (mod == null)
            {
                tag.InnerHtml = "&nbsp;";
            }
            else
            {
                tag.SetInnerText(mod.Description.ToString());
            }
            hb.Append(tag.ToString(YTagRenderMode.Normal));

            hb.Append(@"
</div>");
            return(hb.ToString());
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Renders a DropDownList component as HTML.
        /// </summary>
        /// <param name="component">The component to render.</param>
        /// <param name="model">The model rendered by the component.</param>
        /// <param name="list">A collection of items to render.</param>
        /// <param name="cssClass">A CSS class to add to the &lt;select&gt; tag. May be null.</param>
        /// <returns></returns>
        public static async Task <string> RenderDropDownListAsync(YetaWFComponent component, TYPE model, List <SelectionItem <TYPE> > list, string cssClass)
        {
            await IncludeExplicitAsync();

            HtmlBuilder hb = new HtmlBuilder();

            bool useKendo    = true;
            bool adjustWidth = false;

            YTagBuilder tag = new YTagBuilder("select");

            if (!string.IsNullOrWhiteSpace(cssClass))
            {
                tag.AddCssClass(cssClass);
            }
            tag.AddCssClass("t_edit");
            tag.AddCssClass("yt_dropdownlist_base");

            bool disabled = false;

            if (list.Count <= 1)
            {
                if (component.PropData.GetAdditionalAttributeValue("Disable1OrLess", true))
                {
                    disabled = true;
                }
            }
            if (disabled)
            {
                //$$$$$$ THIS DOESN'T WORK WITH TEMPLATES
                component.FieldSetup(tag, FieldType.Normal);
                tag.Attributes.Remove("disabled");
                tag.Attributes.Add("disabled", "disabled");
                if (list.Count > 0)
                {
                    tag.AddCssClass("disabled-submit");// submit disabled field
                }
            }
            else
            {
                component.FieldSetup(tag, component.Validation ? FieldType.Validated : FieldType.Normal);
            }

            string id = null;

            if (useKendo)
            {
                id = component.MakeId(tag);
                tag.Attributes.Add("data-charavgw", Manager.CharWidthAvg.ToString());
                tag.AddCssClass("t_kendo");
                adjustWidth = component.PropData.GetAdditionalAttributeValue("AdjustWidth", true);
            }
            else
            {
                tag.AddCssClass("t_native");
            }

            HtmlBuilder   tagHtml = new HtmlBuilder();
            ScriptBuilder sb      = new ScriptBuilder();

            bool haveDesc = false;
            int  empty    = 0;// count empty tooltips so we don't generate them (and just drop if all are trailing entries)

            foreach (var item in list)
            {
                YTagBuilder tagOpt = new YTagBuilder("option");
                tagOpt.SetInnerText(item.Text.ToString());
                if (item.Value != null)
                {
                    tagOpt.Attributes["value"] = item.Value.ToString();
                }
                else
                {
                    tagOpt.Attributes["value"] = "";
                }
                if (Equals(item.Value, model))
                {
                    tagOpt.Attributes["selected"] = "selected";
                }
                string desc = (item.Tooltip != null) ? item.Tooltip.ToString() : null;
                if (!useKendo)
                {
                    if (!string.IsNullOrWhiteSpace(desc))
                    {
                        tagOpt.Attributes["title"] = desc;
                    }
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(desc))
                    {
                        desc = "";
                        empty++;
                    }
                    else
                    {
                        while (empty-- > 0)
                        {
                            sb.Append("\"\",");
                        }
                        empty    = 0;
                        haveDesc = true;
                        sb.Append("{0},", Utility.JsonSerialize(desc));
                    }
                }
                tagHtml.Append(tagOpt.ToString(YTagRenderMode.Normal));
            }

            if (useKendo)
            {
                if (!haveDesc) // if we don't have any descriptions, clear the tooltip array
                {
                    sb = new ScriptBuilder();
                }
                ScriptBuilder newSb = new ScriptBuilder();
                newSb.Append($@"new YetaWF_ComponentsHTML.DropDownListEditComponent('{id}', {{
                    ToolTips: [{sb.ToString()}],
                    AdjustWidth: {JE(adjustWidth)}
                }});");
                sb = newSb;
            }

            tag.InnerHtml = tagHtml.ToString();

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

            if (sb.Length > 0)
            {
                Manager.ScriptManager.AddLast(sb.ToString());
            }
            return(hb.ToString());
        }
Ejemplo n.º 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 async Task <string> RenderAsync(object model)
        {
            await Manager.AddOnManager.AddAddOnNamedAsync(Package.AreaName, "ckeditor");

            string addonUrl = Manager.AddOnManager.GetAddOnNamedUrl(Package.AreaName, "ckeditor") + "__CUSTOM_FILES/";

            string text;

            if (model is MultiString)
            {
                text = (MultiString)model;
            }
            else
            {
                text = (string)model;
            }
            Guid owningGuid = Guid.Empty;

            TryGetSiblingProperty <Guid>($"{PropertyName}_Folder", out owningGuid);
            if (owningGuid == Guid.Empty && Manager.CurrentModuleEdited != null)
            {
                owningGuid = Manager.CurrentModuleEdited.ModuleGuid;
            }
            if (owningGuid == Guid.Empty)
            {
                owningGuid = Manager.CurrentModule.ModuleGuid;
            }
            Guid subFolder = PropData.GetAdditionalAttributeValue("SubFolder", Guid.Empty);

            if (subFolder == Guid.Empty)
            {
                TryGetSiblingProperty <Guid>($"{PropertyName}_SubFolder", out subFolder);
            }

            bool sourceOnly       = PropData.GetAdditionalAttributeValue("SourceOnly", false);
            bool useSave          = PropData.GetAdditionalAttributeValue("TextAreaSave", false);
            bool useImageBrowsing = PropData.GetAdditionalAttributeValue("ImageBrowse", false);
            bool useFlashBrowsing = PropData.GetAdditionalAttributeValue("FlashBrowse", false);
            bool usePageBrowsing  = PropData.GetAdditionalAttributeValue("PageBrowse", false);
            bool restrictedHtml   = PropData.GetAdditionalAttributeValue("RestrictedHtml", false);
            int  emHeight         = PropData.GetAdditionalAttributeValue("EmHeight", 10);
            int  pixHeight        = Manager.CharHeight * emHeight;

            string filebrowserImageBrowseUrl = null;

            if (useImageBrowsing)
            {
                filebrowserImageBrowseUrl = string.Format("/__CKEditor/ImageBrowseLinkUrl?__FolderGuid={0}&__SubFolder={1}",
                                                          owningGuid.ToString(), subFolder.ToString());
                filebrowserImageBrowseUrl += "&" + Globals.Link_NoEditMode + "=y";
            }
            string filebrowserFlashBrowseUrl = null;

            if (useFlashBrowsing)
            {
                filebrowserFlashBrowseUrl  = string.Format("/__CKEditor/FlashBrowseLinkUrl?__FolderGuid={0}&__SubFolder={1}", owningGuid.ToString(), subFolder.ToString());
                filebrowserFlashBrowseUrl += "&" + Globals.Link_NoEditMode + "=y";
            }
            string filebrowserPageBrowseUrl = null;

            if (usePageBrowsing)
            {
                filebrowserPageBrowseUrl  = "/__CKEditor/PageBrowseLinkUrl?";
                filebrowserPageBrowseUrl += Globals.Link_NoEditMode + "=y";
            }
            string url = addonUrl + "full_config.js";

            if (sourceOnly)
            {
                url = addonUrl + "sourceonly_config.js";
            }
            else if (!useSave)
            {
                url = addonUrl + "nosave_config.js";
            }

            HtmlBuilder hb = new HtmlBuilder();

            YTagBuilder tag = new YTagBuilder("textarea");

            tag.AddCssClass("yt_textarea");
            tag.AddCssClass("t_edit");
            FieldSetup(tag, Validation ? FieldType.Validated : FieldType.Normal);
            tag.Attributes.Add("id", ControlId);
            tag.Attributes.Add("data-height", pixHeight.ToString());

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

            TextAreaSetup setup = new TextAreaSetup {
                InPartialView                 = Manager.InPartialView,
                CDNUrl                        = Manager.GetCDNUrl(url),
                PixHeight                     = pixHeight,
                RestrictedHtml                = restrictedHtml,
                FilebrowserImageBrowseUrl     = filebrowserImageBrowseUrl,
                FilebrowserImageBrowseLinkUrl = filebrowserImageBrowseUrl,
                FilebrowserFlashBrowseUrl     = filebrowserFlashBrowseUrl,
                FilebrowserPageBrowseUrl      = filebrowserPageBrowseUrl,
                FilebrowserWindowFeatures     = "modal=yes,location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,alwaysRaised=yes,resizable=yes,scrollbars=yes",
            };

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

            return(hb.ToString());
        }
Ejemplo n.º 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 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());
        }