Skip to content

Commit d60939e

Browse files
committed
feat(admin): modernize AJAX handling with data attributes and update version
- Replace `rel="async"` attributes with `data-method` for AJAX links and forms - Add support for flexible HTTP methods via `data-method` attribute - Improve confirmation dialogs with translatable default message - Add `.table-sm` styling for compact table layouts with reduced padding - Streamline AJAX request handling and remove deprecated rel-based approach - Update version to `1.6.11` for this admin interface enhancement
1 parent 6690ce5 commit d60939e

File tree

5 files changed

+39
-44
lines changed

5 files changed

+39
-44
lines changed

css/admin.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,6 +2465,10 @@ table td>input[type="checkbox"] {
24652465
vertical-align: middle;
24662466
}
24672467

2468+
.table-sm > :not(caption) > * > * {
2469+
padding: .325rem .5rem;
2470+
}
2471+
24682472
.navbar-admin {
24692473
background-color: var(--cs-color-blue-navbar);
24702474
color: inherit;

css/admin.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/admin.js

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,23 +1296,20 @@
12961296
* AJAXify anchors with attribute rel="async".
12971297
* @since 1.33
12981298
*/
1299-
$(document).on("click", "a:not([data-confirm])[rel]", function(e) {
1299+
$(document).on("click", "a:not([data-confirm])[data-method]", function(e) {
13001300
var $that = $(this),
1301-
rel = $that.attr("rel"),
1301+
method = $that.data("method")?.toUpperCase() || "GET",
13021302
href = $that.attr("ajaxify") || $that.attr("href");
1303-
if (!href?.length) {
1304-
e.preventDefault();
1305-
return false;
1306-
}
13071303

1308-
// Not valid rel attribute? Proceed by default.
1309-
if (!rel.length || rel !== "async" && rel !== "async-post") {
1304+
if (!href?.length) {
13101305
return;
13111306
}
1307+
13121308
e.preventDefault();
1309+
13131310
csk.ajax.request(href, {
13141311
el: $that,
1315-
type: rel === "async" ? "GET" : "POST",
1312+
type: method,
13161313
beforeSend: function() {
13171314
if ($that.prop("disabled")) {
13181315
return;
@@ -1329,45 +1326,39 @@
13291326
}
13301327
}
13311328
});
1332-
return false;
13331329
});
13341330

13351331
/**
13361332
* We ajaxify forms with attribute rel="async".
13371333
* @since 1.30
13381334
*/
1339-
$(document).on("submit", "form[rel]", function(e) {
1335+
$(document).on("submit", "form[data-method]", function(e) {
13401336
var $form = $(this),
1341-
rel = $form.attr("rel"),
1337+
method = $form.data("method")?.toUpperCase() || "POST",
13421338
href = $form.attr("ajaxify") || $form.attr("action");
13431339

1344-
// No action provided? Nothing to do...
13451340
if (!href?.length) {
1346-
e.preventDefault();
1347-
return false;
1348-
}
1349-
switch (rel) {
1350-
// In case of an asynchronous use.
1351-
case "async":
1352-
e.preventDefault();
1353-
csk.ajax.request(href, {
1354-
el: form,
1355-
type: "POST",
1356-
data: $form.serializeArray(),
1357-
beforeSend: function() {
1358-
if ($form.prop("disabled")) {
1359-
return;
1360-
}
1361-
csk.ui.toggleDisabled($form.find("[type=submit]"), true);
1362-
},
1363-
onComplete: function() {
1364-
$form.trigger("reset");
1365-
csk.ui.toggleDisabled($form.find("[type=submit]"), false);
1366-
setTimeout(location.reload.bind(location), 1500);
1367-
}
1368-
});
1369-
return false;
1341+
return;
13701342
}
1343+
1344+
e.preventDefault();
1345+
1346+
csk.ajax.request(href, {
1347+
el: form,
1348+
type: method,
1349+
data: $form.serializeArray(),
1350+
beforeSend: function() {
1351+
if ($form.prop("disabled")) {
1352+
return;
1353+
}
1354+
csk.ui.toggleDisabled($form.find("[type=submit]"), true);
1355+
},
1356+
onComplete: function() {
1357+
$form.trigger("reset");
1358+
csk.ui.toggleDisabled($form.find("[type=submit]"), false);
1359+
setTimeout(location.reload.bind(location), 1500);
1360+
}
1361+
});
13711362
});
13721363

13731364
/**
@@ -1396,7 +1387,7 @@
13961387
$(document).on("click", "[data-confirm]:not([data-form])", function(e) {
13971388
e.preventDefault();
13981389
var $that = $(this),
1399-
rel = $that.attr("rel"),
1390+
method = $that.data("method")?.toUpperCase(),
14001391
href = $that.attr("ajaxify") || $that.attr("href"),
14011392
data = $that.data("fields"),
14021393
message = $that.data("confirm");
@@ -1413,16 +1404,16 @@
14131404

14141405
// No URL provided? Nothing to do...No message provided? Just proceed.
14151406
if (!message?.length) {
1416-
message = "Are you sure?";
1407+
message = csk.i18n.default?.confirm_action || "Are you sure?";
14171408
}
14181409

14191410
// Display the confirmation box before proceeding.
14201411
return csk.ui.confirm(message, function() {
14211412
// ajax request.
1422-
if (rel?.length) {
1413+
if (method?.length) {
14231414
csk.ajax.request(href, {
14241415
el: $that,
1425-
type: rel === "async" ? "GET" : "POST",
1416+
type: method,
14261417
data: data,
14271418
beforeSend: function() {
14281419
if ($that.prop("disabled")) {

0 commit comments

Comments
 (0)