Add a spinner and disable fields when searching Decitre

This commit is contained in:
Gabriel Augendre 2018-06-16 09:50:24 +02:00
parent 9cd41b5a3f
commit 6fe21af805
3 changed files with 22 additions and 2 deletions

View file

@ -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');
});
});
});

View file

@ -48,7 +48,7 @@
required="" id="{{ form.isbn.auto_id }}" type="text">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" id="id_isbn_button">
Chercher sur Decitre
Chercher sur Decitre <i class="fas fa-spinner fa-spin" id="id_isbn_spinner" hidden></i>
</button>
</div>
</div>

View file

@ -280,6 +280,7 @@ def isbn_api(request, isbn):
title = decitre_soup.select('h1.product-title')
if title:
title = title[0]
if title.span:
title.span.extract()
title = title.getText().strip()