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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
diff --git a/budget/templates/budget/index.html b/budget/templates/budget/index.html
index 27c25897aa232234d0acaf6cf0669c3c92720811..079818016b8729aa463be58e4e2f8504d9ab9599 100644
--- a/budget/templates/budget/index.html
+++ b/budget/templates/budget/index.html
@@ -7,28 +7,55 @@ <script src='https://cdn.jsdelivr.net/npm/fullcalendar@6.1.18/index.global.min.js'></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<script>
- let MINT_DEBUG = true;
- const now = new Date();
+ const MINT_DEBUG = "{{ debug }}" === "True";
let calendar;
document.addEventListener('DOMContentLoaded', function () {
- var calendarEl = document.getElementById('calendar');
+ const calendarEl = document.getElementById('calendar');
calendar = new FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth',
dayMaxEventRows: true,
+ customButtons: {
+ admin: {
+ text: "admin",
+ hint: "Django Admin",
+ click: () => {
+ location.href = "{% url 'admin:index' %}";
+ }
+ },
+ copy: {
+ text: "copy",
+ hint: "Copy budget month-to-month",
+ click: () => {
+ Swal.fire({
+ title: "Are you sure?",
+ html: "This will copy <strong>all</strong> budget items from last month.",
+ icon: "warning",
+ allowOutsideClick: false,
+ showDenyButton: true,
+ showCloseButton: true,
+ confirmButtonText: "Yes",
+ reverseButtons: true,
+ showLoaderOnConfirm: true,
+ preConfirm: () => {
+ fetch("/copy/", {
+ method: "POST",
+ headers: {"X-CSRFToken": '{{ csrf_token }}'},
+ body: JSON.stringify({"month": calendar.getDate().getMonth() + 1}),
+ }).then(() => calendar.refetchEvents());
+ }
+ });
+ }
+ }
+ },
headerToolbar: {
- left: 'prev,next today',
+ left: 'prev,next today copy {% if user.is_staff %}admin{% endif %}',
center: 'title',
right: 'dayGridWeek,dayGridMonth,dayGridYear'
},
selectable: true,
select: (info) => {
if (MINT_DEBUG) console.log(info);
- const days = Math.floor(Math.abs(info.end - info.start) / (1000 * 60 * 60 * 24));
- if (days == 1) {
- input(info.start);
- return;
- }
const events = calendar.getEvents().filter((event) => {
const start = event.start;
const end = event.end || event.start;
@@ -51,7 +78,7 @@ start: event.start,
extendedProps: {
title: props.title,
amount: props.amount,
- recurrance: props.recurrance,
+ recurrence: props.recurrence,
week: props.week,
income: props.income
}
@@ -61,21 +88,19 @@ },
eventClick: (info) => {
const event = info.event;
const props = event.extendedProps;
- input(event.start, event.id, props.title, props.amount / 100, props.recurrance, props.income);
- },
- eventClassNames: (info) => {
- const classes = ['cursor-pointer'];
- if (toDate(info.event.start) < toDate(now)) classes.push("bg-gray-500!", "border-gray-500!");
- return classes;
+ input(event.start, event.id, props.title, props.amount / 100, props.recurrence, props.week, props.income);
},
+ navLinks: true,
+ navLinkDayClick: (date) => input(date),
events: "/events/",
});
calendar.render();
});
- function input(time, id = '', title = 'New Transaction', amount = 0, recurrance = "month", income = false) {
+ function input(time, id = '', title = 'New Transaction', amount = 0, recurrence = "M", week = 1, income = false) {
const weekDay = time.getDay();
const monthDay = time.getDate();
+ title = title.replace(/"/g, """)
Swal.fire({
title: `<input type="text" class="font-semibold" name="title" value="${title}"/>`,
html: `
@@ -83,11 +108,11 @@ <div class="grid grid-cols-1 gap-x-4 gap-y-3 items-center text-left">
<input type="hidden" name="id" value="${id}"/>
<input type="hidden" name="date" value="${time.toISOString()}"/>
<label class="font-semibold">Amount: $<input class="border rounded w-30 mx-px p-1" type="number" name="amount" value="${amount}"/></label>
- <label class="font-semibold">Recurring? <input class="border rounded w-4 h-4" type="checkbox" name="recurring" ${recurrance !== "" ? "checked" : ""}/></label>
- <div id="recurringOptions" class="${recurrance !== "" ? "" : "hidden"}">
- <label><input type="radio" name="recurrance" ${recurrance === "month" ? "checked" : ""} value="month"/> Monthly on the ${ordinal(monthDay)}</label>
+ <label class="font-semibold">Recurring? <input class="border rounded w-4 h-4" type="checkbox" name="recurring" ${recurrence !== "" ? "checked" : ""}/></label>
+ <div id="recurringOptions" class="${recurrence !== "" ? "" : "hidden"}">
+ <label><input type="radio" name="recurrence" ${recurrence === "M" ? "checked" : ""} value="M"/> Monthly on the ${ordinal(monthDay)}</label>
<br/>
- <label><input type="radio" name="recurrance" ${recurrance.endsWith("week") ? "checked" : ""} value="week"/> Every <input name="week" class="border rounded w-15 p-1" type="number" min="1" max="4" value="${recurrance.endsWith("week") ? recurrance.substring(0, 1) : "1"}"/> weeks on ${dayOfWeek(weekDay)}</label>
+ <label><input type="radio" name="recurrence" ${recurrence === "W" ? "checked" : ""} value="W"/> Every <input name="week" class="border rounded w-15 p-1" type="number" min="1" max="4" value="${week}"/> weeks on ${dayOfWeek(weekDay)}</label>
</div>
<label class="font-semibold">Income? <input class="border rounded w-4 h-4" type="checkbox" name="income" ${income ? "checked" : ""}/></label>
</div>
@@ -101,7 +126,7 @@ denyButtonText: 'Delete',
customClass: {
confirmButton: 'ml-[15rem]!'
},
- didRender: (swal) => {
+ didRender: () => {
const $recurring = document.querySelector("[name='recurring']");
const $opts = document.getElementById("recurringOptions");
$recurring.addEventListener('change', () => {
@@ -121,7 +146,7 @@ id: $popup.querySelector("[name='id']").value,
date: new Date($popup.querySelector("[name='date']").value),
title: $popup.querySelector("[name='title']").value,
amount: parseFloat($popup.querySelector("[name='amount']").value),
- recurrance: $popup.querySelector("[name='recurring']").checked ? $popup.querySelector("[name='recurrance']:checked").value : '',
+ recurrence: $popup.querySelector("[name='recurring']").checked ? $popup.querySelector("[name='recurrence']:checked").value : '',
week: $popup.querySelector("[name='week']").value,
income: $popup.querySelector("[name='income']").checked
};
@@ -146,7 +171,7 @@ allDay: true,
extendedProps: {
title: value.title,
amount: value.amount * 100,
- recurrance: value.recurrance,
+ recurrence: value.recurrence,
week: value.week,
income: value.income
}
@@ -171,7 +196,6 @@ }
function toast(message, level = "error", duration = 5) {
const Toast = Swal.mixin({
- toast: true,
position: "top-end",
showConfirmButton: false,
timer: duration * 1000,
@@ -197,10 +221,6 @@ }
function dayOfWeek(i = 0) {
return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][i];
- }
-
- function toDate(dt) {
- return new Date(dt.toDateString());
}
</script>
</head>
|