mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
update logic to adapt to altnames
This commit is contained in:
parent
409cd40460
commit
03bd4d1942
@ -1,21 +1,17 @@
|
|||||||
function capitalizeFirstLetter(string) {
|
function capitalizeFirstLetter(string) {
|
||||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
return string.charAt(0).toLocaleUpperCase() + string.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', function() {
|
window.addEventListener('DOMContentLoaded', function() {
|
||||||
|
|
||||||
const uri = decodeURI(location.hash.substring(1))
|
const uri = decodeURI(location.hash.substring(1))
|
||||||
// console.log(uri)
|
|
||||||
let searchFragments = uri.split(' ')
|
let searchFragments = uri.split(' ')
|
||||||
console.log(searchFragments)
|
|
||||||
searchFragments = searchFragments.filter((el) => {
|
searchFragments = searchFragments.filter((el) => {
|
||||||
if ( ( el.startsWith("firstname") || el.startsWith("lastname") ) || (el !== '' && !el.startsWith('birthdate') && !el.startsWith('gender') && !el.startsWith('city') && !el.startsWith('phonenumber') && !el.startsWith('@'))) {
|
if ( ( el.startsWith("firstname") || el.startsWith("lastname") ) || (el !== '' && !el.startsWith('birthdate') && !el.startsWith('gender') && !el.startsWith('city') && !el.startsWith('phonenumber') && !el.startsWith('@'))) {
|
||||||
return el
|
return el
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('after filter', searchFragments)
|
|
||||||
|
|
||||||
searchFragments = searchFragments.map((el) => {
|
searchFragments = searchFragments.map((el) => {
|
||||||
if (el.startsWith("firstname")) {
|
if (el.startsWith("firstname")) {
|
||||||
return el.slice(10)
|
return el.slice(10)
|
||||||
@ -25,34 +21,39 @@ window.addEventListener('DOMContentLoaded', function() {
|
|||||||
return el.replace('\"', '')
|
return el.replace('\"', '')
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(searchFragments)
|
|
||||||
|
|
||||||
if (searchFragments) {
|
if (searchFragments) {
|
||||||
const suggestions = searchFragments.map((el) => `<p class="name badge bg-person" style="cursor: pointer; margin-right: 5px;">${capitalizeFirstLetter(el)}</p>`)
|
const pre = '<ul class="list-suggest add-items inline">';
|
||||||
const suggestFirstName = document.getElementById("suggest-firstname")
|
const after = '</ul>';
|
||||||
const suggestLastname = document.getElementById("suggest-lastname")
|
|
||||||
|
|
||||||
suggestFirstName.innerHTML = suggestions.join(' ');
|
document.querySelectorAll('[data-suggest-container]').forEach(function(container) {
|
||||||
suggestLastname.innerHTML = suggestions.join(' ');
|
const suggestions = searchFragments.map((el) => `<li class="suggest-item-name"><span data-suggest-target="${container.dataset.suggestContainer}">${capitalizeFirstLetter(el)}</span></li>`);
|
||||||
|
container.innerHTML = pre + suggestions.join(' ') + after;
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const tags = document.querySelectorAll('.name')
|
const tags = document.querySelectorAll('[data-suggest-target]').forEach((tag) => {
|
||||||
|
|
||||||
tags.forEach((tag) => {
|
|
||||||
tag.addEventListener('click', function(e) {
|
tag.addEventListener('click', function(e) {
|
||||||
const field = e.target.parentElement.id === 'suggest-lastname' ? document.getElementById('lastname-field') : document.getElementById('firstname-field')
|
const field = document.querySelector(`[name="${e.target.dataset.suggestTarget}"]`);
|
||||||
const suggestion = e.target.parentElement.id === 'suggest-lastname' ? e.target.textContent.toUpperCase() : e.target.textContent
|
let suggestion = e.target.textContent.trim();
|
||||||
|
switch (field.dataset.suggestTransform) {
|
||||||
|
case 'uppercase_all':
|
||||||
|
suggestion = suggestion.toLocaleUpperCase();
|
||||||
|
break;
|
||||||
|
case 'uppercase_first_letter':
|
||||||
|
default:
|
||||||
|
suggestion = capitalizeFirstLetter(suggestion);
|
||||||
|
}
|
||||||
|
|
||||||
if (field.value === '') {
|
if (field.value === '') {
|
||||||
field.value = suggestion;
|
field.value = suggestion;
|
||||||
} else {
|
} else {
|
||||||
field.value = `${field.value} ${suggestion}`
|
field.value = `${field.value} ${suggestion}`
|
||||||
}
|
}
|
||||||
e.target.style.display = "none";
|
e.target.style.display = "none";
|
||||||
|
|
||||||
[...document.querySelectorAll("p")]
|
[...document.querySelectorAll("[data-suggest-target]")]
|
||||||
.filter(p => p.textContent.includes(e.target.textContent))
|
.filter(p => p.textContent.includes(e.target.textContent))
|
||||||
.forEach(p => p.style.display = "none")
|
.forEach(p => p.remove());
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -66,21 +66,29 @@
|
|||||||
<div class="row mb-1" style="display:flex;">
|
<div class="row mb-1" style="display:flex;">
|
||||||
{{ form_label(form.lastName, 'Last name'|trans) }}
|
{{ form_label(form.lastName, 'Last name'|trans) }}
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
{{ form_widget(form.lastName, { 'id' : 'lastname-field'}) }}
|
{{ form_widget(form.lastName, {'attr': {'data-suggest-transform': 'uppercase_all' } }) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="suggest-lastname" class="col-sm-8" style="margin-left: auto;"></div>
|
<div data-suggest-container="{{ form.lastName.vars.full_name|e('html_attr') }}" class="col-sm-8" style="margin-left: auto;"></div>
|
||||||
|
|
||||||
<div class="row mb-1" style="display:flex;">
|
<div class="row mb-1" style="display:flex;">
|
||||||
{{ form_label(form.firstName, 'First name'|trans) }}
|
{{ form_label(form.firstName, 'First name'|trans) }}
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
{{ form_widget(form.firstName, { 'id' : 'firstname-field' }) }}
|
{{ form_widget(form.firstName, {'attr': {'data-suggest-transform': 'uppercase_first_letter' } }) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="suggest-firstname" class="col-sm-8" style="margin-left: auto;"></div>
|
<div data-suggest-container="{{ form.firstName.vars.full_name|e('html_attr') }}" class="col-sm-8" style="margin-left: auto;"></div>
|
||||||
|
|
||||||
{% if form.altNames is defined %}
|
{% if form.altNames is defined %}
|
||||||
{{ form_widget(form.altNames) }}
|
{% for altName in form.altNames %}
|
||||||
|
<div class="row mb-1" style="display:flex;">
|
||||||
|
{{ form_label(altName) }}
|
||||||
|
<div class="col-sm-8">
|
||||||
|
{{ form_widget(altName, {'attr': {'data-suggest-transform': 'uppercase_all' } }) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div data-suggest-container="{{ altName.vars.full_name|e('html_attr') }}" class="col-sm-8" style="margin-left: auto;"></div>
|
||||||
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{{ form_row(form.gender, { 'label' : 'Gender'|trans }) }}
|
{{ form_row(form.gender, { 'label' : 'Gender'|trans }) }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user