Esempio n. 1
0
        public Task <string> RenderViewAsync(PageEarModule module, PageEarModuleController.Model model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            if (Manager.EditMode)
            {
                hb.Append($@"
<div class='{Globals.CssDivWarning}'>
    {HE(this.__ResStr("changeMod", "Change \"Module Settings\" to configure the page ear displayed"))}
</div>");
            }

            if (module.AdImage_Data.Length > 0 && module.CoverImage_Data.Length > 0 && !string.IsNullOrWhiteSpace(module.ClickUrl))
            {
                Manager.ScriptManager.AddLast($@"
$('body').peelback({{
    adImage: '{JE(ImageHTML.FormatUrl(YetaWF.Core.Modules.ModuleImageSupport.ImageType, null, module.AdImage))}',
    peelImage: '{JE(ImageHTML.FormatUrl(YetaWF.Core.Modules.ModuleImageSupport.ImageType, null, module.CoverImage))}',
    clickURL: '{JE(module.ClickUrl)}',
    smallSize: {module.SmallSize},
    bigSize: {module.LargeSize},
    autoAnimate: {(module.Animate ? "true" : "false")},
    //gaTrack: true, //RFFU
    //gaLabel: '#1 Stegosaurus',
    debug: false
}});

// Listen for events that the page is changing
$YetaWF.registerPageChange(true, function () {{
    // when the page is removed, we need to clean up
    $('#peelback').remove();
}});");
            }
            return(Task.FromResult(hb.ToString()));
        }
Esempio 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(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()));
        }
Esempio n. 3
0
        private string GetImage(PageDefinition pageDef)
        {
            string image;
            string type;

            if (pageDef.FavIcon != null)
            {
                type  = PageDefinition.ImageType;
                image = pageDef.FavIcon;
            }
            else if (Module.DefaultImage != null)
            {
                type  = ModuleImageSupport.ImageType;
                image = Module.DefaultImage;
            }
            else
            {
                type  = PageDefinition.ImageType;
                image = Guid.Empty.ToString();
            }
            int size;

            switch (Module.Style)
            {
            default:
            case PageBarModule.PanelStyleEnum.Vertical:
                size = 32;
                break;

            case PageBarModule.PanelStyleEnum.Horizontal:
                size = 32;
                break;
            }
            return(ImageHTML.FormatUrl(type, null, image, size, size, Stretch: true));
        }
Esempio n. 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(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)));
        }
Esempio n. 5
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));
        }
Esempio 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());
        }
Esempio n. 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(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());
        }
Esempio n. 8
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());
        }
Esempio n. 9
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));
        }
Esempio 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 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());
        }
Esempio n. 11
0
        public async Task <ActionResult> RssFeed(Guid moduleGuid)
        {
            TextModule mod = (TextModule)await ModuleDefinition.LoadAsync(moduleGuid, AllowNone : true);

            if (mod == null || !mod.Feed)
            {
                throw new Error(this.__ResStr("noFeed", "The feed is no longer available"));
            }

            ModuleAction action = await mod.GetAction_RssFeedAwait(mod.ModuleGuid);

            string url = action.GetCompleteUrl();

            SyndicationFeed        feed;
            List <SyndicationItem> items = new List <SyndicationItem>();

            feed = new SyndicationFeed(mod.FeedTitle, mod.FeedSummary,
                                       string.IsNullOrWhiteSpace(mod.FeedMainUrl) ? new Uri(url) : new Uri(Manager.CurrentSite.MakeUrl(mod.FeedMainUrl)),
                                       items);

            action = await mod.GetAction_RssDetailAsync(mod.FeedDetailUrl, mod.ModuleGuid, mod.AnchorId);

            url = action.GetCompleteUrl();
            SyndicationItem sItem = new SyndicationItem(mod.Title, mod.Contents, new Uri(url));

            sItem.PublishDate = mod.FeedPublishDate ?? DateTime.MinValue;
            items.Add(sItem);

            if (mod.FeedImage != null)
            {
                feed.ImageUrl = new Uri(Manager.CurrentSite.MakeUrl(ImageHTML.FormatUrl(YetaWF.Core.Modules.ModuleImageSupport.ImageType, null, mod.FeedImage, CacheBuster: mod.DateUpdated.Ticks.ToString())));
            }
            feed.LastUpdatedTime = mod.FeedUpdateDate ?? DateTime.MinValue;

            return(new RssResult(feed));
        }
