Compare commits
2 Commits
b78c4ba9c5
...
a3042caa20
Author | SHA1 | Date |
---|---|---|
Lukáš Kucharczyk | a3042caa20 | |
Lukáš Kucharczyk | 7997f9bbb2 |
|
@ -2,6 +2,11 @@ from django import forms
|
||||||
|
|
||||||
from games.models import Game, Platform, Purchase, Session, Edition, Device
|
from games.models import Game, Platform, Purchase, Session, Edition, Device
|
||||||
|
|
||||||
|
custom_date_widget = forms.DateInput(attrs={"type": "date"})
|
||||||
|
custom_datetime_widget = forms.DateTimeInput(
|
||||||
|
attrs={"type": "datetime-local"}, format="%Y-%m-%d %H:%M"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SessionForm(forms.ModelForm):
|
class SessionForm(forms.ModelForm):
|
||||||
purchase = forms.ModelChoiceField(
|
purchase = forms.ModelChoiceField(
|
||||||
|
@ -9,6 +14,10 @@ class SessionForm(forms.ModelForm):
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
widgets = {
|
||||||
|
"timestamp_start": custom_datetime_widget,
|
||||||
|
"timestamp_end": custom_datetime_widget,
|
||||||
|
}
|
||||||
model = Session
|
model = Session
|
||||||
fields = [
|
fields = [
|
||||||
"purchase",
|
"purchase",
|
||||||
|
@ -30,6 +39,10 @@ class PurchaseForm(forms.ModelForm):
|
||||||
platform = forms.ModelChoiceField(queryset=Platform.objects.order_by("name"))
|
platform = forms.ModelChoiceField(queryset=Platform.objects.order_by("name"))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
widgets = {
|
||||||
|
"date_purchased": custom_date_widget,
|
||||||
|
"date_refunded": custom_date_widget,
|
||||||
|
}
|
||||||
model = Purchase
|
model = Purchase
|
||||||
fields = [
|
fields = [
|
||||||
"edition",
|
"edition",
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
function elt(type, props, ...children) {
|
||||||
|
let dom = document.createElement(type);
|
||||||
|
if (props) Object.assign(dom, props);
|
||||||
|
for (let child of children) {
|
||||||
|
if (typeof child != "string") dom.appendChild(child);
|
||||||
|
else dom.appendChild(document.createTextNode(child));
|
||||||
|
}
|
||||||
|
return dom;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Node} targetNode
|
||||||
|
*/
|
||||||
|
function addToggleButton(targetNode) {
|
||||||
|
let manualToggleButton = elt(
|
||||||
|
"td",
|
||||||
|
{},
|
||||||
|
elt(
|
||||||
|
"div",
|
||||||
|
{ className: "basic-button" },
|
||||||
|
elt(
|
||||||
|
"button",
|
||||||
|
{
|
||||||
|
onclick: (event) => {
|
||||||
|
let textInputField = elt("input", { type: "text", id: targetNode.id });
|
||||||
|
targetNode.replaceWith(textInputField);
|
||||||
|
event.target.addEventListener("click", (event) => {
|
||||||
|
textInputField.replaceWith(targetNode);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Toggle manual"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
targetNode.parentElement.appendChild(manualToggleButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggleableFields = ["#id_game", "#id_edition", "#id_platform"];
|
||||||
|
|
||||||
|
toggleableFields.map((selector) => {
|
||||||
|
addToggleButton(document.querySelector(selector));
|
||||||
|
});
|
|
@ -149,3 +149,5 @@ if _csrf_trusted_origins:
|
||||||
CSRF_TRUSTED_ORIGINS = _csrf_trusted_origins.split(",")
|
CSRF_TRUSTED_ORIGINS = _csrf_trusted_origins.split(",")
|
||||||
else:
|
else:
|
||||||
CSRF_TRUSTED_ORIGINS = []
|
CSRF_TRUSTED_ORIGINS = []
|
||||||
|
|
||||||
|
USE_L10N = False
|
||||||
|
|
Loading…
Reference in New Issue