Skip to content
Snippets Groups Projects
Commit 321bb36b authored by Pierre Fleutot's avatar Pierre Fleutot
Browse files

Fin barre de recherche de mot-vedette dans la navbar

parent 1363bae0
No related branches found
No related tags found
No related merge requests found
.bg-dark-gray {
background-color: darkgrey;
}
/* AJAX LOADING */ /* AJAX LOADING */
#overlay { #overlay {
position: fixed; position: fixed;
......
...@@ -52,13 +52,17 @@ $(function() { ...@@ -52,13 +52,17 @@ $(function() {
type: "GET", type: "GET",
url: url, url: url,
cache: false, 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.find('.modal-content').html(resp);
appModal.modal('show'); appModal.modal('show');
if (isForm) { if (isForm) {
initializeAjaxForm(); initializeAjaxForm();
initializeForm(true); initializeForm(true);
}; }
}, },
complete: function() { complete: function() {
$overlay.hide(); $overlay.hide();
...@@ -369,33 +373,45 @@ function initializeAjaxLinks() { ...@@ -369,33 +373,45 @@ function initializeAjaxLinks() {
}) })
} }
}) })
}
function initializeSearchHeadwords() { function initializeSearchHeadwords() {
// cliqk sur search => ajax pour get url entry_show dan sle bon lexique // 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();
$.ajax({ $form = $('#searchHeadwordsForm');
type: 'GET', $form.on('submit', function (e) {
url: $form.attr('action') + '?' + search, e.preventDefault();
dataType: "json", var $overlay = $('#overlay').show();
success: function (response, textStatus, xhr) { 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; window.location.href = response;
}, } else {
error: function (jqXHR, textStatus, errorThrown) { $appModal.find('.modal-content').html(response);
console.log(jqXHR.responseText, textStatus, errorThrown); $appModal.modal('show');
$wordCreationConfirmationLink = $('headwordConfirmCreation');
$wordCreationConfirmationLink.data('url', $wordCreationConfirmationLink.data('url') + '?' + search);
$wordCreationConfirmationLink.click();
// $overlay.hide();
} }
}) },
}); complete: function() {
// si pas présnete => modal-form ou confirm-dialog pour demander création dans Agora $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
...@@ -41,7 +41,7 @@ class HeadwordController extends AppBaseController ...@@ -41,7 +41,7 @@ class HeadwordController extends AppBaseController
*/ */
public function search(Request $request): Response public function search(Request $request): Response
{ {
$search = $request->get('search'); $search = $request->get('searchHeadwordBox');
$orderedLexicons = array_merge($this->getUser()->getMyLexicons(), [ $orderedLexicons = array_merge($this->getUser()->getMyLexicons(), [
$this->getZeroLexicon($this->getLanguage()), $this->getZeroLexicon($this->getLanguage()),
$this->getNewWordsLexicon($this->getLanguage()), $this->getNewWordsLexicon($this->getLanguage()),
...@@ -49,9 +49,9 @@ class HeadwordController extends AppBaseController ...@@ -49,9 +49,9 @@ class HeadwordController extends AppBaseController
$entries = $this->em->getRepository(Entry::class)->getByHeadwordValueInLexicons($search, $orderedLexicons); $entries = $this->em->getRepository(Entry::class)->getByHeadwordValueInLexicons($search, $orderedLexicons);
if ($entries) { 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 { } else {
return new JsonResponse(null,404); return $this->render("headword/confirmAddNewWord.html.twig", ['word' => $search]);
} }
} }
...@@ -60,11 +60,13 @@ class HeadwordController extends AppBaseController ...@@ -60,11 +60,13 @@ class HeadwordController extends AppBaseController
*/ */
public function confirmNewWordCreation(Request $request): Response 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", [ $this->addFlash('success', sprintf("Le mot « %s » a été ajouté à l'Agora des nouveaux mots.", $word));
'form' => $form->crea
]); return $this->render("closeModalAndReload.html.twig");
} }
/** /**
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
{% include "js_translations.html.twig" %} {% include "js_translations.html.twig" %}
<script src="{{ asset('assets/js/app.js') }}"></script> <script src="{{ asset('assets/js/app.js') }}"></script>
{% endblock %} {% endblock %}
<body> <body {% if app.environment|upper == 'DEV' %}class="bg-dark-gray"{% endif %}>
{% block nav %} {% block nav %}
{% include "nav.html.twig" %} {% include "nav.html.twig" %}
......
{% 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
...@@ -8,8 +8,7 @@ ...@@ -8,8 +8,7 @@
<form id="searchHeadwordsForm" class="d-flex" role="search" action="{{ path('app_headword_search') }}"> <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"> <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> <button id="searchHeadwordButton" class="btn btn-light me-3"><i class="fa fa-search"></i></button>
<a id="headwordConfirmCreation" href="#" class="modal-form d-none" data-url="{{ path('app_headword_confirm_creation') }}"></a>
</form> </form>
{% if app.user %} {% if app.user %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment