Skip to content

Commit c4fc13d

Browse files
committed
Add stripe.js and base.js home static folder
1 parent e7482d0 commit c4fc13d

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

static/js/base.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
$(document).ready(function() {
2+
// Initialise all tooltips
3+
$(function() {
4+
$('[data-toggle="tooltip"]').tooltip();
5+
});
6+
7+
// KANBAN JS
8+
if (window.location.pathname == '/kanban/') {
9+
// Toggle Cancelled column display
10+
$('#cancelled-checkbox').click(function() {
11+
$('.kanban-cancelled')
12+
.parent()
13+
.toggleClass('d-none');
14+
});
15+
}
16+
17+
// USER lIST JS
18+
if (window.location.pathname == '/accounts/user_list/') {
19+
// Initialize DataTables
20+
$('#submitters-table').DataTable({
21+
language: {
22+
search: '_INPUT_',
23+
searchPlaceholder: 'Search...'
24+
},
25+
// Set template of pagination display
26+
oLanguage: {
27+
sLengthMenu: 'Show: _MENU_ users',
28+
sInfo: 'Showing: _START_-_END_ of _TOTAL_'
29+
}
30+
});
31+
$('#assignees-table').DataTable({
32+
language: {
33+
search: '_INPUT_',
34+
searchPlaceholder: 'Search...'
35+
},
36+
// Set template of pagination display
37+
oLanguage: {
38+
sLengthMenu: 'Show: _MENU_ users',
39+
sInfo: 'Showing: _START_-_END_ of _TOTAL_'
40+
}
41+
});
42+
}
43+
44+
// TICKETS JS
45+
if (window.location.pathname == '/tickets/') {
46+
console.log('TICKETS PAGE');
47+
48+
// Field Filtering: Insert a text input to each footer cell of table
49+
$('#tickets-table tfoot th').each(function() {
50+
var title = $(this).text();
51+
$(this).html('<input type="text" placeholder="Search ' + title + '" />');
52+
});
53+
54+
let ticketsTable = $('#tickets-table').DataTable({
55+
// Add Global search box
56+
language: {
57+
search: '_INPUT_',
58+
searchPlaceholder: 'Search All...'
59+
},
60+
// Define Column widths
61+
columnDefs: [
62+
{ width: '16px', targets: [0, 2, 5, 6] },
63+
{ width: '340px', targets: [1] }
64+
],
65+
// Set template of pagination display
66+
oLanguage: {
67+
sLengthMenu: 'Show: _MENU_ tickets',
68+
sInfo: 'Showing: _START_-_END_ of _TOTAL_'
69+
}
70+
});
71+
// Apply the search
72+
// Source: https://datatables.net/examples/api/multi_filter.html
73+
ticketsTable.columns().every(function() {
74+
let that = this;
75+
$('input', this.footer()).on('keyup change clear', function() {
76+
if (that.search() !== this.value) {
77+
that.search(this.value).draw();
78+
}
79+
});
80+
});
81+
// Move to search boxes to head of table
82+
$('#tickets-table tfoot tr').appendTo('#tickets-table thead');
83+
// Set search box placeholders to blank
84+
$('#ticket-search-boxes th input').attr('placeholder', '');
85+
// Clickable row
86+
$('.clickable-row').on('click', function() {
87+
window.location = $(this).data('url');
88+
});
89+
}
90+
});

static/js/stripe.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
$(function() {
2+
$('#payment-form').submit(function() {
3+
var form = this;
4+
var card = {
5+
number: $('#id_credit_card_number').val(),
6+
expMonth: $('#id_expiry_month').val(),
7+
expYear: $('#id_expiry_year').val(),
8+
cvc: $('#id_cvv').val()
9+
};
10+
11+
Stripe.createToken(card, function(status, response) {
12+
if (status === 200) {
13+
$('#credit-card-errors').hide();
14+
$('#id_stripe_id').val(response.id);
15+
$('#id_credit_card_number').removeAttr('name');
16+
$('#id_cvv').removeAttr('name');
17+
$('#id_expiry_month').removeAttr('name');
18+
$('#id_expiry_year').removeAttr('name');
19+
20+
form.submit();
21+
} else {
22+
$('#stripe-error-message').text(response.error.message);
23+
$('#credit-card-errors').show();
24+
$('#validate_card_btn').attr('disabled', false);
25+
}
26+
});
27+
return false;
28+
});
29+
});

0 commit comments

Comments
 (0)