From 8c54fce37eb3481079cb5b507b28ed60d79affb5 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Thu, 31 May 2018 08:16:22 +0200 Subject: [PATCH] Allow no book for a level/field. Close #4 --- manuels/forms.py | 4 +++- manuels/static/manuels/no_book.js | 20 ++++++++++++++++++++ manuels/templates/manuels/add_item.html | 5 +++++ manuels/templates/manuels/base.html | 3 +++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 manuels/static/manuels/no_book.js diff --git a/manuels/forms.py b/manuels/forms.py index 83a9891..1a72a5e 100644 --- a/manuels/forms.py +++ b/manuels/forms.py @@ -6,9 +6,11 @@ from manuels.models import Book, SuppliesRequirement class AddBookForm(forms.ModelForm): class Meta: model = Book - exclude = ['done'] + fields = ['teacher', 'level', 'field', 'no_book', 'title', 'authors', 'editor', 'publication_year', + 'isbn', 'price', 'previously_acquired', 'comments', 'add_another'] add_another = forms.BooleanField(label='Ajouter un autre livre', required=False, initial=True) + no_book = forms.BooleanField(label='Pas de livre pour cette classe/matière', required=False, initial=False) class AddSuppliesForm(forms.ModelForm): diff --git a/manuels/static/manuels/no_book.js b/manuels/static/manuels/no_book.js new file mode 100644 index 0000000..2638ecb --- /dev/null +++ b/manuels/static/manuels/no_book.js @@ -0,0 +1,20 @@ +document.addEventListener("DOMContentLoaded", function (event) { + var _selector = document.querySelector('#id_no_book'); + _selector.addEventListener('change', function (event) { + if (_selector.checked) { + document.querySelector('#id_title').value = "PAS DE LIVRE POUR CETTE CLASSE"; + document.querySelector('#id_authors').value = "N/A"; + document.querySelector('#id_editor').value = 1; + document.querySelector('#id_publication_year').value = 1900; + document.querySelector('#id_isbn').value = "0000000000"; + document.querySelector('#id_price').value = 0; + } else { + document.querySelector('#id_title').value = ""; + document.querySelector('#id_authors').value = ""; + document.querySelector('#id_editor').value = ""; + document.querySelector('#id_publication_year').value = ""; + document.querySelector('#id_isbn').value = ""; + document.querySelector('#id_price').value = ""; + } + }); +}); diff --git a/manuels/templates/manuels/add_item.html b/manuels/templates/manuels/add_item.html index 4a53695..c3d9140 100644 --- a/manuels/templates/manuels/add_item.html +++ b/manuels/templates/manuels/add_item.html @@ -1,6 +1,7 @@ {% extends 'manuels/base.html' %} {% load bootstrap4 %} +{% load static %} {% block content %}
@@ -24,4 +25,8 @@
+{% endblock %} + +{% block end_js %} + {% endblock %} \ No newline at end of file diff --git a/manuels/templates/manuels/base.html b/manuels/templates/manuels/base.html index 7926781..8d5287d 100644 --- a/manuels/templates/manuels/base.html +++ b/manuels/templates/manuels/base.html @@ -17,5 +17,8 @@ {% block content %} {% endblock %} + +{% block end_js %} +{% endblock %} \ No newline at end of file