From 89e0c0b4b35b4edeaf95f6485294c1aad76c3dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 1 May 2018 10:18:20 +0300 Subject: [PATCH] Automatically add busy text to abp-button submit if not provided. --- .../Button/AbpButtonTagHelperService.cs | 26 ++++++++++++++++--- .../Localization/Resources/AbpUi/en.json | 3 ++- .../Localization/Resources/AbpUi/tr.json | 3 ++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Button/AbpButtonTagHelperService.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Button/AbpButtonTagHelperService.cs index d56a96a8c7..76adea4e15 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Button/AbpButtonTagHelperService.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Button/AbpButtonTagHelperService.cs @@ -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 { + protected const string DataBusyTextAttributeName = "data-busy-text"; + + protected IStringLocalizer L { get; } + + public AbpButtonTagHelperService(IStringLocalizer 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"]); } } } diff --git a/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json b/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json index 849303c22c..dbd20ba903 100644 --- a/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json +++ b/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json @@ -6,6 +6,7 @@ "SavingWithThreeDot": "Saving...", "Actions": "Actions", "Delete": "Delete", - "Edit": "Edit" + "Edit": "Edit", + "ProcessingWithThreeDot": "Processing..." } } \ No newline at end of file diff --git a/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json b/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json index 70ad3061a5..9fdd55ba69 100644 --- a/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json +++ b/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json @@ -6,6 +6,7 @@ "SavingWithThreeDot": "Kaydediliyor...", "Actions": "İşlemler", "Delete": "Sil", - "Edit": "Düzenle" + "Edit": "Düzenle", + "ProcessingWithThreeDot": "İşleniyor..." } } \ No newline at end of file