From 6fe21af805c3fe469443cbc8d0d344978019d44e Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 16 Jun 2018 09:50:24 +0200 Subject: [PATCH] Add a spinner and disable fields when searching Decitre --- manuels/static/manuels/fetch-isbn.js | 19 +++++++++++++++++++ manuels/templates/manuels/add_book.html | 2 +- manuels/views.py | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/manuels/static/manuels/fetch-isbn.js b/manuels/static/manuels/fetch-isbn.js index 0dfbdf9..1c7eaa5 100644 --- a/manuels/static/manuels/fetch-isbn.js +++ b/manuels/static/manuels/fetch-isbn.js @@ -2,6 +2,15 @@ document.addEventListener("DOMContentLoaded", function (event) { var isbnButton = document.querySelector('#id_isbn_button'); var isbn = document.querySelector('#id_isbn'); isbnButton.addEventListener('click', function (event) { + isbn.setAttribute('disabled', 'disabled'); + isbnButton.setAttribute('disabled', 'disabled'); + document.querySelector('#id_title').setAttribute('disabled', 'disabled'); + document.querySelector('#id_authors').setAttribute('disabled', 'disabled'); + document.querySelector('#id_publication_year').setAttribute('disabled', 'disabled'); + document.querySelector('#id_price').setAttribute('disabled', 'disabled'); + document.querySelector('#id_editor').setAttribute('disabled', 'disabled'); + document.querySelector('#id_other_editor').setAttribute('disabled', 'disabled'); + document.querySelector('#id_isbn_spinner').removeAttribute('hidden'); $.get("/isbn_api/" + isbn.value, {}, function (data, status, xhr) { if (data.error) { isbn.classList.add('is-invalid'); @@ -48,6 +57,16 @@ document.addEventListener("DOMContentLoaded", function (event) { document.querySelector('#id_other_editor').value = data.editor; document.querySelector('#id_other_editor').classList.add('is-valid'); } + + isbn.removeAttribute('disabled'); + isbnButton.removeAttribute('disabled'); + document.querySelector('#id_title').removeAttribute('disabled'); + document.querySelector('#id_authors').removeAttribute('disabled'); + document.querySelector('#id_publication_year').removeAttribute('disabled'); + document.querySelector('#id_price').removeAttribute('disabled'); + document.querySelector('#id_editor').removeAttribute('disabled'); + document.querySelector('#id_other_editor').removeAttribute('disabled'); + document.querySelector('#id_isbn_spinner').setAttribute('hidden', 'hidden'); }); }); }); diff --git a/manuels/templates/manuels/add_book.html b/manuels/templates/manuels/add_book.html index 28d1f7d..e886555 100644 --- a/manuels/templates/manuels/add_book.html +++ b/manuels/templates/manuels/add_book.html @@ -48,7 +48,7 @@ required="" id="{{ form.isbn.auto_id }}" type="text">
diff --git a/manuels/views.py b/manuels/views.py index 2cded29..54c6e39 100644 --- a/manuels/views.py +++ b/manuels/views.py @@ -280,7 +280,8 @@ def isbn_api(request, isbn): title = decitre_soup.select('h1.product-title') if title: title = title[0] - title.span.extract() + if title.span: + title.span.extract() title = title.getText().strip() authors = decitre_soup.select('h2.authors')