Skip to content

Commit

Permalink
Improve bind events
Browse files Browse the repository at this point in the history
  • Loading branch information
JadynWong committed Dec 25, 2023
1 parent 406e554 commit 7a04f75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Expand Up @@ -5,7 +5,7 @@

@foreach (var group in Model.GroupBy(sd => sd.Group2))
{
<form method="post" id="@(group.Key)SettingGroup">
<form method="post" id="@(group.Key)SettingGroup" class="setting-ui">
<abp-card class="mb-3">
<abp-card-header>
<h4>@L[group.Key]</h4>
Expand Down
Expand Up @@ -4,12 +4,8 @@
var l = abp.localization.getResource("EasyAbpAbpSettingUi");

var event_fn = function (id = '') {
$(id + "form").submit(function (e) {
$(id + " form.setting-ui").submit(function (e) {
e.preventDefault();
// Skip abp `EmailSettingsForm`
if (e.currentTarget.id == 'EmailSettingsForm') {
return;
}

if (!$(e.currentTarget).valid()) {
return;
Expand All @@ -23,7 +19,7 @@
});
});

$(id + ".reset").click(function (e) {
$(id + " form.setting-ui .reset").click(function (e) {
var form = e.currentTarget.closest("form");
abp.message.confirm(
l("ResetConfirm", $(form).find("h4").text()),
Expand All @@ -48,15 +44,17 @@

var bind_nav_event_fn = function (element) {
var btn_set = setInterval(function () {
var _id = '#' + element.data('id') + " ";
event_fn(_id);
if ($(_id + " form").length > 0) {
var _id = '#' + element.data('id').replace(/\./g, '-');
if ($(_id + " form.setting-ui").length > 0) {
event_fn(_id);
clearInterval(btn_set);
return;
}

// Rendering is done but not SettingUi.
var target = element.attr('data-bs-target');
if (target !== undefined && $(target).length > 0) {
clearInterval(btn_set);
} else {
var target = element.attr('data-bs-target');
if (target !== undefined && $(target).length > 0) {
clearInterval(btn_set);
}
}
}, 200);
}
Expand All @@ -71,10 +69,10 @@

if (location.hash) {
var index = location.hash.substring(1);
$("#SettingManagementWrapper li.nav-item > a.nav-link")[index].click();
$("#tabs-nav .nav-item .nav-link")[index].click();
history.replaceState(null, null, ' '); // remove hash from the location url
}

// The first nav will automatically click and loading before on this script.
bind_nav_event_fn($("#SettingManagementWrapper li.nav-item > a.nav-link").first());
bind_nav_event_fn($("#tabs-nav .nav-item .nav-link").first());
})(jQuery);

0 comments on commit 7a04f75

Please sign in to comment.