Browse Source

Form extension for confirmation before closing the modal without saving in edit modals

pull/983/head
Yunus Emre Kalkan 7 years ago
parent
commit
fd417647b1
  1. 32
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/jquery/jquery-extensions.js
  2. 3
      framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/en.json
  3. 3
      framework/src/Volo.Abp.UI/Localization/Resources/AbpUi/tr.json

32
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);

3
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."
}
}

3
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."
}
}
Loading…
Cancel
Save