Esempio n. 12
0
        // Windows RSS Publisher's Guide http://blogs.msdn.com/b/rssteam/archive/2005/08/02/publishersguide.aspx

        public async Task <ActionResult> RssFeed(int?blogCategory)
        {
            BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync();

            if (!config.Feed)
            {
                throw new Error(this.__ResStr("noFeed", "The feed is no longer available"));
            }

            int          categoryIdentity = blogCategory ?? 0;
            BlogCategory category         = null;

            if (categoryIdentity != 0)
            {
                using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) {
                    category = await categoryDP.GetItemAsync(categoryIdentity);

                    if (!category.Syndicated)
                    {
                        throw new Error(this.__ResStr("noFeed", "The feed is no longer available"));
                    }
                }
            }

            using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) {
                List <DataProviderSortInfo> sort = new List <DataProviderSortInfo> {
                    new DataProviderSortInfo {
                        Field = nameof(BlogEntry.DatePublished), Order = DataProviderSortInfo.SortDirection.Descending
                    },
                };
                List <DataProviderFilterInfo> filters = new List <DataProviderFilterInfo> {
                    new DataProviderFilterInfo {
                        Field = nameof(BlogEntry.Published), Operator = "==", Value = true
                    },
                };
                if (categoryIdentity != 0)
                {
                    filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo {
                        Field = nameof(BlogEntry.CategoryIdentity), Operator = "==", Value = categoryIdentity
                    });
                }
                DataProviderGetRecords <BlogEntry> data = await dataProvider.GetItemsAsync(0, 0, sort, filters);

                string url = string.IsNullOrWhiteSpace(config.FeedMainUrl) ? Manager.CurrentSite.HomePageUrl : config.FeedMainUrl;

                List <SyndicationItem> items   = new List <SyndicationItem>();
                EntryDisplayModule     dispMod = new EntryDisplayModule();

                DateTime lastUpdated = DateTime.MinValue;
                foreach (BlogEntry blogEntry in data.Data)
                {
                    if (categoryIdentity == 0)
                    {
                        using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) {
                            category = await categoryDP.GetItemAsync(blogEntry.CategoryIdentity);

                            if (!category.Syndicated)
                            {
                                continue;
                            }
                        }
                    }
                    ModuleAction viewAction = await dispMod.GetAction_DisplayAsync(blogEntry.Identity);

                    if (viewAction == null)
                    {
                        continue;
                    }
                    SyndicationItem sItem   = new SyndicationItem(blogEntry.Title.ToString(), blogEntry.Text, new Uri(viewAction.GetCompleteUrl()));
                    DateTime        updDate = blogEntry.DateUpdated ?? blogEntry.DateCreated;
                    sItem.LastUpdatedTime = updDate;
                    if (!string.IsNullOrEmpty(category.SyndicationEmail))
                    {
                        sItem.Authors.Add(new SyndicationPerson(category.SyndicationEmail));
                    }
                    sItem.Categories.Add(new SyndicationCategory(category.Category.ToString()));
                    if (!string.IsNullOrEmpty(category.SyndicationCopyright.ToString()))
                    {
                        sItem.Copyright = new TextSyndicationContent(category.SyndicationCopyright.ToString());
                    }
                    sItem.PublishDate = blogEntry.DatePublished;
                    if (!string.IsNullOrEmpty(blogEntry.DisplayableSummary))
                    {
                        sItem.Summary = new TextSyndicationContent(blogEntry.DisplayableSummary);
                    }
                    lastUpdated = updDate > lastUpdated ? updDate : lastUpdated;

                    items.Add(sItem);
                }

                SyndicationFeed feed;
                if (categoryIdentity != 0)
                {
                    feed = new SyndicationFeed(category.Category.ToString(), category.Description.ToString(), new Uri(Manager.CurrentSite.MakeUrl(url)), items);
                }
                else
                {
                    feed = new SyndicationFeed(config.FeedTitle, config.FeedSummary, new Uri(Manager.CurrentSite.MakeUrl(url)), items);
                }
                if (config.FeedImage != null)
                {
                    feed.ImageUrl = new Uri(Manager.CurrentSite.MakeUrl(ImageHTML.FormatUrl(BlogConfigData.ImageType, null, config.FeedImage))); //$$$ caching issue
                }
                if (lastUpdated != DateTime.MinValue)
                {
                    feed.LastUpdatedTime = lastUpdated;
                }
                return(new RssResult(feed));
            }
        }
