Skip to content

Commit 9ea4e04

Browse files
committed
opt confirm btn
1 parent f245cb5 commit 9ea4e04

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

adminlte/static/js/adminlte.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@ $(document).ready(function () {
1919

2020
$(".confirm-to-href-btn").on('click', function () {
2121
var href = $(this).data('href');
22+
var title = $(this).data('title') || "Are you sure?";
2223
console.log('start to confirm. href:', href);
23-
if (!href) {
24-
swal("To Coder!", "you need add data-href on your button!");
25-
return false;
26-
}
2724
swal({
28-
title: "Are you sure?",
25+
title: title,
2926
type: "warning",
3027
showCancelButton: true,
3128
confirmButtonClass: "btn-danger",

adminlte/templatetags/adminlte_extras.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ def order_th(context, name, field):
2323

2424

2525
@register.simple_tag
26-
def confirm_btn(view_name, **kwargs):
26+
def confirm_btn(view_name, css_class='btn btn-danger', text="Delete", title="Are you sure?", **kwargs):
2727
"""
2828
a button with confirm, you can just use this tag like {% url 'foo' %}
2929
e.g: {% confirm_btn view_name="foo" pk=permission.id %}
3030
:param view_name: view name
31-
:param kwargs:
31+
:param css_class: css class, default: btn btn-danger
32+
:param text: button text
33+
:param title: title of the confirm box
34+
:param kwargs: kwargs for url reverse
3235
:return:
3336
"""
34-
css_class = kwargs.pop('css_class', 'btn btn-danger')
35-
text = kwargs.pop('text', 'Delete')
3637
url = reverse(view_name, kwargs=kwargs)
3738

38-
return mark_safe("""<button class="%s confirm-to-href-btn" data-href="%s">%s</button>""" % (css_class, url, text))
39+
return mark_safe("""<button class="%s confirm-to-href-btn" data-title="%s" data-href="%s">%s</button>""" % (
40+
css_class, title, url, text))

0 commit comments

Comments
 (0)