diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery/jquery-extensions.js b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery/jquery-extensions.js index 52ef81d536..17ee5a0355 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery/jquery-extensions.js +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery/jquery-extensions.js @@ -3,6 +3,10 @@ return; } + var localize = function (key) { + return abp.localization.getResource('AbpUi')(key); + }; + /* A simple jQuery plug-in to make a button busy. */ $.fn.buttonBusy = function (isBusy) { return $(this).each(function () { @@ -127,4 +131,32 @@ }); }; + $.fn.needConfirmationOnUnsavedClose = function () { + var $form = $(this); + var formSaved = false; + var unEditedForm = JSON.stringify($form.serializeFormToObject()); + + var modal = $(this).find('.modal'); + + $(modal).on("hide.bs.modal", function (e) { + var currentForm = JSON.stringify($form.serializeFormToObject()); + var thereAreUnsavedChanges = currentForm !== unEditedForm; + + if (!formSaved && thereAreUnsavedChanges) { + e.preventDefault(); + abp.message.confirm(localize('AreYouSureYouWantToCancelEditingWarningMessage'), + function (result) { + if (result) { + formSaved = true; + $(modal).modal('toggle'); + } + }); + } + }); + + $(this).bind('ajax:complete',function () { + formSaved = true; + }); + }; + })(jQuery); \ No newline at end of file diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json index 9eb47477f4..20b521c7fa 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json @@ -45,6 +45,7 @@ "PagerShowMenuEntries": "Show _MENU_ entries", "DatatableActionDropdownDefaultText": "Actions", "ChangePassword": "Change password", - "PersonalInfo": "My profile" + "PersonalInfo": "My profile", + "AreYouSureYouWantToCancelEditingWarningMessage": "Your changes will be lost." } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json index d45c353878..796c3d0ced 100644 --- a/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json +++ b/framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json @@ -45,6 +45,7 @@ "PagerShowMenuEntries": "Sayfada _MENU_ kayıt göster.", "DatatableActionDropdownDefaultText": "İşlemler", "ChangePassword": "Şifre değiştir", - "PersonalInfo": "Profilim" + "PersonalInfo": "Profilim", + "AreYouSureYouWantToCancelEditingWarningMessage": "Yaptığınız değişiklikler kaybolacak." } } \ No newline at end of file