Esempio n. 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(string model)
        {
            HtmlBuilder hb = new HtmlBuilder();

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

            string imageType = PropData.GetAdditionalAttributeValue <string>("ImageType", null);
            int    width     = PropData.GetAdditionalAttributeValue("Width", 0);
            int    height    = PropData.GetAdditionalAttributeValue("Height", 0);

            if (string.IsNullOrWhiteSpace(imageType) && model != null && (model.IsAbsoluteUrl() || model.StartsWith("/") || model.StartsWith("data:")))
            {
                if (width != 0 || height != 0)
                {
                    throw new InternalError("Can't use Width or Height with external Urls");
                }

                YTagBuilder img = new YTagBuilder("img");
                img.Attributes.Add("src", model);
                if (!img.Attributes.ContainsKey("alt"))
                {
                    img.Attributes.Add("alt", __ResStr("altImage", "Image"));
                }
                hb.Append(img.ToString(YTagRenderMode.Normal));
            }
            else
            {
                if (string.IsNullOrWhiteSpace(imageType))
                {
                    throw new InternalError("No ImageType specified");
                }

                bool showMissing = PropData.GetAdditionalAttributeValue("ShowMissing", true);
                if (string.IsNullOrWhiteSpace(model) && !showMissing)
                {
                    return(Task.FromResult <string>(null));
                }

                string alt = null;
                if (HtmlAttributes.ContainsKey("alt"))
                {
                    alt = (string)HtmlAttributes["alt"];
                }
                string imgTag = ImageComponentBase.RenderImage(imageType, width, height, model, Alt: alt);

                bool linkToImage = PropData.GetAdditionalAttributeValue("LinkToImage", false);
                if (linkToImage)
                {
                    YTagBuilder link   = new YTagBuilder("a");
                    string      imgUrl = ImageHTML.FormatUrl(imageType, null, model);
                    link.MergeAttribute("href", imgUrl);
                    link.MergeAttribute("target", "_blank");
                    link.MergeAttribute("rel", "noopener noreferrer");
                    link.InnerHtml = imgTag;
                    hb.Append(link.ToString(YTagRenderMode.Normal));
                }
                else
                {
                    hb.Append(imgTag);
                }
            }

            hb.Append("</div>");
            return(Task.FromResult(hb.ToString()));
        }
Esempio 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(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()));
        }
Esempio 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 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());
        }
Esempio n. 16
0
 public string MakeFlashUrl(string filename, int width = 0, int height = 0)
 {
     // always defeat browser caching for image selection
     return(ImageHTML.FormatUrl(ImageSupport.ImageType, string.Format("{0},{1},{2}", FolderGuid.ToString(), SubFolder, FileType), filename, width, height, CacheBuster: DateTime.UtcNow.Ticks.ToString()));
 }
