Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the RenderButtonEdit class
 /// </summary>
 /// <param name="url">URL to the edit action</param>
 public RenderButtonEdit(DataUrl url)
 {
     Url       = url;
     ClassName = QNetButtonClassDefaults.Default;
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the RenderButton class 
 /// </summary>
 /// <param name="url">URL</param>
 public RenderLink(DataUrl url)
 {
     Url = url;
 }
Esempio n. 3
0
    /// <summary>
    /// Erstellt einen neuen <see cref="DataUrl"/>. Löst keine Ausnahme aus, wenn der <see cref="DataUrl"/> nicht erstellt werden kann.
    /// </summary>
    /// <param name="value">Ein <see cref="string"/>, der dem Data-URL-Schema nach RFC 2397 entspricht.</param>
    /// <param name="dataUrl">Enthält nach dem Beenden der Methode einen aus <paramref name="value"/> erstellten <see cref="DataUrl"/>.
    /// Dieser Parameter wird nicht-initialisiert übergeben.</param>
    /// <returns>Ein <see cref="bool"/>-Wert, der <c>true</c> ist, wenn der <see cref="DataUrl"/> erfolgreich erstellt wurde, andernfalls <c>false</c>.</returns>
    public static bool TryCreate(string?value, [NotNullWhen(true)] out DataUrl?dataUrl)
    {
        dataUrl = null;

        if (value is null || !value.StartsWith("data:", StringComparison.OrdinalIgnoreCase))
        {
            return(false);
        }

        const int DATA_PROTOCOL_LENGTH = 5; // 5 == LengthOf "data:"
        const int BASE64_LENGTH        = 7; // 7 = LengthOf ";base64"

        int          endIndex = -1;
        DataEncoding enc      = DataEncoding.UrlEncoded;


        for (int i = DATA_PROTOCOL_LENGTH; i < value.Length; i++)
        {
            char c = value[i];
            if (char.IsWhiteSpace(c))
            {
                return(false);
            }

            if (c == ',')
            {
                endIndex = i;
                break;
            }
        }

        if (endIndex == -1)
        {
            return(false);
        }

        // dies ändert ggf. auch endIndex
        if (HasBase64Encoding(value))
        {
            enc = DataEncoding.Base64;
        }

        var mime = new MimeType(value.Substring(DATA_PROTOCOL_LENGTH, endIndex - DATA_PROTOCOL_LENGTH));

        try
        {
            dataUrl = new DataUrl(value, mime, enc);
        }
        catch
        {
            return(false);
        }

        return(true);


        bool HasBase64Encoding(string val)
        {
            //Suche ";base64"
            int start = endIndex - 1;
            int end   = endIndex - BASE64_LENGTH;

            if (end > DATA_PROTOCOL_LENGTH)
            {
                int index = BASE64_LENGTH - 1;

                for (int i = start; i >= end; i--, index--)
                {
                    char c = char.ToLowerInvariant(val[i]);

                    if (c != ";base64"[index])
                    {
                        return(false);
                    }
                }

                endIndex = end;
                return(true);
            }

            return(false);
        }
    }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the RenderButtonEdit class
 /// </summary>
 /// <param name="url">URL to the edit action</param>
 public RenderButtonView(DataUrl url)
 {
     Url       = url;
     ClassName = NopButtonClassDefaults.Default;
 }
Esempio n. 5
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            (_htmlHelper as IViewContextAware).Contextualize(ViewContext);
            var prefix = ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix;

            var htmlId = prefix.IsEmpty()
                ? ModelItem.Metadata.PropertyName
                : _htmlHelper.IdForModel() != ModelItem.Metadata.PropertyName
                    ? _htmlHelper.IdForModel() + "_" + ModelItem.Metadata.PropertyName
                    : ModelItem.Metadata.PropertyName;

            var htmlName  = prefix.IsEmpty() ? ModelItem.Metadata.PropertyName : prefix + "." + ModelItem.Metadata.PropertyName;
            var labelText = ModelItem.Metadata.DisplayName ?? ModelItem.Metadata.PropertyName ?? htmlId.Split('.').Last();

            if (ItemList == null && ItemList2 == null)
            {
                var comboDataInfo = GetComboBoxDataSource(ModelItem.ModelExplorer);
                ItemList = comboDataInfo.ListItems;
                if (comboDataInfo.CanSelect)
                {
                    if (OptionLabel.IsEmpty())
                    {
                        OptionLabel = UI.Select;
                    }
                }
                else
                {
                    OptionLabel = null;
                }
            }
            var sbOptions = new StringBuilder();

            if (!OptionLabel.IsEmpty())
            {
                sbOptions.AppendLine(string.Concat("<option value=\"\">", OptionLabel, "</option>"));
            }
            if (ItemList != null)
            {
                foreach (var item in ItemList)
                {
                    var option = new TagBuilder("option");
                    option.Attributes.Add("value", item.Value);
                    if (item.Selected)
                    {
                        option.Attributes.Add("selected", "selected");
                    }
                    option.InnerHtml.AppendHtml(item.Text);
                    sbOptions.AppendLine(option.GetString());
                }
            }
            else if (ItemList2 != null)
            {
                foreach (var item in ItemList2)
                {
                    var option = new TagBuilder("option");
                    option.Attributes.Add("value", item.Value);
                    if (item.Selected)
                    {
                        option.Attributes.Add("selected", "selected");
                    }
                    option.InnerHtml.AppendHtml(item.Text);
                    sbOptions.AppendLine(option.GetString());
                }
            }

            if (DisableEditorTemplate)
            {
                output.TagName = "div";
                output.TagMode = TagMode.StartTagAndEndTag;
                output.Attributes.Add("id", "div" + htmlId);
                if (!DisableColSize)
                {
                    output.Attributes.Add("class", $"col-sm-{EditorColCount}");
                }

                var select = new TagBuilder("select");
                if (ReadOnly)
                {
                    select.Attributes.Add("disabled", "disabled");
                }
                if (!DataUrl.IsEmpty())
                {
                    select.Attributes.Add("onChange", $"LoadDropdown('{DataUrl}','{htmlId}', '{(SubComboId.IsEmpty() ? "" : SubComboId)}', '{(OptionLabel.IsEmpty() ? "" : OptionLabel)}');");
                }
                select.Attributes.Add("name", htmlName);
                select.AddCssClass("form-control form-control-sm");
                if (!CssClass.IsEmpty())
                {
                    select.AddCssClass(CssClass);
                }
                select.Attributes.Add("id", htmlId);
                if (ModelItem.Metadata.IsRequired)
                {
                    var requiredAttr = Digger2.GetMetaAttr <RequiredAttribute>(ModelItem.Metadata);
                    var errMsg       = "";
                    if (requiredAttr != null)
                    {
                        errMsg = requiredAttr.ErrorMessage;
                        if (errMsg.IsEmpty() && requiredAttr.ErrorMessageResourceType != null)
                        {
                            var rm  = new ResourceManager(requiredAttr.ErrorMessageResourceType);
                            var rsm = rm.GetString(requiredAttr.ErrorMessageResourceName);
                            if (rsm != null && !rsm.IsEmpty())
                            {
                                errMsg = string.Format(rsm, labelText);
                            }
                        }
                    }
                    select.Attributes.Add("data-val", "true");
                    select.Attributes.Add("data-val-required",
                                          requiredAttr != null
                            ? errMsg
                            : "Gereklidir"
                                          );
                }
                select.InnerHtml.AppendHtml(sbOptions.ToString());
                output.Content.SetHtmlContent(select.GetString());
            }
            else
            {
                output.TagName = "div";
                output.TagMode = TagMode.StartTagAndEndTag;
                output.Attributes.Add("class", "form-group row");
                output.Attributes.Add("id", "div" + htmlId);

                var select = new TagBuilder("select");
                if (ReadOnly)
                {
                    select.Attributes.Add("disabled", "disabled");
                }
                if (!DataUrl.IsEmpty())
                {
                    select.Attributes.Add("onChange", $"LoadDropdown('{DataUrl}','{htmlId}', '{(SubComboId.IsEmpty() ? "" : SubComboId)}', '{(OptionLabel.IsEmpty() ? "" : OptionLabel)}');");
                }
                select.AddCssClass("form-control form-control-sm");
                if (!CssClass.IsEmpty())
                {
                    select.AddCssClass(CssClass);
                }
                select.Attributes.Add("name", htmlName);
                select.Attributes.Add("id", htmlId);

                var irq          = (!IsRequired.HasValue && ModelItem.Metadata.GetIsRequired()) || (IsRequired.HasValue && IsRequired.Value);
                var requiredHtml = irq
                    ? $"<span class=\"{RequiredCssClass}\">{Symbol}</span>"
                    : "";
                var metaHtml = irq
                    ? $"<span class=\"field-validation-valid help-block\" data-valmsg-for=\"{htmlId}\" data-valmsg-replace=\"true\"></span>"
                    : "";

                if (irq)
                {
                    var requiredAttr = Digger2.GetMetaAttr <RequiredAttribute>(ModelItem.Metadata);
                    var errMsg       = "";
                    if (requiredAttr != null)
                    {
                        errMsg = requiredAttr.ErrorMessage;
                        if (errMsg.IsEmpty() && requiredAttr.ErrorMessageResourceType != null)
                        {
                            var rm  = new ResourceManager(requiredAttr.ErrorMessageResourceType);
                            var rsm = rm.GetString(requiredAttr.ErrorMessageResourceName);
                            if (rsm != null && !rsm.IsEmpty())
                            {
                                errMsg = string.Format(rsm, labelText);
                            }
                        }
                    }
                    select.Attributes.Add("data-val", "true");
                    select.Attributes.Add("data-val-required",
                                          requiredAttr != null
                            ? errMsg
                            : "Gereklidir"
                                          );
                }
                select.InnerHtml.AppendHtml(sbOptions.ToString());

                var addHtml = "";
                if (!AddNewUrl.IsEmpty())
                {
                    addHtml = $@"<div class='col-1'>
                <a href='{AddNewUrl}' class='btn btn-sm btn-primary fancyboxAdd fancybox.iframe'><i class='fas fa-plus'></i></a>
            </div>";
                    EditorColCount--;
                }

                var editorTemplate = $@"
                    <label class=""col-{LabelColCount} col-form-label col-form-label-sm"">{labelText} {requiredHtml}</label>
                    <div class=""col-{EditorColCount}"">
                        {select.GetString()}
                        {metaHtml}
                    </div>
                    {addHtml}";
                output.Content.SetHtmlContent(editorTemplate);
            }
        }