diff --git a/public/assets/css/app.css b/public/assets/css/app.css index 09d1537538acb2def9c23555e020096e9de4ec86..4116d92289934a8735ad358ac43a6eee84c30a5f 100644 --- a/public/assets/css/app.css +++ b/public/assets/css/app.css @@ -1,3 +1,7 @@ +.bg-dark-gray { + background-color: darkgrey; +} + /* AJAX LOADING */ #overlay { position: fixed; diff --git a/public/assets/js/app.js b/public/assets/js/app.js index 5bec1ce13b2803917dcce712176bb0b898b7eb7b..d45bd65801db991972cc3f8b27d078033d2ea6e7 100644 --- a/public/assets/js/app.js +++ b/public/assets/js/app.js @@ -52,13 +52,17 @@ $(function() { type: "GET", url: url, cache: false, - success: function(resp){ + success: function(resp, textStatus, xhr){ + console.log(resp); + if (xhr.status === 211) { + window.location.href = resp; + } appModal.find('.modal-content').html(resp); appModal.modal('show'); if (isForm) { initializeAjaxForm(); initializeForm(true); - }; + } }, complete: function() { $overlay.hide(); @@ -369,33 +373,45 @@ function initializeAjaxLinks() { }) } }) +} - function initializeSearchHeadwords() { - // cliqk sur search => ajax pour get url entry_show dan sle bon lexique - $form = $('#searchHeadwordsForm'); - $form.on('submit', function (e) { - e.preventDefault(); - var $overlay = $('#overlay').show(); - var search = $('#searchHeadwordBox').val(); +function initializeSearchHeadwords() { + // cliqk sur search => ajax pour get url entry_show dan sle bon lexique - $.ajax({ - type: 'GET', - url: $form.attr('action') + '?' + search, - dataType: "json", - success: function (response, textStatus, xhr) { + $form = $('#searchHeadwordsForm'); + $form.on('submit', function (e) { + e.preventDefault(); + var $overlay = $('#overlay').show(); + var $appModal = $('#bootstrap-modal'); + var search = $('#searchHeadwordBox').val(); + var action = $form.attr('action'); + var url = action + (action.indexOf('?') >= 0 ? '&' : '?') + $form.serialize(); + + $.ajax({ + type: 'GET', + url: url, + cache: false, + success: function (response, textStatus, xhr) { + if (xhr.status === 211) { window.location.href = response; - }, - error: function (jqXHR, textStatus, errorThrown) { - console.log(jqXHR.responseText, textStatus, errorThrown); - $wordCreationConfirmationLink = $('headwordConfirmCreation'); - $wordCreationConfirmationLink.data('url', $wordCreationConfirmationLink.data('url') + '?' + search); - $wordCreationConfirmationLink.click(); - // $overlay.hide(); + } else { + $appModal.find('.modal-content').html(response); + $appModal.modal('show'); } - }) - }); - // si pas présnete => modal-form ou confirm-dialog pour demander création dans Agora + }, + complete: function() { + $overlay.hide(); + }, + error: function (jqXHR, textStatus, errorThrown) { + console.log(jqXHR.responseText, textStatus, errorThrown); + // $wordCreationConfirmationLink = $('headwordConfirmCreation'); + // $wordCreationConfirmationLink.data('url', $wordCreationConfirmationLink.data('url') + '?' + search); + // $wordCreationConfirmationLink.click(); + // $overlay.hide(); + } + }) + }); + // si pas présnete => modal-form ou confirm-dialog pour demander création dans Agora - } } \ No newline at end of file diff --git a/src/Controller/HeadwordController.php b/src/Controller/HeadwordController.php index 7c6dca52eedb2217d27f5fcffdc999b29b049f01..008df894642e3d56cc536f84bdbbf979706b1a46 100644 --- a/src/Controller/HeadwordController.php +++ b/src/Controller/HeadwordController.php @@ -41,7 +41,7 @@ class HeadwordController extends AppBaseController */ public function search(Request $request): Response { - $search = $request->get('search'); + $search = $request->get('searchHeadwordBox'); $orderedLexicons = array_merge($this->getUser()->getMyLexicons(), [ $this->getZeroLexicon($this->getLanguage()), $this->getNewWordsLexicon($this->getLanguage()), @@ -49,9 +49,9 @@ class HeadwordController extends AppBaseController $entries = $this->em->getRepository(Entry::class)->getByHeadwordValueInLexicons($search, $orderedLexicons); if ($entries) { - return new JsonResponse($this->generateUrl('app_entry_show', ['id' => $entries[0]->getId()])); + return new JsonResponse($this->generateUrl('app_entry_show', ['id' => $entries[0]->getId()]), 211); } else { - return new JsonResponse(null,404); + return $this->render("headword/confirmAddNewWord.html.twig", ['word' => $search]); } } @@ -60,11 +60,13 @@ class HeadwordController extends AppBaseController */ public function confirmNewWordCreation(Request $request): Response { - + $word = $request->get('word'); + $headword = $this->newHeadword($word, $this->getLanguage()); + $this->createEntryInNewWordsLexicon($headword); - return $this->render("genericModalForm.html.twig", [ - 'form' => $form->crea - ]); + $this->addFlash('success', sprintf("Le mot « %s » a été ajouté à l'Agora des nouveaux mots.", $word)); + + return $this->render("closeModalAndReload.html.twig"); } /** diff --git a/templates/base.html.twig b/templates/base.html.twig index 77af615f6c84312ecd0afa16ab3624e68afd9634..259bb13043ef7623bbecb9c20084e3d6d35239cd 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -22,7 +22,7 @@ {% include "js_translations.html.twig" %} <script src="{{ asset('assets/js/app.js') }}"></script> {% endblock %} -<body> +<body {% if app.environment|upper == 'DEV' %}class="bg-dark-gray"{% endif %}> {% block nav %} {% include "nav.html.twig" %} diff --git a/templates/headword/confirmAddNewWord.html.twig b/templates/headword/confirmAddNewWord.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..1a324205b90053fa3094bd7252cfbecaf8b5db30 --- /dev/null +++ b/templates/headword/confirmAddNewWord.html.twig @@ -0,0 +1,25 @@ +{% extends 'modal.html.twig' %} + +{% block modal_title %} + {{ "Ajouter un mot à l'Agora"|trans }} +{% endblock %} + +{% block modal_body %} + <div class="row"> + <div class="col-md-12"> + + {% include "flashes.html.twig" %} + + <div class="alert alert-warning">{{ ("« " ~ word ~ " » est introuvable dans BaLex et dans le Wiktionnaire.<br>Souhaitez-vous l'ajouter à l'Agora des nouveax mots ?"|trans)|raw }}</div> + + <div class="row pt-3"> + <div class="col-sm-4"></div> + <div class="col-sm-8"> + <a href="#" data-url="{{ path('app_headword_confirm_creation', {word: word}) }}" class="modal-show btn btn-dark">{{ "Ajouter"|trans }}</a> + <button type="button" class="btn btn-light" data-bs-dismiss="modal">{{ 'Annuler'|trans }}</button> + </div> + </div> + + </div> + </div> +{% endblock %} \ No newline at end of file diff --git a/templates/nav.html.twig b/templates/nav.html.twig index 19a98568cfcecb7b3b7e1aea2ab98a61d917ede0..8af2724e577323028383a5cee052563b67540683 100644 --- a/templates/nav.html.twig +++ b/templates/nav.html.twig @@ -8,8 +8,7 @@ <form id="searchHeadwordsForm" class="d-flex" role="search" action="{{ path('app_headword_search') }}"> <input name="searchHeadwordBox" class="form-control me-2" type="search" placeholder="{{ "Rechercher"|trans }}" aria-label="Search"> - <button class="btn btn-light me-3" type="submit"><i class="fa fa-search"></i> </button> - <a id="headwordConfirmCreation" href="#" class="modal-form d-none" data-url="{{ path('app_headword_confirm_creation') }}"></a> + <button id="searchHeadwordButton" class="btn btn-light me-3"><i class="fa fa-search"></i></button> </form> {% if app.user %}