Esempio n. 17
0
        internal static async Task <string> RenderActionAsync(ModuleAction action, ModuleAction.RenderModeEnum mode, string id,
                                                              ModuleAction.RenderEngineEnum RenderEngine = ModuleAction.RenderEngineEnum.KendoMenu, int BootstrapSmartMenuLevel = 0, bool HasSubmenu = false)
        {
            // check if we're in the right mode
            if (!await action.RendersSomethingAsync())
            {
                return(null);
            }

            await Manager.AddOnManager.AddTemplateFromUIHintAsync("ActionIcons");// this is needed because we're not used by templates

            if (!string.IsNullOrWhiteSpace(action.ConfirmationText) && (action.Style != ModuleAction.ActionStyleEnum.Post && action.Style != ModuleAction.ActionStyleEnum.Nothing))
            {
                throw new InternalError("When using ConfirmationText, the Style property must be set to Post");
            }
            if (!string.IsNullOrWhiteSpace(action.PleaseWaitText) && (action.Style != ModuleAction.ActionStyleEnum.Normal && action.Style != ModuleAction.ActionStyleEnum.Post))
            {
                throw new InternalError("When using PleaseWaitText, the Style property must be set to Normal or Post");
            }
            if (action.CookieAsDoneSignal && action.Style != ModuleAction.ActionStyleEnum.Normal)
            {
                throw new InternalError("When using CookieAsDoneSignal, the Style property must be set to Normal");
            }

            ModuleAction.ActionStyleEnum style = action.Style;
            if (style == ModuleAction.ActionStyleEnum.OuterWindow)
            {
                if (!Manager.IsInPopup)
                {
                    style = ModuleAction.ActionStyleEnum.Normal;
                }
            }

            if (style == ModuleAction.ActionStyleEnum.Popup || style == ModuleAction.ActionStyleEnum.PopupEdit)
            {
                if (Manager.IsInPopup)
                {
                    style = ModuleAction.ActionStyleEnum.NewWindow;
                }
            }

            if (style == ModuleAction.ActionStyleEnum.Popup || style == ModuleAction.ActionStyleEnum.PopupEdit || style == ModuleAction.ActionStyleEnum.ForcePopup)
            {
                await YetaWFCoreRendering.Render.AddPopupsAddOnsAsync();
            }

            bool newWindow = false, outerWindow = false;
            bool popup = false, popupEdit = false;
            bool nothing = false, post = false;

            switch (style)
            {
            default:
            case ModuleAction.ActionStyleEnum.Normal:
                break;

            case ModuleAction.ActionStyleEnum.NewWindow:
                newWindow = true;
                break;

            case ModuleAction.ActionStyleEnum.Popup:
            case ModuleAction.ActionStyleEnum.ForcePopup:
                popup = Manager.CurrentSite.AllowPopups;
                break;

            case ModuleAction.ActionStyleEnum.PopupEdit:
                popup     = Manager.CurrentSite.AllowPopups;
                popupEdit = Manager.CurrentSite.AllowPopups;
                break;

            case ModuleAction.ActionStyleEnum.OuterWindow:
                outerWindow = true;
                break;

            case ModuleAction.ActionStyleEnum.Nothing:
                nothing = true;
                break;

            case ModuleAction.ActionStyleEnum.Post:
                post = true;
                break;
            }

            YTagBuilder tag = new YTagBuilder("a");

            if (!string.IsNullOrWhiteSpace(action.Tooltip))
            {
                tag.MergeAttribute(Basics.CssTooltip, action.Tooltip);
            }
            if (!string.IsNullOrWhiteSpace(action.Name))
            {
                tag.MergeAttribute("data-name", action.Name);
            }
            if (!action.Displayed)
            {
                tag.MergeAttribute("style", "display:none");
            }
            if (HasSubmenu)
            {
                if (RenderEngine == ModuleAction.RenderEngineEnum.BootstrapSmartMenu)
                {
                    tag.AddCssClass("dropdown-toggle");
                    tag.Attributes.Add("data-toggle", "dropdown-toggle");
                }
                tag.Attributes.Add("aria-haspopup", "true");
                tag.Attributes.Add("aria-expanded", "false");
            }
            if (RenderEngine == ModuleAction.RenderEngineEnum.BootstrapSmartMenu)
            {
                tag.AddCssClass(BootstrapSmartMenuLevel <= 1 ? "nav-link" : "dropdown-item");
            }

            if (!string.IsNullOrWhiteSpace(id))
            {
                tag.Attributes.Add("id", id);
            }

            if (!string.IsNullOrWhiteSpace(action.CssClass))
            {
                tag.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(action.CssClass));
            }
            string extraClass;

            switch (mode)
            {
            default:
            case ModuleAction.RenderModeEnum.Button: extraClass = "y_act_button"; break;

            case ModuleAction.RenderModeEnum.ButtonIcon: extraClass = "y_act_buttonicon"; break;

            case ModuleAction.RenderModeEnum.ButtonOnly: extraClass = "y_act_buttononly"; break;

            case ModuleAction.RenderModeEnum.IconsOnly: extraClass = "y_act_icon"; break;

            case ModuleAction.RenderModeEnum.LinksOnly: extraClass = "y_act_link"; break;

            case ModuleAction.RenderModeEnum.NormalLinks: extraClass = "y_act_normlink"; break;

            case ModuleAction.RenderModeEnum.NormalMenu: extraClass = "y_act_normmenu"; break;
            }
            tag.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(extraClass));

            string url = action.GetCompleteUrl(OnPage: true);

            if (!string.IsNullOrWhiteSpace(url))
            {
                tag.MergeAttribute("href", Utility.UrlEncodePath(url));
                if (Manager.CurrentPage != null)
                {
                    string currUrl = Manager.CurrentPage.EvaluatedCanonicalUrl;
                    if (!string.IsNullOrWhiteSpace(currUrl) && currUrl != "/")  // this doesn't work on home page because everything matches
                    {
                        if (action.Url == currUrl)
                        {
                            tag.AddCssClass("t_currenturl");
                        }
                        if (currUrl.StartsWith(action.Url))
                        {
                            tag.AddCssClass("t_currenturlpart");
                        }
                    }
                }
            }
            else
            {
                tag.MergeAttribute("href", "javascript:void(0);");
            }

            if (!string.IsNullOrWhiteSpace(action.ConfirmationText))
            {
                if (action.Category == ModuleAction.ActionCategoryEnum.Delete)
                {
                    // confirm deletions?
                    if (UserSettings.GetProperty <bool>("ConfirmDelete"))
                    {
                        tag.MergeAttribute(Basics.CssConfirm, action.ConfirmationText);
                    }
                }
                else
                {
                    // confirm actions?
                    if (UserSettings.GetProperty <bool>("ConfirmActions"))
                    {
                        tag.MergeAttribute(Basics.CssConfirm, action.ConfirmationText);
                    }
                }
            }
            if (!string.IsNullOrWhiteSpace(action.PleaseWaitText))
            {
                tag.MergeAttribute(Basics.CssPleaseWait, action.PleaseWaitText);
            }
            if (action.CookieAsDoneSignal)
            {
                tag.Attributes.Add(Basics.CookieDoneCssAttr, "");
            }
            if (action.SaveReturnUrl)
            {
                tag.Attributes.Add(Basics.CssSaveReturnUrl, "");
                if (!action.AddToOriginList)
                {
                    tag.Attributes.Add(Basics.CssDontAddToOriginList, "");
                }
            }
            if (!string.IsNullOrWhiteSpace(action.ExtraData))
            {
                tag.Attributes.Add(Basics.CssExtraData, action.ExtraData);
            }
            if (action.NeedsModuleContext)
            {
                tag.Attributes.Add(Basics.CssAddModuleContext, "");
            }

            if (post)
            {
                tag.Attributes.Add(Basics.PostAttr, "");
            }
            if (action.DontFollow || action.CookieAsDoneSignal || post || nothing)
            {
                tag.MergeAttribute("rel", "nofollow"); // this is so bots don't follow this assuming it's a simple page (Post actions can't be retrieved with GET/HEAD anyway)
            }
            if (outerWindow)
            {
                tag.Attributes.Add(Basics.CssOuterWindow, "");
            }
            if (!nothing)
            {
                tag.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(Basics.CssActionLink));
            }
            if (newWindow)
            {
                tag.MergeAttribute("target", "_blank");
                tag.MergeAttribute("rel", "noopener noreferrer");
            }
            if (popup)
            {
                tag.AddCssClass(Manager.AddOnManager.CheckInvokedCssModule(Basics.CssPopupLink));
                if (popupEdit)
                {
                    tag.Attributes.Add(Basics.CssAttrDataSpecialEdit, "");
                }
            }
            if (mode == ModuleAction.RenderModeEnum.Button || mode == ModuleAction.RenderModeEnum.ButtonIcon || mode == ModuleAction.RenderModeEnum.ButtonOnly)
            {
                tag.Attributes.Add(Basics.CssAttrActionButton, "");
            }

            bool   hasText = false, hasImg = false;
            string innerHtml = "";

            if (mode != ModuleAction.RenderModeEnum.LinksOnly && mode != ModuleAction.RenderModeEnum.ButtonOnly && !string.IsNullOrWhiteSpace(action.ImageUrlFinal))
            {
                string text = mode == ModuleAction.RenderModeEnum.NormalMenu ? action.MenuText : action.LinkText;
                if (RenderEngine == ModuleAction.RenderEngineEnum.KendoMenu)
                {
                    innerHtml += ImageHTML.BuildKnownIcon(action.ImageUrlFinal, alt: text, cssClass: Basics.CssNoTooltip + " k-image"); // k-image is needed to align <i> and <img> correctly
                }
                else
                {
                    innerHtml += ImageHTML.BuildKnownIcon(action.ImageUrlFinal, alt: text, cssClass: Basics.CssNoTooltip);
                }
                hasImg = true;
            }
            if (mode != ModuleAction.RenderModeEnum.IconsOnly && mode != ModuleAction.RenderModeEnum.ButtonIcon)
            {
                string text = mode == ModuleAction.RenderModeEnum.NormalMenu ? action.MenuText : action.LinkText;
                if (!string.IsNullOrWhiteSpace(text))
                {
                    innerHtml += Utility.HtmlEncode(text);
                    hasText    = true;
                }
            }
            if (hasText)
            {
                if (hasImg)
                {
                    tag.AddCssClass("y_act_textimg");
                }
                else
                {
                    tag.AddCssClass("y_act_text");
                }
            }
            else
            {
                if (hasImg)
                {
                    tag.AddCssClass("y_act_img");
                }
            }
            if (HasSubmenu && RenderEngine == ModuleAction.RenderEngineEnum.BootstrapSmartMenu)
            {
                innerHtml += " <span class='caret'></span>";
            }

            tag.AddCssClass(Globals.CssModuleNoPrint);
            tag.InnerHtml = innerHtml;

            return(tag.ToString(YTagRenderMode.Normal));
        }
