Merge remote-tracking branch 'origin/master' into issue596_admin_user

This commit is contained in:
2022-05-13 15:08:49 +02:00
47 changed files with 916 additions and 212 deletions

View File

@@ -0,0 +1,18 @@
import { ShowHide } from 'ShowHide';
const addressForm = document.getElementById("addressForm");
const address = document.getElementById("address");
new ShowHide({
froms: [addressForm],
container: [address],
test: function(froms) {
for (let f of froms.values()) {
for (let input of f.querySelectorAll('input').values()) {
return input.checked;
}
}
return false;
},
event_name: 'change'
});

View File

@@ -123,6 +123,7 @@ export default {
body.email = payload.data.email;
body.altNames = payload.data.altNames;
body.gender = payload.data.gender;
if (payload.data.civility !== null) { body.civility = {id: payload.data.civility.id, type: payload.data.civility.type }; }
makeFetch('PATCH', `/api/1.0/person/person/${payload.data.id}.json`, body)
.then(response => {

View File

@@ -150,6 +150,7 @@ export default {
body.email = payload.data.email;
body.altNames = payload.data.altNames;
body.gender = payload.data.gender;
if (payload.data.civility !== null) { body.civility = {id: payload.data.civility.id, type: payload.data.civility.type}; }
makeFetch('PATCH', `/api/1.0/person/person/${payload.data.id}.json`, body)
.then(response => {

View File

@@ -14,8 +14,13 @@ const getPersonAltNames = () =>
fetch('/api/1.0/person/config/alt_names.json').then(response => {
if (response.ok) { return response.json(); }
throw Error('Error with request resource response');
});;
});
const getCivilities = () =>
fetch('/api/1.0/main/civility.json').then(response => {
if (response.ok) { return response.json(); }
throw Error('Error with request resource response');
});
/*
* POST a new person
@@ -56,6 +61,7 @@ const patchPerson = (id, body) => {
export {
getPerson,
getPersonAltNames,
getCivilities,
postPerson,
patchPerson
};

View File

@@ -277,12 +277,79 @@ export default {
}
},
saveFormOnTheFly({ type, data }) {
// console.log('saveFormOnTheFly from addPersons, type', type, ', data', data);
console.log('saveFormOnTheFly from addPersons, type', type, ', data', data);
if (type === 'person') {
makeFetch('POST', '/api/1.0/person/person.json', data)
.then(response => {
this.newPriorSuggestion(response);
.then(responsePerson => {
this.newPriorSuggestion(responsePerson);
this.$refs.onTheFly.closeModal();
if (null !== data.addressId) {
const household = {
'type': 'household'
};
const address = {
'id': data.addressId
};
makeFetch('POST', '/api/1.0/person/household.json', household)
.then(responseHousehold => {
const member = {
'concerned': [
{
'person': {
'type': 'person',
'id': responsePerson.id
},
'start_date': {
// TODO: use date.js methods (low priority)
'datetime': `${new Date().toISOString().split('T')[0]}T00:00:00+02:00`
},
'holder': false,
'comment': null
}
],
'destination': {
'type': 'household',
'id': responseHousehold.id
},
'composition': null
};
return makeFetch('POST', '/api/1.0/person/household/members/move.json', member)
.then(_response => {
makeFetch('POST', `/api/1.0/person/household/${responseHousehold.id}/address.json`, address)
.then(_response => {})
.catch((error) => {
if (error.name === 'ValidationException') {
for (let v of error.violations) {
this.$toast.open({message: v });
}
} else {
this.$toast.open({message: 'An error occurred'});
}
});
})
.catch((error) => {
if (error.name === 'ValidationException') {
for (let v of error.violations) {
this.$toast.open({message: v });
}
} else {
this.$toast.open({message: 'An error occurred'});
}
});
})
.catch((error) => {
if (error.name === 'ValidationException') {
for (let v of error.violations) {
this.$toast.open({message: v });
}
} else {
this.$toast.open({message: 'An error occurred'});
}
});
}
})
.catch((error) => {
if (error.name === 'ValidationException') {
@@ -292,7 +359,8 @@ export default {
} else {
this.$toast.open({message: 'An error occurred'});
}
})
});
}
else if (type === 'thirdparty') {
makeFetch('POST', '/api/1.0/thirdparty/thirdparty.json', data)

View File

@@ -87,6 +87,20 @@
<label>{{ $t('person.gender.title') }}</label>
</div>
<div class="form-floating mb-3">
<select
class="form-select form-select-lg"
id="civility"
v-model="civility"
>
<option selected disabled >{{ $t('person.civility.placeholder') }}</option>
<option v-for="c in config.civilities" :value="c.id" :key="c.id">
{{ c.name.fr }}
</option>
</select>
<label>{{ $t('person.civility.title') }}</label>
</div>
<div class="input-group mb-3">
<span class="input-group-text" id="birthdate"><i class="fa fa-fw fa-birthday-cake"></i></span>
<input type="date"
@@ -124,6 +138,24 @@
aria-describedby="email" />
</div>
<div v-if="action === 'create'" class="input-group mb-3 form-check">
<input class="form-check-input"
type='checkbox'
v-model="showAddressForm"
name='showAddressForm'/>
<label class="form-check-label">{{ $t('person.address.show_address_form') }}</label>
</div>
<div v-if="action === 'create' && showAddressFormValue" class="form-floating mb-3">
<p>{{ $t('person.address.warning') }}</p>
<add-address
:context="addAddress.context"
:options="addAddress.options"
:addressChangedCallback="submitNewAddress"
ref="addAddress">
</add-address>
</div>
<div class="alert alert-warning" v-if="errors.length">
<ul>
<li v-for="(e, i) in errors" :key="i">{{ e }}</li>
@@ -134,24 +166,43 @@
</template>
<script>
import { getPerson, getPersonAltNames } from '../../_api/OnTheFly';
import { getCivilities, getPerson, getPersonAltNames } from '../../_api/OnTheFly';
import PersonRenderBox from '../Entity/PersonRenderBox.vue';
import AddAddress from "ChillMainAssets/vuejs/Address/components/AddAddress.vue";
export default {
name: "OnTheFlyPerson",
props: ['id', 'type', 'action', 'query'],
//emits: ['createAction'],
components: {
PersonRenderBox
PersonRenderBox,
AddAddress
},
data() {
return {
person: {
type: 'person',
altNames: []
altNames: [],
addressId: null
},
config: {
altNames: []
altNames: [],
civilities: []
},
showAddressFormValue: false,
addAddress: {
options: {
button: {
text: { create: 'person.address.create_address' },
size: 'btn-sm'
},
title: { create: 'person.address.create_address' },
},
context: {
target: {}, // boilerplate for getting the address id
edit: false,
addressId: null
}
},
errors: []
}
@@ -171,6 +222,10 @@ export default {
set(value) { this.person.gender = value; },
get() { return this.person.gender; }
},
civility: {
set(value) { this.person.civility = {id: value, type: 'chill_main_civility'}; },
get() { return this.person.civility ? this.person.civility.id : null; }
},
birthDate: {
set(value) {
if (this.person.birthdate) {
@@ -195,6 +250,10 @@ export default {
set(value) { this.person.email = value; },
get() { return this.person.email; }
},
showAddressForm: {
set(value) { this.showAddressFormValue = value; },
get() { return this.showAddressFormValue; }
},
genderClass() {
switch (this.person.gender) {
case 'woman':
@@ -230,6 +289,13 @@ export default {
.then(altNames => {
this.config.altNames = altNames;
});
getCivilities()
.then(civilities => {
if ('results' in civilities) {
this.config.civilities = civilities.results;
}
});
if (this.action !== 'create') {
this.loadData();
}
@@ -273,6 +339,9 @@ export default {
this.person.firstName = queryItem;
break;
}
},
submitNewAddress(payload) {
this.person.addressId = payload.addressId;
}
}
}
@@ -293,4 +362,9 @@ dl {
margin-left: 1em;
}
}
div.form-check {
label {
margin-left: 0.5em!important;
}
}
</style>

View File

@@ -38,6 +38,15 @@ const personMessages = {
man: "Masculin",
neuter: "Neutre, non binaire",
undefined: "Non renseigné"
},
civility: {
title: "Civilité",
placeholder: "Choisissez la civilité",
},
address: {
create_address: "Ajouter une adresse",
show_address_form: "Créer un ménage et ajouter une adresse",
warning: "Un nouveau ménage va être créé. L'usager sera membre de ce ménage."
}
},
error_only_one_person: "Une seule personne peut être sélectionnée !"

View File

@@ -4,17 +4,19 @@
{% block js %}
{{ encore_entry_script_tags('mod_set_referrer') }}
{{ encore_entry_script_tags('mod_pickentity_type') }}
{% endblock %}
{% block css %}
{{ encore_entry_link_tags('mod_set_referrer') }}
{{ encore_entry_link_tags('mod_pickentity_type') }}
{% endblock %}
{% macro period_meta(period) %}
{% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_UPDATE', period) %}
<div class="item-col item-meta">
{% set job_id = null %}
{% if period.job is defined %}
{% if period.job is defined and period.job is not null %}
{% set job_id = period.job.id %}
{% endif %}
<span
@@ -28,9 +30,9 @@
{% macro period_actions(period) %}
{% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', period) %}
{% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_UPDATE', period) %}
<li>
<a href="{{ chill_path_add_return_path('chill_person_accompanying_course_index', {'accompanying_period_id': period.id}) }}" class="btn btn-show"></a>
<a href="{{ chill_path_add_return_path('chill_person_accompanying_course_edit', {'accompanying_period_id': period.id}) }}" class="btn btn-edit"></a>
</li>
{% endif %}
{% endmacro %}
@@ -38,45 +40,66 @@
{% import _self as m %}
{% block content %}
<div class="col-10">
<div class="row col-10">
<h1>{{ block('title') }}</h1>
{{ form_start(form) }}
<div class="row filter-box">
<div class="col-md-6">
{{ form_start(form) }}
{{ form_label(form.user ) }}
{{ form_widget(form.user, {'attr': {'class': 'select2'}}) }}
<ul class="record_actions">
<li>
<button type="submit" class="btn btn-misc">
<i class="fa fa-filter"></i> {{ 'Filter'|trans }}
</button>
</li>
</ul>
{{ form_end(form) }}
</div>
<div class="col-md-6">
{% if userFrom is not null %}
<div>
{{ form_start(assignForm) }}
{{ form_label(assignForm.userTo ) }}
{{ form_widget(assignForm.userTo, {'attr': {'class': 'select2'}}) }}
</div>
<ul class="record_actions">
<li>
<button type="submit" class="btn btn-update change-icon">
{{ 'reassign.Reassign'|trans }}
</button>
</li>
</ul>
{{ form_end(assignForm) }}
{% else %}
<div class="alert alert-info">{{ 'reassign.List periods to be able to reassign them'|trans }}</div>
{% endif %}
</div>
</div>
<ul class="record_actions">
<li>
<button type="submit" class="btn btn-save change-icon">
<i class="fa fa-filter"></i> Filtrer
</button>
</li>
</ul>
{{ form_end(form) }}
{% if form.user.vars.value is empty %}
<p class="chill-no-data-statement">{{ 'period_by_user_list.Pick a user'|trans }}</p>
{% elseif periods|length == 0 and form.user.vars.value is not empty %}
<p class="chill-no-data-statement">{{ 'period_by_user_list.Any course or no authorization to see them'|trans }}</p>
{% else %}
{% if userFrom is not null %}
<p><span class="badge rounded-pill bg-primary">{{ paginator.totalItems }}</span> parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})</p>
<div class="flex-table">
{% for period in periods %}
{% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period,
'recordAction': m.period_actions(period), 'itemMeta': m.period_meta(period) } %}
{% endfor %}
</div>
{% endif %}
{{ chill_pagination(paginator) }}
<div class="flex-table">
{% for period in periods %}
{% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period,
'recordAction': m.period_actions(period), 'itemMeta': m.period_meta(period) } %}
{% else %}
{% if userFrom is same as(null) %}
<p class="chill-no-data-statement">{{ 'period_by_user_list.Pick a user'|trans }}</p>
{% else %}
<p class="chill-no-data-statement">{{ 'period_by_user_list.Any course or no authorization to see them'|trans }}</p>
{% endif %}
{% endfor %}
</div>
{% if paginator is defined %}
{{ chill_pagination(paginator) }}
{% endif %}
</div>
{% endblock %}
{% endblock %}

View File

@@ -93,6 +93,8 @@
{{ form_row(form.gender, { 'label' : 'Gender'|trans }) }}
{{ form_row(form.civility, { 'label' : 'Civility'|trans }) }}
{{ form_row(form.birthdate, { 'label' : 'Date of birth'|trans }) }}
{{ form_row(form.phonenumber, { 'label' : 'Phonenumber'|trans }) }}
@@ -105,6 +107,13 @@
{{ form_row(form.center) }}
{% endif %}
<div id=addressForm>
{{ form_row(form.addressForm) }}
</div>
<div id=address>
{{ form_row(form.address) }}
</div>
<ul class="record_actions sticky-form-buttons">
<li class="dropdown">
<a class="btn btn-create dropdown-toggle"
@@ -132,4 +141,10 @@
{% block js %}
{{ encore_entry_script_tags('page_suggest_names') }}
{{ encore_entry_script_tags('page_create_person') }}
{{ encore_entry_script_tags('mod_input_address') }}
{% endblock js %}
{% block css %}
{{ encore_entry_link_tags('mod_input_address') }}
{% endblock %}

View File

@@ -48,7 +48,9 @@
</div>
<div class="wl-col list">
<p class="item">
{{ p.position.label|localize_translatable_string }}
{% if p.position %}
{{ p.position.label|localize_translatable_string }}
{% endif %}
{% if p.holder %}
<span class="fa-stack fa-holder" title="{{ 'houshold.holder'|trans|e('html_attr') }}">
<i class="fa fa-circle fa-stack-1x text-success"></i>