-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathplugins.js
119 lines (107 loc) · 3.5 KB
/
plugins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* Place any jQuery/helper plugins in here.
*/
$(function () {
/**
* Checkbox tree for permission selecting
*/
let permissionTree = $('.permission-tree :checkbox');
permissionTree.on('click change', function (){
if($(this).is(':checked')) {
$(this).siblings('ul').find('input[type="checkbox"]').attr('checked', true).attr('disabled', true);
} else {
$(this).siblings('ul').find('input[type="checkbox"]').removeAttr('checked').removeAttr('disabled');
}
});
permissionTree.each(function () {
if($(this).is(':checked')) {
$(this).siblings('ul').find('input[type="checkbox"]').attr('checked', true).attr('disabled', true);
}
});
/**
* Disable submit inputs in the given form
*
* @param form
*/
function disableSubmitButtons(form) {
form.find('input[type="submit"]').attr('disabled', true);
form.find('button[type="submit"]').attr('disabled', true);
}
/**
* Enable the submit inputs in a given form
*
* @param form
*/
function enableSubmitButtons(form) {
form.find('input[type="submit"]').removeAttr('disabled');
form.find('button[type="submit"]').removeAttr('disabled');
}
/**
* Disable all submit buttons once clicked
*/
$('form').submit(function () {
disableSubmitButtons($(this));
return true;
});
/**
* Add a confirmation to a delete button/form
*/
$('body').on('submit', 'form[name=delete-item]', function(e) {
e.preventDefault();
Swal.fire({
title: 'Are you sure you want to delete this item?',
showCancelButton: true,
confirmButtonText: 'Confirm Delete',
cancelButtonText: 'Cancel',
icon: 'warning'
}).then((result) => {
if (result.value) {
this.submit()
} else {
enableSubmitButtons($(this));
}
});
})
.on('submit', 'form[name=confirm-item]', function (e) {
e.preventDefault();
Swal.fire({
title: 'Are you sure you want to do this?',
showCancelButton: true,
confirmButtonText: 'Continue',
cancelButtonText: 'Cancel',
icon: 'warning'
}).then((result) => {
if (result.value) {
this.submit()
} else {
enableSubmitButtons($(this));
}
});
})
.on('click', 'a[name=confirm-item]', function (e) {
/**
* Add an 'are you sure' pop-up to any button/link
*/
e.preventDefault();
Swal.fire({
title: 'Are you sure you want to do this?',
showCancelButton: true,
confirmButtonText: 'Continue',
cancelButtonText: 'Cancel',
icon: 'info',
}).then((result) => {
result.value && window.location.assign($(this).attr('href'));
});
});
// Remember tab on page load
$('a[data-toggle="tab"], a[data-toggle="pill"]').on('shown.bs.tab', function (e) {
let hash = $(e.target).attr('href');
history.pushState ? history.pushState(null, null, hash) : location.hash = hash;
});
let hash = window.location.hash;
if (hash) {
$('.nav-link[href="'+hash+'"]').tab('show');
}
// Enable tooltips everywhere
$('[data-toggle="tooltip"]').tooltip();
});