Esempio n. 18
0
        /// <summary>
        /// Renders a text input control.
        /// </summary>
        /// <param name="component">The current component being rendered.</param>
        /// <param name="model">The model.</param>
        /// <param name="templateCssClass">The CSS class to add to the template (starting with yt_).</param>
        /// <returns>The component rendered as HTML.</returns>
        public static async Task <string> RenderTextAsync(YetaWFComponent component, string model, string templateCssClass)
        {
            await IncludeExplicitAsync();

            HtmlBuilder hb = new HtmlBuilder();

            component.UseSuppliedIdAsControlId();

            YTagBuilder tag = new YTagBuilder("input");

            if (!string.IsNullOrWhiteSpace(templateCssClass))
            {
                tag.AddCssClass(templateCssClass);
            }
            tag.AddCssClass("yt_text_base");
            // 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_edit");
            component.FieldSetup(tag, component.Validation ? FieldType.Validated : FieldType.Normal);
            tag.Attributes.Add("id", component.ControlId);
            //string id = null;
            //if (!string.IsNullOrWhiteSpace(mask)) {
            //    id = component.MakeId(tag);
            //}
            if (Manager.CurrentModule != null && Manager.CurrentModule.FormAutoComplete)
            {
                tag.MergeAttribute("autocomplete", "on", replaceExisting: false);
            }
            else
            {
                tag.MergeAttribute("autocomplete", "new-password", replaceExisting: false);
            }

            bool copy = component.PropData.GetAdditionalAttributeValue <bool>("Copy", false);
            //string mask = component.PropData.GetAdditionalAttributeValue<string>("Mask", null);

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

            if (lenAttr != null)
            {
#if DEBUG
                if (tag.Attributes.ContainsKey("maxlength"))
                {
                    throw new InternalError("Both StringLengthAttribute and maxlength specified - {0}", component.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 - {0}", component.FieldName);
            }
#endif
            // text
            tag.MergeAttribute("type", "text");
            tag.MergeAttribute("value", model ?? "");

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

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

            //if (!string.IsNullOrWhiteSpace(mask)) {
            //    // if there is a Mask we need to use the KendoMaskedTextBox
            //    await KendoUICore.AddFileAsync("kendo.maskedtextbox.min.js");
            //    ScriptBuilder sb = new ScriptBuilder();
            //    sb.Append("$('#{0}').kendoMaskedTextBox({{ mask: '{1}' }});\n", id, Utility.JserEncode(mask));
            //    Manager.ScriptManager.AddLastDocumentReady(sb);
            //}
            //Manager.ScriptManager.AddLast($@"new YetaWF_ComponentsHTML.TextEditComponent('{component.ControlId}');");

            return(hb.ToString());
        }
Esempio n. 19
0
        public async Task <string> RenderAsync(int model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            string type = PropData.GetAdditionalAttributeValue <string>("Force", null);

            if (type == "Grid" || (await IsLargeUserBaseAsync() && type != "DropDown"))
            {
                string hiddenId = UniqueId();
                string allId    = UniqueId();
                string nameId   = UniqueId();
                string noUser   = __ResStr("noUser", "(none)");

                bool header = PropData.GetAdditionalAttributeValue("Header", true);

                UserIdUI ui = new UserIdUI {
                    UserId = model,
                };
                using (UserDefinitionDataProvider userDP = new UserDefinitionDataProvider()) {
                    UserDefinition user = await userDP.GetItemByUserIdAsync(model);

                    if (user == null)
                    {
                        ui.UserName = __ResStr("noUser", "(none)");
                    }
                    else
                    {
                        ui.UserName = user.UserName;
                    }
                }

                ui.AllUsers    = GetGridAllUsersModel(header);
                ui.AllUsers.Id = allId;

                hb.Append($@"
<div class='yt_yetawf_identity_userid t_large t_edit' id='{DivId}'>
    {await HtmlHelper.ForEditComponentAsync(Container, PropertyName, model, "Hidden", HtmlAttributes: new { id = hiddenId, __NoTemplate = true })}");

                using (Manager.StartNestedComponent(FieldName)) {
                    hb.Append($@"
    <div class='t_name'>
        {await HtmlHelper.ForDisplayAsync(ui, nameof(ui.UserName), HtmlAttributes: new { id = nameId })}
        {ImageHTML.BuildKnownIcon("#RemoveLight", title: __ResStr("ttClear", "Clear the current selection"), cssClass: "t_clear")}
    </div>
    {await HtmlHelper.ForLabelAsync(ui, nameof(ui.AllUsers))}
    {await HtmlHelper.ForDisplayAsync(ui, nameof(ui.AllUsers))}");
                }
                hb.Append($@"
</div>");

                UserIdSetup setup = new UserIdSetup {
                    GridAllId = ui.AllUsers.Id,
                    HiddenId  = hiddenId,
                    NameId    = nameId,
                    NoUser    = noUser,
                };

                Manager.ScriptManager.AddLast($@"new YetaWF_Identity.UserIdEditComponent('{DivId}', {Utility.JsonSerialize(setup)});");
            }
            else
            {
                hb.Append($@"
<div class='yt_yetawf_identity_userid t_small t_edit'>");

                using (UserDefinitionDataProvider userDP = new UserDefinitionDataProvider()) {
                    List <DataProviderSortInfo> sorts = null;
                    DataProviderSortInfo.Join(sorts, new DataProviderSortInfo {
                        Field = nameof(UserDefinition.UserName), Order = DataProviderSortInfo.SortDirection.Ascending
                    });
                    DataProviderGetRecords <UserDefinition> recs = await userDP.GetItemsAsync(0, MAXUSERS, sorts, null);

                    List <SelectionItem <int> > list = (from u in recs.Data select new SelectionItem <int> {
                        Text = u.UserName,
                        Value = u.UserId,
                    }).ToList();
                    list.Insert(0, new SelectionItem <int> {
                        Text  = __ResStr("select", "(select)"),
                        Value = 0,
                    });
                    hb.Append(await DropDownListIntComponent.RenderDropDownListAsync(this, model, list, null));
                }

                hb.Append($@"
</div>");
            }
            return(hb.ToString());
        }