Esempio 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 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());
        }