Automatically add busy text to abp-button submit if not provided.

pull/279/head
Halil İbrahim Kalkan 8 years ago
parent f0e8e9519c
commit 89e0c0b4b3

@ -1,11 +1,22 @@
using System;
using Localization.Resources.AbpUi;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Button
{
public class AbpButtonTagHelperService : AbpTagHelperService<AbpButtonTagHelper>
{
protected const string DataBusyTextAttributeName = "data-busy-text";
protected IStringLocalizer<AbpUiResource> L { get; }
public AbpButtonTagHelperService(IStringLocalizer<AbpUiResource> localizer)
{
L = localizer;
}
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "button";
@ -17,10 +28,19 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Button
output.Attributes.AddClass("btn-" + TagHelper.ButtonType.ToString().ToLowerInvariant());
}
if (string.Equals(output.Attributes["type"]?.Value.ToString(), "submit", StringComparison.OrdinalIgnoreCase) &&
!output.Attributes.ContainsName("data-busy-text"))
AddButtonBusyText(context, output);
}
protected virtual void AddButtonBusyText(TagHelperContext context, TagHelperOutput output)
{
if (output.Attributes.ContainsName(DataBusyTextAttributeName))
{
return;
}
if (string.Equals(output.Attributes["type"]?.Value.ToString(), "submit", StringComparison.OrdinalIgnoreCase))
{
output.Attributes.SetAttribute("data-busy-text", "Processing...");
output.Attributes.SetAttribute(DataBusyTextAttributeName, L["ProcessingWithThreeDot"]);
}
}
}

@ -6,6 +6,7 @@
"SavingWithThreeDot": "Saving...",
"Actions": "Actions",
"Delete": "Delete",
"Edit": "Edit"
"Edit": "Edit",
"ProcessingWithThreeDot": "Processing..."
}
}

@ -6,6 +6,7 @@
"SavingWithThreeDot": "Kaydediliyor...",
"Actions": "İşlemler",
"Delete": "Sil",
"Edit": "Düzenle"
"Edit": "Düzenle",
"ProcessingWithThreeDot": "İşleniyor..."
}
}
Loading…
Cancel
Save